"use client"; import { useState, useEffect } from "react"; import { cn } from "@/lib/utils"; import { Activity, AppWindow, Globe, LayoutDashboard, Shield, ShieldAlert, Server, Zap, Radio, Lock, Search, LogOut } from "lucide-react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { Modal } from "@/components/ui/Modal"; const navigation = [ { name: "Summary", href: "/", icon: LayoutDashboard }, { name: "Agents", href: "/agents", icon: Server }, { name: "Devices", href: "/devices", icon: Server }, { name: "Flows", href: "/flows", icon: Activity }, { name: "Apps", href: "/apps", icon: AppWindow }, { name: "App Database", href: "/lookup", icon: Search }, { name: "Threats", href: "/threats", icon: ShieldAlert }, { name: "Geography", href: "/geography", icon: Globe }, { name: "DNS", href: "/dns", icon: Radio }, { name: "Events", href: "/events", icon: Zap }, { name: "Network Intelligence", href: "/network-intelligence", icon: Activity }, { name: "Security Audit", href: "/security-audit", icon: Lock }, { name: "Intelligence", href: "/intelligence", icon: Shield }, { name: "Network Infra", href: "/network-infrastructure", icon: Server }, { name: "DPI Analytics", href: "/dpi-analytics", icon: Activity }, ]; export function Sidebar() { const pathname = usePathname(); const router = useRouter(); const [user, setUser] = useState<{ role?: string; agent_uuid?: string } | null>(null); // Change Password state const [isChangePasswordOpen, setIsChangePasswordOpen] = useState(false); const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [errorMsg, setErrorMsg] = useState(""); const [successMsg, setSuccessMsg] = useState(""); const [isSubmitting, setIsSubmitting] = useState(false); // Real-time checks for password strength validation const isMinLength = newPassword.length >= 8; const hasUppercase = /[A-Z]/.test(newPassword); const hasLowercase = /[a-z]/.test(newPassword); const hasNumber = /[0-9]/.test(newPassword); const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(newPassword); const passwordsMatch = newPassword === confirmPassword && confirmPassword.length > 0; const isPasswordValid = isMinLength && hasUppercase && hasLowercase && hasNumber && hasSpecial && passwordsMatch; useEffect(() => { fetch('/api/auth/me') .then(res => res.json()) .then(data => { if (data.user) { setUser(data.user); } }) .catch(err => console.error(err)); }, []); const handleLogout = async () => { try { await fetch('/api/auth/logout', { method: 'POST' }); router.push('/login'); router.refresh(); } catch (e) { console.error(e); } }; const handlePasswordChange = async (e: React.FormEvent) => { e.preventDefault(); if (!isPasswordValid) return; setIsSubmitting(true); setErrorMsg(""); setSuccessMsg(""); try { const res = await fetch('/api/auth/change-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ currentPassword, newPassword }), }); const data = await res.json(); if (res.ok) { setSuccessMsg("Password berhasil diubah!"); setCurrentPassword(""); setNewPassword(""); setConfirmPassword(""); setTimeout(() => { setIsChangePasswordOpen(false); setSuccessMsg(""); }, 1500); } else { setErrorMsg(data.error || "Gagal mengubah password"); } } catch (err) { setErrorMsg("Terjadi kesalahan koneksi"); } finally { setIsSubmitting(false); } }; const filteredNavigation = navigation.filter((item) => { if (user?.role === 'AGENT_VIEWER' && item.name === 'Agents') { return false; } return true; }); return (
{/* Subtle glow effect behind sidebar */}
BackOne Logo
BackOne Deep Package Inspection
setIsChangePasswordOpen(false)} title="Ubah Password">
{errorMsg && (
{errorMsg}
)} {successMsg && (
{successMsg}
)}
setCurrentPassword(e.target.value)} required className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-white placeholder-slate-500 focus:border-primary focus:outline-none" />
setNewPassword(e.target.value)} required className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-white placeholder-slate-500 focus:border-primary focus:outline-none" />
setConfirmPassword(e.target.value)} required className="w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-white placeholder-slate-500 focus:border-primary focus:outline-none" />
{/* Real-time Checklist */}
Syarat Kekuatan Password:
  • {isMinLength ? "Γ£ô" : "Γùï"} Minimal 8 karakter
  • {hasUppercase ? "Γ£ô" : "Γùï"} Mengandung huruf besar (A-Z)
  • {hasLowercase ? "Γ£ô" : "Γùï"} Mengandung huruf kecil (a-z)
  • {hasNumber ? "Γ£ô" : "Γùï"} Mengandung angka (0-9)
  • {hasSpecial ? "Γ£ô" : "Γùï"} Mengandung karakter spesial (contoh: @$!%*?&)
  • {passwordsMatch ? "Γ£ô" : "Γùï"} Password cocok
); }