Skip to content

armgit / ARES

Public Imported from GitHub
0

ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.

9.5 KB
Raw Blame
import { AlertCircle, Eye, EyeOff } from "lucide-react";
import { FormEvent, useEffect, useState } from "react";
import { Navigate, useNavigate } from "react-router-dom";
import { initiateSso } from "../../api/client";
import { AresIgniteButton } from "./AresIgniteButton";
import { BackgroundAnimationCanvas } from "./BackgroundAnimationCanvas";
import { useAuth } from "./authContext";

const brandMarkPath = "/dashboard/brand/ares-mark.png";
const brandMascotVideoPath = "/dashboard/brand/ares-dragon-mascot.mp4";
const brandMascotPosterPath = "/dashboard/brand/ares-dragon-poster.png";

export function LoginPage() {
  const [username, setUsername] = useState("");
  const [password, setPassword] = useState("");
  const [showPassword, setShowPassword] = useState(false);
  const [isSubmitting, setIsSubmitting] = useState(false);
  const [isSsoLoading, setIsSsoLoading] = useState(false);
  const [error, setError] = useState("");
  const [ssoError, setSsoError] = useState("");
  const { login, user } = useAuth();
  const navigate = useNavigate();

  useEffect(() => {
    const searchParams = new URLSearchParams(window.location.search);
    const urlErr = searchParams.get("error");
    if (urlErr) {
      setError(urlErr);
    }
  }, []);

  if (user) {
    return <Navigate to="/" replace />;
  }

  async function submit(event: FormEvent) {
    event.preventDefault();
    if (isSubmitting || isSsoLoading) return;
    setError("");
    setSsoError("");
    setIsSubmitting(true);
    try {
      await login(username, password);
      navigate("/", { replace: true });
    } catch (exc) {
      setError(exc instanceof Error ? exc.message : "Authentication failed");
      setIsSubmitting(false);
    }
  }

  async function handleSso() {
    if (isSubmitting || isSsoLoading) return;
    setError("");
    setSsoError("");
    setIsSsoLoading(true);
    try {
      const res = await initiateSso("default");
      // Only navigate to http(s) URLs. The server-supplied redirect_url MUST NOT be
      // trusted blindly: a 'javascript:…' or 'data:text/html,…' value would execute
      // in the login origin as reflected XSS, and arbitrary cross-origin navigation
      // is also an open-redirect vector. (AUDIT run-1 H19)
      const url = typeof res?.redirect_url === "string" ? res.redirect_url : "";
      if (url && /^https?:\/\//i.test(url)) {
        window.location.href = url;
      } else {
        setSsoError("SSO is not configured for this organization. Contact your administrator.");
      }
    } catch {
      setSsoError("SSO is not configured for this organization. Contact your administrator.");
    } finally {
      setIsSsoLoading(false);
    }
  }

  return (
    <div className="min-h-[100dvh] w-full bg-[#09090b] text-[#f4f4f5] grid lg:grid-cols-2 selection:bg-red-700 selection:text-white">

      {/* Left Column: Focused Clean Sign In */}
      <div className="flex flex-col justify-between p-8 sm:p-12 xl:p-16 relative">
        {/* Brand Header */}
        <div className="flex items-center gap-3">
          <img
            className="h-8 w-8 object-contain rounded-md border border-zinc-800 bg-zinc-900/80 p-1"
            src={brandMarkPath}
            alt="ARES"
          />
          <div>
            <h1 className="text-sm font-semibold text-white tracking-tight">ARES Dashboard</h1>
            <span className="text-xs text-zinc-500 font-mono">v6.0</span>
          </div>
        </div>

        {/* Center Form Container */}
        <div className="w-full max-w-sm mx-auto my-auto py-8">
          <div className="mb-6">
            <h2 className="text-2xl font-semibold text-white tracking-tight">Sign in</h2>
            <p className="text-xs text-zinc-400 mt-1.5 leading-relaxed">
              Enter your credentials to access your dashboard.
            </p>
          </div>

          <form onSubmit={(event) => void submit(event)} className="space-y-4">
            <div>
              <label className="block text-xs font-medium text-zinc-300 mb-1.5" htmlFor="operator-username">
                Username / Operator ID
              </label>
              <input
                id="operator-username"
                className="block w-full rounded-md border border-zinc-800 bg-zinc-950 px-3.5 py-2.5 text-sm text-white placeholder-zinc-600 transition-all duration-150 focus:border-red-600 focus:outline-none focus:ring-1 focus:ring-red-600 disabled:opacity-50"
                placeholder="operator"
                value={username}
                onChange={(e) => setUsername(e.target.value)}
                autoComplete="username"
                disabled={isSubmitting || isSsoLoading}
                required
              />
            </div>

            <div>
              <label className="block text-xs font-medium text-zinc-300 mb-1.5" htmlFor="operator-password">
                Password
              </label>
              <div className="relative">
                <input
                  id="operator-password"
                  className="block w-full rounded-md border border-zinc-800 bg-zinc-950 pl-3.5 pr-10 py-2.5 text-sm text-white placeholder-zinc-600 transition-all duration-150 focus:border-red-600 focus:outline-none focus:ring-1 focus:ring-red-600 disabled:opacity-50"
                  type={showPassword ? "text" : "password"}
                  value={password}
                  onChange={(e) => setPassword(e.target.value)}
                  autoComplete="current-password"
                  placeholder="••••••••••••"
                  disabled={isSubmitting || isSsoLoading}
                  required
                />
                <button
                  type="button"
                  className="absolute inset-y-0 right-0 flex items-center pr-3 text-zinc-500 hover:text-zinc-300 transition-colors disabled:pointer-events-none"
                  onClick={() => setShowPassword((v) => !v)}
                  disabled={isSubmitting || isSsoLoading}
                  aria-label={showPassword ? "Hide password" : "Show password"}
                >
                  {showPassword ? <EyeOff size={16} /> : <Eye size={16} />}
                </button>
              </div>
            </div>

            {error && (
              <div className="rounded-md border border-red-900/50 bg-red-950/30 px-3 py-2 text-xs text-red-400 flex items-start gap-2 animate-login-enter">
                <AlertCircle size={14} className="mt-0.5 shrink-0" />
                <span>{error}</span>
              </div>
            )}

            <AresIgniteButton isLoading={isSubmitting} disabled={isSubmitting || isSsoLoading}>
              Sign in
            </AresIgniteButton>

            <div className="pt-2">
              <button
                id="ares-sso-btn"
                type="button"
                onClick={() => void handleSso()}
                disabled={isSubmitting || isSsoLoading}
                className="w-full flex items-center justify-center gap-2 rounded-md border border-zinc-800/80 bg-transparent hover:bg-zinc-900/60 hover:border-zinc-700 py-2 px-3 text-xs text-zinc-400 hover:text-zinc-200 transition-colors disabled:opacity-50"
              >
                <span>{isSsoLoading ? "Connecting..." : "Or continue with SSO"}</span>
              </button>

              {ssoError && (
                <div className="mt-2 rounded-md border border-amber-900/40 bg-amber-950/20 px-3 py-2 text-xs text-amber-400 flex items-start gap-2 animate-login-enter">
                  <AlertCircle size={14} className="mt-0.5 shrink-0 text-amber-400" />
                  <span>{ssoError}</span>
                </div>
              )}
            </div>
          </form>
        </div>

      </div>

      {/* Right Column: Clean Premium Showcase with Living HD Mascot.
          No hairline divider between the columns: the panel's own
          bg-black against the left column's #09090b is the tone step
          that separates them. */}
      <div className="hidden lg:flex flex-col items-center justify-center gap-10 p-8 xl:p-12 bg-black relative overflow-hidden select-none">
        {/* Architectural Grid & Traveling Light Pulses Canvas */}
        <BackgroundAnimationCanvas className="opacity-25" />

        {/* Centerpiece Hero Mascot. The source video is 16:9 with the
            dragon occupying most of its height but only its centre ~80%
            of width; a 16:9 box in a portrait panel left most of the
            panel's height empty. Framing the box at ~1.55:1 and cropping
            with object-cover (measured safe margins, not guessed) fills
            far more of the panel without touching the animation's own
            motion bounds across the full 10s loop. */}
        <div className="relative z-10 w-full max-w-xl h-[52vh] max-h-[620px]">
          <video
            src={brandMascotVideoPath}
            poster={brandMascotPosterPath}
            autoPlay
            loop
            muted
            playsInline
            preload="auto"
            className="h-full w-full object-cover select-none pointer-events-none"
            style={{ objectPosition: "46% 50%" }}
          />
          {/* Flat ground plinth: a step in tone, not a glow - grounds the
              mascot instead of leaving it floating on flat black. */}
          <div
            aria-hidden="true"
            className="absolute left-1/2 bottom-[6%] -translate-x-1/2 w-[58%] h-3 rounded-full bg-[#121216]"
          />
        </div>

        <p className="relative z-10 max-w-sm text-center text-sm leading-relaxed text-zinc-400">
          Operator-directed red team orchestration &amp; continuous security
          validation platform.
        </p>
      </div>

    </div>
  );
}