mirror of
https://github.com/AeThex-Corporation/AeThex-OS.git
synced 2026-04-17 22:27:19 +00:00
Add new admin dashboard sections and enhance Aegis monitor functionality
Introduce new admin routes for sites, logs, and achievements, refactor Aegis monitor to display real data from alerts and auth_logs, and implement JWT token generation for authentication. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 279f1558-c0e3-40e4-8217-be7e9f4c6eca Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 48e7daad-43dd-4684-8441-ff2ea20129e1 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/b984cb14-1d19-4944-922b-bc79e821ed35/279f1558-c0e3-40e4-8217-be7e9f4c6eca/HbU8yEz Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
2f98c630e9
commit
5f40710e82
8 changed files with 835 additions and 115 deletions
|
|
@ -16,6 +16,9 @@ import AdminArchitects from "@/pages/admin-architects";
|
|||
import AdminProjects from "@/pages/admin-projects";
|
||||
import AdminCredentials from "@/pages/admin-credentials";
|
||||
import AdminAegis from "@/pages/admin-aegis";
|
||||
import AdminSites from "@/pages/admin-sites";
|
||||
import AdminLogs from "@/pages/admin-logs";
|
||||
import AdminAchievements from "@/pages/admin-achievements";
|
||||
|
||||
function Router() {
|
||||
return (
|
||||
|
|
@ -31,6 +34,9 @@ function Router() {
|
|||
<Route path="/admin/projects" component={AdminProjects} />
|
||||
<Route path="/admin/credentials" component={AdminCredentials} />
|
||||
<Route path="/admin/aegis" component={AdminAegis} />
|
||||
<Route path="/admin/sites" component={AdminSites} />
|
||||
<Route path="/admin/logs" component={AdminLogs} />
|
||||
<Route path="/admin/achievements" component={AdminAchievements} />
|
||||
<Route path="/pitch" component={Pitch} />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
|
|
|
|||
167
client/src/pages/admin-achievements.tsx
Normal file
167
client/src/pages/admin-achievements.tsx
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
import { useEffect } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { Link, useLocation } from "wouter";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
Users, FileCode, Shield, Activity, LogOut,
|
||||
BarChart3, User, Globe, Key, Award, Star, Trophy
|
||||
} from "lucide-react";
|
||||
|
||||
export default function AdminAchievements() {
|
||||
const { user, isAuthenticated, isLoading: authLoading, logout } = useAuth();
|
||||
const [, setLocation] = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !isAuthenticated) {
|
||||
setLocation("/login");
|
||||
}
|
||||
}, [authLoading, isAuthenticated, setLocation]);
|
||||
|
||||
const { data: achievements, isLoading } = useQuery({
|
||||
queryKey: ["achievements"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/achievements");
|
||||
if (!res.ok) throw new Error("Failed to fetch achievements");
|
||||
return res.json();
|
||||
},
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
if (authLoading || !isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
<div className="text-primary animate-pulse">Loading...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
setLocation("/");
|
||||
};
|
||||
|
||||
const getRarityColor = (rarity: string) => {
|
||||
switch (rarity?.toLowerCase()) {
|
||||
case 'legendary': return 'border-yellow-500 bg-yellow-500/10';
|
||||
case 'epic': return 'border-purple-500 bg-purple-500/10';
|
||||
case 'rare': return 'border-blue-500 bg-blue-500/10';
|
||||
case 'uncommon': return 'border-green-500 bg-green-500/10';
|
||||
default: return 'border-white/10 bg-white/5';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background text-foreground font-mono flex">
|
||||
<Sidebar user={user} onLogout={handleLogout} active="achievements" />
|
||||
|
||||
<div className="flex-1 overflow-auto">
|
||||
<div className="p-8">
|
||||
<div className="mb-8">
|
||||
<h2 className="text-2xl font-display font-bold text-white uppercase tracking-wider">
|
||||
Achievements
|
||||
</h2>
|
||||
<p className="text-muted-foreground text-sm mt-1">
|
||||
{achievements?.length || 0} achievements configured
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{isLoading ? (
|
||||
<div className="col-span-full text-center text-muted-foreground py-12">Loading...</div>
|
||||
) : achievements?.length === 0 ? (
|
||||
<div className="col-span-full text-center text-muted-foreground py-12">No achievements found</div>
|
||||
) : (
|
||||
achievements?.map((achievement: any) => (
|
||||
<motion.div
|
||||
key={achievement.id}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className={`border p-6 ${getRarityColor(achievement.rarity)}`}
|
||||
>
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="w-12 h-12 bg-black/20 rounded-lg flex items-center justify-center text-2xl">
|
||||
{achievement.icon || '🏆'}
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<h3 className="font-display text-white uppercase text-sm">{achievement.name}</h3>
|
||||
<p className="text-xs text-muted-foreground mt-1">{achievement.description}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 pt-4 border-t border-white/5 grid grid-cols-3 gap-2 text-xs">
|
||||
<div>
|
||||
<div className="text-muted-foreground">XP</div>
|
||||
<div className="text-primary font-bold">+{achievement.xp_reward || 0}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">Points</div>
|
||||
<div className="text-secondary font-bold">+{achievement.points_reward || 0}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">Rarity</div>
|
||||
<div className="text-white font-bold capitalize">{achievement.rarity || 'common'}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{achievement.category && (
|
||||
<div className="mt-3">
|
||||
<span className="text-xs bg-white/5 px-2 py-1 rounded text-muted-foreground">
|
||||
{achievement.category}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({ user, onLogout, active }: { user: any; onLogout: () => void; active: string }) {
|
||||
return (
|
||||
<div className="w-64 bg-card border-r border-white/10 flex flex-col">
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-xl font-display font-bold text-white uppercase tracking-wider">AeThex</h1>
|
||||
<p className="text-xs text-primary mt-1">Command Center</p>
|
||||
</div>
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" active={active === 'dashboard'} />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" active={active === 'architects'} />
|
||||
<NavItem icon={<Award className="w-4 h-4" />} label="Achievements" href="/admin/achievements" active={active === 'achievements'} />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" active={active === 'credentials'} />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" active={active === 'projects'} />
|
||||
<NavItem icon={<Globe className="w-4 h-4" />} label="Sites" href="/admin/sites" active={active === 'sites'} />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" active={active === 'aegis'} />
|
||||
</nav>
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-8 h-8 bg-primary/20 rounded-full flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-white font-bold">{user?.username}</div>
|
||||
<div className="text-xs text-muted-foreground">{user?.isAdmin ? "Administrator" : "Member"}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onLogout} className="w-full flex items-center gap-2 text-muted-foreground hover:text-white text-sm py-2 px-3 hover:bg-white/5 transition-colors">
|
||||
<LogOut className="w-4 h-4" /> Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NavItem({ icon, label, href, active = false }: { icon: React.ReactNode; label: string; href: string; active?: boolean }) {
|
||||
return (
|
||||
<Link href={href}>
|
||||
<div className={`flex items-center gap-3 px-3 py-2 text-sm transition-colors cursor-pointer ${active ? 'bg-primary/10 text-primary border-l-2 border-primary' : 'text-muted-foreground hover:text-white hover:bg-white/5'}`}>
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,9 +1,10 @@
|
|||
import { useEffect } from "react";
|
||||
import { Link, useLocation } from "wouter";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
Users, FileCode, Shield, Activity, LogOut,
|
||||
BarChart3, User, AlertTriangle, CheckCircle, XCircle, Eye
|
||||
BarChart3, User, AlertTriangle, CheckCircle, XCircle, Eye, Globe, Award, Key
|
||||
} from "lucide-react";
|
||||
|
||||
export default function AdminAegis() {
|
||||
|
|
@ -16,6 +17,26 @@ export default function AdminAegis() {
|
|||
}
|
||||
}, [authLoading, isAuthenticated, setLocation]);
|
||||
|
||||
const { data: alerts } = useQuery({
|
||||
queryKey: ["alerts"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/alerts");
|
||||
if (!res.ok) return [];
|
||||
return res.json();
|
||||
},
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
const { data: authLogs } = useQuery({
|
||||
queryKey: ["auth-logs-recent"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/auth-logs");
|
||||
if (!res.ok) return [];
|
||||
return res.json();
|
||||
},
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
if (authLoading || !isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
|
|
@ -29,54 +50,14 @@ export default function AdminAegis() {
|
|||
setLocation("/");
|
||||
};
|
||||
|
||||
// Mock threat data for demo
|
||||
const mockThreats = [
|
||||
{ id: 1, type: "PII Exposure", severity: "high", status: "blocked", timestamp: "2 min ago" },
|
||||
{ id: 2, type: "Suspicious Pattern", severity: "medium", status: "flagged", timestamp: "15 min ago" },
|
||||
{ id: 3, type: "Rate Limit", severity: "low", status: "allowed", timestamp: "1 hour ago" },
|
||||
];
|
||||
const failedLogins = authLogs?.filter((l: any) => l.event_type?.includes('fail')).length || 0;
|
||||
const successLogins = authLogs?.filter((l: any) => l.event_type?.includes('success')).length || 0;
|
||||
const unresolvedAlerts = alerts?.filter((a: any) => !a.is_resolved).length || 0;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background text-foreground font-mono flex">
|
||||
{/* Sidebar */}
|
||||
<div className="w-64 bg-card border-r border-white/10 flex flex-col">
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-xl font-display font-bold text-white uppercase tracking-wider">
|
||||
AeThex
|
||||
</h1>
|
||||
<p className="text-xs text-primary mt-1">Command Center</p>
|
||||
</div>
|
||||
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" active />
|
||||
</nav>
|
||||
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-8 h-8 bg-primary/20 rounded-full flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-white font-bold">{user?.username}</div>
|
||||
<div className="text-xs text-muted-foreground">
|
||||
{user?.isAdmin ? "Administrator" : "Member"}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="w-full flex items-center gap-2 text-muted-foreground hover:text-white text-sm py-2 px-3 hover:bg-white/5 transition-colors"
|
||||
>
|
||||
<LogOut className="w-4 h-4" /> Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<Sidebar user={user} onLogout={handleLogout} active="aegis" />
|
||||
|
||||
{/* Main Content */}
|
||||
<div className="flex-1 overflow-auto">
|
||||
<div className="p-8">
|
||||
<div className="flex justify-between items-start mb-8">
|
||||
|
|
@ -85,7 +66,7 @@ export default function AdminAegis() {
|
|||
Aegis Monitor
|
||||
</h2>
|
||||
<p className="text-muted-foreground text-sm mt-1">
|
||||
Real-time security monitoring and threat intervention
|
||||
Real-time security monitoring from your database
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 bg-green-500/10 text-green-500 px-4 py-2 text-sm">
|
||||
|
|
@ -94,78 +75,93 @@ export default function AdminAegis() {
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{/* Stats */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Threats Blocked</div>
|
||||
<div className="text-3xl font-display font-bold text-destructive">247</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Last 24 hours</div>
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Auth Events</div>
|
||||
<div className="text-3xl font-display font-bold text-white">{authLogs?.length || 0}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Last 100 events</div>
|
||||
</div>
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">PII Scrubbed</div>
|
||||
<div className="text-3xl font-display font-bold text-primary">1,892</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Instances protected</div>
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Failed Logins</div>
|
||||
<div className="text-3xl font-display font-bold text-destructive">{failedLogins}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Blocked attempts</div>
|
||||
</div>
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Active Sessions</div>
|
||||
<div className="text-3xl font-display font-bold text-white">34</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Being monitored</div>
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Successful Logins</div>
|
||||
<div className="text-3xl font-display font-bold text-green-500">{successLogins}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Verified access</div>
|
||||
</div>
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Uptime</div>
|
||||
<div className="text-3xl font-display font-bold text-green-500">99.9%</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Last 30 days</div>
|
||||
<div className="text-xs text-muted-foreground uppercase tracking-wider mb-2">Active Alerts</div>
|
||||
<div className="text-3xl font-display font-bold text-primary">{unresolvedAlerts}</div>
|
||||
<div className="text-xs text-muted-foreground mt-1">Unresolved</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recent Activity */}
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<h3 className="text-sm font-bold text-white uppercase tracking-widest mb-6 flex items-center gap-2">
|
||||
<Activity className="w-4 h-4 text-primary" />
|
||||
Recent Threat Activity
|
||||
</h3>
|
||||
|
||||
<div className="space-y-4">
|
||||
{mockThreats.map((threat) => (
|
||||
<div key={threat.id} className="flex items-center justify-between p-4 bg-black/20 border border-white/5">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className={`w-10 h-10 rounded-full flex items-center justify-center ${
|
||||
threat.severity === 'high' ? 'bg-destructive/10' :
|
||||
threat.severity === 'medium' ? 'bg-yellow-500/10' :
|
||||
'bg-white/5'
|
||||
}`}>
|
||||
<AlertTriangle className={`w-5 h-5 ${
|
||||
threat.severity === 'high' ? 'text-destructive' :
|
||||
threat.severity === 'medium' ? 'text-yellow-500' :
|
||||
'text-muted-foreground'
|
||||
}`} />
|
||||
{alerts && alerts.length > 0 && (
|
||||
<div className="bg-card/50 border border-white/10 p-6 mb-8">
|
||||
<h3 className="text-sm font-bold text-white uppercase tracking-widest mb-6 flex items-center gap-2">
|
||||
<AlertTriangle className="w-4 h-4 text-destructive" />
|
||||
System Alerts
|
||||
</h3>
|
||||
<div className="space-y-4">
|
||||
{alerts.slice(0, 10).map((alert: any) => (
|
||||
<div key={alert.id} className="flex items-center justify-between p-4 bg-black/20 border border-white/5">
|
||||
<div className="flex items-center gap-4">
|
||||
<div className={`w-10 h-10 rounded-full flex items-center justify-center ${
|
||||
alert.severity === 'critical' ? 'bg-destructive/10' :
|
||||
alert.severity === 'warning' ? 'bg-yellow-500/10' :
|
||||
'bg-blue-500/10'
|
||||
}`}>
|
||||
<AlertTriangle className={`w-5 h-5 ${
|
||||
alert.severity === 'critical' ? 'text-destructive' :
|
||||
alert.severity === 'warning' ? 'text-yellow-500' :
|
||||
'text-blue-500'
|
||||
}`} />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-white font-bold">{alert.type}</div>
|
||||
<div className="text-xs text-muted-foreground">{alert.message}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-white font-bold">{threat.type}</div>
|
||||
<div className="text-xs text-muted-foreground">{threat.timestamp}</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<span className={`text-xs px-2 py-1 rounded uppercase font-bold ${
|
||||
alert.is_resolved ? 'bg-green-500/10 text-green-500' : 'bg-destructive/10 text-destructive'
|
||||
}`}>
|
||||
{alert.is_resolved ? 'resolved' : 'active'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<span className={`text-xs px-2 py-1 rounded uppercase font-bold ${
|
||||
threat.status === 'blocked' ? 'bg-destructive/10 text-destructive' :
|
||||
threat.status === 'flagged' ? 'bg-yellow-500/10 text-yellow-500' :
|
||||
'bg-green-500/10 text-green-500'
|
||||
}`}>
|
||||
{threat.status}
|
||||
</span>
|
||||
<button className="text-muted-foreground hover:text-white p-2">
|
||||
<Eye className="w-4 h-4" />
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-card/50 border border-white/10 p-6">
|
||||
<h3 className="text-sm font-bold text-white uppercase tracking-widest mb-6 flex items-center gap-2">
|
||||
<Key className="w-4 h-4 text-primary" />
|
||||
Recent Auth Events
|
||||
</h3>
|
||||
<div className="space-y-2">
|
||||
{authLogs?.slice(0, 10).map((log: any) => (
|
||||
<div key={log.id} className="flex items-center justify-between p-3 bg-black/20 border border-white/5 text-sm">
|
||||
<div className="flex items-center gap-3">
|
||||
{log.event_type?.includes('success') ? (
|
||||
<CheckCircle className="w-4 h-4 text-green-500" />
|
||||
) : log.event_type?.includes('fail') ? (
|
||||
<XCircle className="w-4 h-4 text-destructive" />
|
||||
) : (
|
||||
<Key className="w-4 h-4 text-muted-foreground" />
|
||||
)}
|
||||
<span className="text-white">{log.event_type}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-4 text-xs text-muted-foreground">
|
||||
<span className="font-mono">{log.ip_address || 'N/A'}</span>
|
||||
<span>{log.created_at ? new Date(log.created_at).toLocaleString() : ''}</span>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-6 text-center">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Aegis security layer is monitoring all active sessions
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -173,19 +169,45 @@ export default function AdminAegis() {
|
|||
);
|
||||
}
|
||||
|
||||
function NavItem({ icon, label, href, active = false }: {
|
||||
icon: React.ReactNode;
|
||||
label: string;
|
||||
href: string;
|
||||
active?: boolean;
|
||||
}) {
|
||||
function Sidebar({ user, onLogout, active }: { user: any; onLogout: () => void; active: string }) {
|
||||
return (
|
||||
<div className="w-64 bg-card border-r border-white/10 flex flex-col">
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-xl font-display font-bold text-white uppercase tracking-wider">AeThex</h1>
|
||||
<p className="text-xs text-primary mt-1">Command Center</p>
|
||||
</div>
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" active={active === 'dashboard'} />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" active={active === 'architects'} />
|
||||
<NavItem icon={<Award className="w-4 h-4" />} label="Achievements" href="/admin/achievements" active={active === 'achievements'} />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" active={active === 'credentials'} />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" active={active === 'projects'} />
|
||||
<NavItem icon={<Globe className="w-4 h-4" />} label="Sites" href="/admin/sites" active={active === 'sites'} />
|
||||
<NavItem icon={<Key className="w-4 h-4" />} label="Auth Logs" href="/admin/logs" active={active === 'logs'} />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" active={active === 'aegis'} />
|
||||
</nav>
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-8 h-8 bg-primary/20 rounded-full flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-white font-bold">{user?.username}</div>
|
||||
<div className="text-xs text-muted-foreground">{user?.isAdmin ? "Administrator" : "Member"}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onLogout} className="w-full flex items-center gap-2 text-muted-foreground hover:text-white text-sm py-2 px-3 hover:bg-white/5 transition-colors">
|
||||
<LogOut className="w-4 h-4" /> Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NavItem({ icon, label, href, active = false }: { icon: React.ReactNode; label: string; href: string; active?: boolean }) {
|
||||
return (
|
||||
<Link href={href}>
|
||||
<div className={`flex items-center gap-3 px-3 py-2 text-sm transition-colors cursor-pointer ${
|
||||
active
|
||||
? 'bg-primary/10 text-primary border-l-2 border-primary'
|
||||
: 'text-muted-foreground hover:text-white hover:bg-white/5'
|
||||
}`}>
|
||||
<div className={`flex items-center gap-3 px-3 py-2 text-sm transition-colors cursor-pointer ${active ? 'bg-primary/10 text-primary border-l-2 border-primary' : 'text-muted-foreground hover:text-white hover:bg-white/5'}`}>
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
|
|
|
|||
166
client/src/pages/admin-logs.tsx
Normal file
166
client/src/pages/admin-logs.tsx
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import { useEffect } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { Link, useLocation } from "wouter";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
Users, FileCode, Shield, Activity, LogOut,
|
||||
BarChart3, User, Globe, Key, CheckCircle, XCircle, AlertTriangle
|
||||
} from "lucide-react";
|
||||
|
||||
export default function AdminLogs() {
|
||||
const { user, isAuthenticated, isLoading: authLoading, logout } = useAuth();
|
||||
const [, setLocation] = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !isAuthenticated) {
|
||||
setLocation("/login");
|
||||
}
|
||||
}, [authLoading, isAuthenticated, setLocation]);
|
||||
|
||||
const { data: logs, isLoading } = useQuery({
|
||||
queryKey: ["auth-logs"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/auth-logs");
|
||||
if (!res.ok) throw new Error("Failed to fetch logs");
|
||||
return res.json();
|
||||
},
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
if (authLoading || !isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
<div className="text-primary animate-pulse">Loading...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
setLocation("/");
|
||||
};
|
||||
|
||||
const getEventIcon = (eventType: string) => {
|
||||
if (eventType?.includes('success') || eventType?.includes('login')) {
|
||||
return <CheckCircle className="w-4 h-4 text-green-500" />;
|
||||
} else if (eventType?.includes('fail') || eventType?.includes('error')) {
|
||||
return <XCircle className="w-4 h-4 text-destructive" />;
|
||||
} else if (eventType?.includes('warn')) {
|
||||
return <AlertTriangle className="w-4 h-4 text-yellow-500" />;
|
||||
}
|
||||
return <Key className="w-4 h-4 text-muted-foreground" />;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background text-foreground font-mono flex">
|
||||
<Sidebar user={user} onLogout={handleLogout} active="logs" />
|
||||
|
||||
<div className="flex-1 overflow-auto">
|
||||
<div className="p-8">
|
||||
<div className="mb-8">
|
||||
<h2 className="text-2xl font-display font-bold text-white uppercase tracking-wider">
|
||||
Auth Logs
|
||||
</h2>
|
||||
<p className="text-muted-foreground text-sm mt-1">
|
||||
{logs?.length || 0} recent authentication events
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="bg-card/50 border border-white/10 overflow-hidden">
|
||||
<table className="w-full">
|
||||
<thead>
|
||||
<tr className="border-b border-white/10 text-left">
|
||||
<th className="p-4 text-xs text-muted-foreground uppercase tracking-wider font-bold">Event</th>
|
||||
<th className="p-4 text-xs text-muted-foreground uppercase tracking-wider font-bold">User</th>
|
||||
<th className="p-4 text-xs text-muted-foreground uppercase tracking-wider font-bold">IP Address</th>
|
||||
<th className="p-4 text-xs text-muted-foreground uppercase tracking-wider font-bold">User Agent</th>
|
||||
<th className="p-4 text-xs text-muted-foreground uppercase tracking-wider font-bold">Time</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{isLoading ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="p-8 text-center text-muted-foreground">Loading...</td>
|
||||
</tr>
|
||||
) : logs?.length === 0 ? (
|
||||
<tr>
|
||||
<td colSpan={5} className="p-8 text-center text-muted-foreground">No logs found</td>
|
||||
</tr>
|
||||
) : (
|
||||
logs?.map((log: any) => (
|
||||
<tr key={log.id} className="border-b border-white/5 hover:bg-white/5 transition-colors">
|
||||
<td className="p-4">
|
||||
<div className="flex items-center gap-2">
|
||||
{getEventIcon(log.event_type)}
|
||||
<span className="text-sm text-white">{log.event_type}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className="p-4 text-sm text-muted-foreground font-mono">
|
||||
{log.user_id?.substring(0, 8)}...
|
||||
</td>
|
||||
<td className="p-4 text-sm text-muted-foreground font-mono">
|
||||
{log.ip_address || 'N/A'}
|
||||
</td>
|
||||
<td className="p-4 text-xs text-muted-foreground max-w-[200px] truncate">
|
||||
{log.user_agent || 'N/A'}
|
||||
</td>
|
||||
<td className="p-4 text-xs text-muted-foreground">
|
||||
{log.created_at ? new Date(log.created_at).toLocaleString() : 'N/A'}
|
||||
</td>
|
||||
</tr>
|
||||
))
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({ user, onLogout, active }: { user: any; onLogout: () => void; active: string }) {
|
||||
return (
|
||||
<div className="w-64 bg-card border-r border-white/10 flex flex-col">
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-xl font-display font-bold text-white uppercase tracking-wider">AeThex</h1>
|
||||
<p className="text-xs text-primary mt-1">Command Center</p>
|
||||
</div>
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" active={active === 'dashboard'} />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" active={active === 'architects'} />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" active={active === 'credentials'} />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" active={active === 'projects'} />
|
||||
<NavItem icon={<Globe className="w-4 h-4" />} label="Sites" href="/admin/sites" active={active === 'sites'} />
|
||||
<NavItem icon={<Key className="w-4 h-4" />} label="Auth Logs" href="/admin/logs" active={active === 'logs'} />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" active={active === 'aegis'} />
|
||||
</nav>
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-8 h-8 bg-primary/20 rounded-full flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-white font-bold">{user?.username}</div>
|
||||
<div className="text-xs text-muted-foreground">{user?.isAdmin ? "Administrator" : "Member"}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onLogout} className="w-full flex items-center gap-2 text-muted-foreground hover:text-white text-sm py-2 px-3 hover:bg-white/5 transition-colors">
|
||||
<LogOut className="w-4 h-4" /> Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NavItem({ icon, label, href, active = false }: { icon: React.ReactNode; label: string; href: string; active?: boolean }) {
|
||||
return (
|
||||
<Link href={href}>
|
||||
<div className={`flex items-center gap-3 px-3 py-2 text-sm transition-colors cursor-pointer ${active ? 'bg-primary/10 text-primary border-l-2 border-primary' : 'text-muted-foreground hover:text-white hover:bg-white/5'}`}>
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
192
client/src/pages/admin-sites.tsx
Normal file
192
client/src/pages/admin-sites.tsx
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
import { useEffect } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { Link, useLocation } from "wouter";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
Users, FileCode, Shield, Activity, LogOut,
|
||||
BarChart3, User, Globe, CheckCircle, XCircle, AlertTriangle, ExternalLink
|
||||
} from "lucide-react";
|
||||
|
||||
export default function AdminSites() {
|
||||
const { user, isAuthenticated, isLoading: authLoading, logout } = useAuth();
|
||||
const [, setLocation] = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
if (!authLoading && !isAuthenticated) {
|
||||
setLocation("/login");
|
||||
}
|
||||
}, [authLoading, isAuthenticated, setLocation]);
|
||||
|
||||
const { data: sites, isLoading } = useQuery({
|
||||
queryKey: ["sites"],
|
||||
queryFn: async () => {
|
||||
const res = await fetch("/api/sites");
|
||||
if (!res.ok) throw new Error("Failed to fetch sites");
|
||||
return res.json();
|
||||
},
|
||||
enabled: isAuthenticated,
|
||||
});
|
||||
|
||||
if (authLoading || !isAuthenticated) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
<div className="text-primary animate-pulse">Loading...</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const handleLogout = async () => {
|
||||
await logout();
|
||||
setLocation("/");
|
||||
};
|
||||
|
||||
const getStatusColor = (status: string) => {
|
||||
switch (status?.toLowerCase()) {
|
||||
case 'online': case 'operational': return 'text-green-500';
|
||||
case 'degraded': case 'warning': return 'text-yellow-500';
|
||||
case 'offline': case 'down': return 'text-destructive';
|
||||
default: return 'text-muted-foreground';
|
||||
}
|
||||
};
|
||||
|
||||
const getStatusIcon = (status: string) => {
|
||||
switch (status?.toLowerCase()) {
|
||||
case 'online': case 'operational': return <CheckCircle className="w-4 h-4" />;
|
||||
case 'degraded': case 'warning': return <AlertTriangle className="w-4 h-4" />;
|
||||
case 'offline': case 'down': return <XCircle className="w-4 h-4" />;
|
||||
default: return <Globe className="w-4 h-4" />;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-background text-foreground font-mono flex">
|
||||
<Sidebar user={user} onLogout={handleLogout} active="sites" />
|
||||
|
||||
<div className="flex-1 overflow-auto">
|
||||
<div className="p-8">
|
||||
<div className="mb-8">
|
||||
<h2 className="text-2xl font-display font-bold text-white uppercase tracking-wider">
|
||||
AeThex Sites
|
||||
</h2>
|
||||
<p className="text-muted-foreground text-sm mt-1">
|
||||
{sites?.length || 0} monitored sites
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{isLoading ? (
|
||||
<div className="col-span-full text-center text-muted-foreground py-12">
|
||||
Loading sites...
|
||||
</div>
|
||||
) : sites?.length === 0 ? (
|
||||
<div className="col-span-full text-center text-muted-foreground py-12">
|
||||
No sites found
|
||||
</div>
|
||||
) : (
|
||||
sites?.map((site: any) => (
|
||||
<motion.div
|
||||
key={site.id}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
className="bg-card/50 border border-white/10 p-6 hover:border-primary/30 transition-colors"
|
||||
>
|
||||
<div className="flex justify-between items-start mb-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<Globe className="w-5 h-5 text-primary" />
|
||||
<h3 className="font-display text-white uppercase text-sm">{site.name}</h3>
|
||||
</div>
|
||||
<div className={`flex items-center gap-1 text-xs ${getStatusColor(site.status)}`}>
|
||||
{getStatusIcon(site.status)}
|
||||
{site.status || 'unknown'}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{site.url && (
|
||||
<a
|
||||
href={site.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-xs text-muted-foreground hover:text-primary flex items-center gap-1 mb-4"
|
||||
>
|
||||
{site.url} <ExternalLink className="w-3 h-3" />
|
||||
</a>
|
||||
)}
|
||||
|
||||
<div className="grid grid-cols-2 gap-4 text-xs">
|
||||
<div>
|
||||
<div className="text-muted-foreground">Uptime</div>
|
||||
<div className="text-white font-bold">{site.uptime || 0}%</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">Response</div>
|
||||
<div className="text-white font-bold">{site.response_time || 0}ms</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">Users</div>
|
||||
<div className="text-white font-bold">{site.users || 0}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-muted-foreground">Requests</div>
|
||||
<div className="text-white font-bold">{site.requests || 0}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{site.last_check && (
|
||||
<div className="mt-4 pt-4 border-t border-white/5 text-xs text-muted-foreground">
|
||||
Last check: {new Date(site.last_check).toLocaleString()}
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Sidebar({ user, onLogout, active }: { user: any; onLogout: () => void; active: string }) {
|
||||
return (
|
||||
<div className="w-64 bg-card border-r border-white/10 flex flex-col">
|
||||
<div className="p-6 border-b border-white/10">
|
||||
<h1 className="text-xl font-display font-bold text-white uppercase tracking-wider">AeThex</h1>
|
||||
<p className="text-xs text-primary mt-1">Command Center</p>
|
||||
</div>
|
||||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" active={active === 'dashboard'} />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" active={active === 'architects'} />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" active={active === 'credentials'} />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" active={active === 'projects'} />
|
||||
<NavItem icon={<Globe className="w-4 h-4" />} label="Sites" href="/admin/sites" active={active === 'sites'} />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" active={active === 'aegis'} />
|
||||
</nav>
|
||||
<div className="p-4 border-t border-white/10">
|
||||
<div className="flex items-center gap-3 mb-4">
|
||||
<div className="w-8 h-8 bg-primary/20 rounded-full flex items-center justify-center">
|
||||
<User className="w-4 h-4 text-primary" />
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-sm text-white font-bold">{user?.username}</div>
|
||||
<div className="text-xs text-muted-foreground">{user?.isAdmin ? "Administrator" : "Member"}</div>
|
||||
</div>
|
||||
</div>
|
||||
<button onClick={onLogout} className="w-full flex items-center gap-2 text-muted-foreground hover:text-white text-sm py-2 px-3 hover:bg-white/5 transition-colors">
|
||||
<LogOut className="w-4 h-4" /> Sign Out
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function NavItem({ icon, label, href, active = false }: { icon: React.ReactNode; label: string; href: string; active?: boolean }) {
|
||||
return (
|
||||
<Link href={href}>
|
||||
<div className={`flex items-center gap-3 px-3 py-2 text-sm transition-colors cursor-pointer ${active ? 'bg-primary/10 text-primary border-l-2 border-primary' : 'text-muted-foreground hover:text-white hover:bg-white/5'}`}>
|
||||
{icon}
|
||||
{label}
|
||||
</div>
|
||||
</Link>
|
||||
);
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import { useQuery } from "@tanstack/react-query";
|
|||
import { useAuth } from "@/lib/auth";
|
||||
import {
|
||||
Users, FileCode, Shield, Activity, LogOut,
|
||||
Home, BarChart3, Settings, ChevronRight, User
|
||||
Home, BarChart3, Settings, ChevronRight, User, Globe, Award, Key
|
||||
} from "lucide-react";
|
||||
import gridBg from '@assets/generated_images/dark_subtle_digital_grid_texture.png';
|
||||
|
||||
|
|
@ -77,8 +77,11 @@ export default function Admin() {
|
|||
<nav className="flex-1 p-4 space-y-2">
|
||||
<NavItem icon={<BarChart3 className="w-4 h-4" />} label="Dashboard" href="/admin" active />
|
||||
<NavItem icon={<Users className="w-4 h-4" />} label="Architects" href="/admin/architects" />
|
||||
<NavItem icon={<Award className="w-4 h-4" />} label="Achievements" href="/admin/achievements" />
|
||||
<NavItem icon={<FileCode className="w-4 h-4" />} label="Credentials" href="/admin/credentials" />
|
||||
<NavItem icon={<Activity className="w-4 h-4" />} label="Projects" href="/admin/projects" />
|
||||
<NavItem icon={<Globe className="w-4 h-4" />} label="Sites" href="/admin/sites" />
|
||||
<NavItem icon={<Key className="w-4 h-4" />} label="Auth Logs" href="/admin/logs" />
|
||||
<NavItem icon={<Shield className="w-4 h-4" />} label="Aegis Monitor" href="/admin/aegis" />
|
||||
</nav>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@ import { createServer, type Server } from "http";
|
|||
import { storage } from "./storage";
|
||||
import { loginSchema } from "@shared/schema";
|
||||
import bcrypt from "bcrypt";
|
||||
import crypto from "crypto";
|
||||
|
||||
// Extend session type
|
||||
declare module 'express-session' {
|
||||
interface SessionData {
|
||||
userId?: string;
|
||||
isAdmin?: boolean;
|
||||
token?: string;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -31,6 +33,21 @@ function requireAdmin(req: Request, res: Response, next: NextFunction) {
|
|||
next();
|
||||
}
|
||||
|
||||
// Generate JWT-like token
|
||||
function generateToken(userId: string, username: string): string {
|
||||
const header = Buffer.from(JSON.stringify({ alg: "HS256", typ: "JWT" })).toString('base64url');
|
||||
const payload = Buffer.from(JSON.stringify({
|
||||
userId,
|
||||
username,
|
||||
iat: Math.floor(Date.now() / 1000),
|
||||
exp: Math.floor(Date.now() / 1000) + 3600 // 1 hour
|
||||
})).toString('base64url');
|
||||
const signature = crypto.createHmac('sha256', process.env.SESSION_SECRET || 'dev-secret')
|
||||
.update(`${header}.${payload}`)
|
||||
.digest('base64url');
|
||||
return `${header}.${payload}.${signature}`;
|
||||
}
|
||||
|
||||
export async function registerRoutes(
|
||||
httpServer: Server,
|
||||
app: Express
|
||||
|
|
@ -38,7 +55,7 @@ export async function registerRoutes(
|
|||
|
||||
// ========== AUTH ROUTES ==========
|
||||
|
||||
// Login
|
||||
// Login - creates JWT token and stores in sessions table
|
||||
app.post("/api/auth/login", async (req, res) => {
|
||||
try {
|
||||
const result = loginSchema.safeParse(req.body);
|
||||
|
|
@ -58,7 +75,19 @@ export async function registerRoutes(
|
|||
return res.status(401).json({ error: "Invalid credentials" });
|
||||
}
|
||||
|
||||
// Regenerate session on login to prevent session fixation
|
||||
// Generate token like your other apps
|
||||
const token = generateToken(user.id, user.username);
|
||||
const expiresAt = new Date(Date.now() + 3600 * 1000); // 1 hour
|
||||
|
||||
// Store session in sessions table (like your other apps)
|
||||
await storage.createSession({
|
||||
user_id: user.id,
|
||||
username: user.username,
|
||||
token,
|
||||
expires_at: expiresAt.toISOString()
|
||||
});
|
||||
|
||||
// Also set express session for this app
|
||||
req.session.regenerate((err) => {
|
||||
if (err) {
|
||||
return res.status(500).json({ error: "Session error" });
|
||||
|
|
@ -66,9 +95,11 @@ export async function registerRoutes(
|
|||
|
||||
req.session.userId = user.id;
|
||||
req.session.isAdmin = user.is_admin ?? false;
|
||||
req.session.token = token;
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
token,
|
||||
user: {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
|
|
@ -77,6 +108,7 @@ export async function registerRoutes(
|
|||
});
|
||||
});
|
||||
} catch (err: any) {
|
||||
console.error('Login error:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
|
@ -185,6 +217,58 @@ export async function registerRoutes(
|
|||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// ========== NEW ADMIN ROUTES ==========
|
||||
|
||||
// Get all aethex sites (admin only)
|
||||
app.get("/api/sites", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const sites = await storage.getSites();
|
||||
res.json(sites);
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get auth logs (admin only)
|
||||
app.get("/api/auth-logs", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const logs = await storage.getAuthLogs();
|
||||
res.json(logs);
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get achievements (admin only)
|
||||
app.get("/api/achievements", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const achievements = await storage.getAchievements();
|
||||
res.json(achievements);
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get applications (admin only)
|
||||
app.get("/api/applications", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const applications = await storage.getApplications();
|
||||
res.json(applications);
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// Get alerts for Aegis (admin only)
|
||||
app.get("/api/alerts", requireAdmin, async (req, res) => {
|
||||
try {
|
||||
const alerts = await storage.getAlerts();
|
||||
res.json(alerts);
|
||||
} catch (err: any) {
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
return httpServer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ export interface IStorage {
|
|||
getUser(id: string): Promise<User | undefined>;
|
||||
getUserByUsername(username: string): Promise<User | undefined>;
|
||||
|
||||
// Sessions
|
||||
createSession(session: { user_id: string; username: string; token: string; expires_at: string }): Promise<any>;
|
||||
|
||||
// Profiles
|
||||
getProfiles(): Promise<Profile[]>;
|
||||
getProfile(id: string): Promise<Profile | undefined>;
|
||||
|
|
@ -16,6 +19,21 @@ export interface IStorage {
|
|||
getProjects(): Promise<Project[]>;
|
||||
getProject(id: string): Promise<Project | undefined>;
|
||||
|
||||
// Sites
|
||||
getSites(): Promise<any[]>;
|
||||
|
||||
// Auth Logs
|
||||
getAuthLogs(): Promise<any[]>;
|
||||
|
||||
// Achievements
|
||||
getAchievements(): Promise<any[]>;
|
||||
|
||||
// Applications
|
||||
getApplications(): Promise<any[]>;
|
||||
|
||||
// Alerts
|
||||
getAlerts(): Promise<any[]>;
|
||||
|
||||
// Metrics
|
||||
getMetrics(): Promise<{
|
||||
totalProfiles: number;
|
||||
|
|
@ -51,6 +69,17 @@ export class SupabaseStorage implements IStorage {
|
|||
return data as User;
|
||||
}
|
||||
|
||||
async createSession(session: { user_id: string; username: string; token: string; expires_at: string }): Promise<any> {
|
||||
const { data, error } = await supabase
|
||||
.from('sessions')
|
||||
.insert(session)
|
||||
.select()
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
}
|
||||
|
||||
async getProfiles(): Promise<Profile[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('profiles')
|
||||
|
|
@ -116,6 +145,58 @@ export class SupabaseStorage implements IStorage {
|
|||
return data as Project;
|
||||
}
|
||||
|
||||
async getSites(): Promise<any[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('aethex_sites')
|
||||
.select('*')
|
||||
.order('last_check', { ascending: false });
|
||||
|
||||
if (error) return [];
|
||||
return data || [];
|
||||
}
|
||||
|
||||
async getAuthLogs(): Promise<any[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('auth_logs')
|
||||
.select('*')
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(100);
|
||||
|
||||
if (error) return [];
|
||||
return data || [];
|
||||
}
|
||||
|
||||
async getAchievements(): Promise<any[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('achievements')
|
||||
.select('*')
|
||||
.order('name', { ascending: true });
|
||||
|
||||
if (error) return [];
|
||||
return data || [];
|
||||
}
|
||||
|
||||
async getApplications(): Promise<any[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('applications')
|
||||
.select('*')
|
||||
.order('submitted_at', { ascending: false });
|
||||
|
||||
if (error) return [];
|
||||
return data || [];
|
||||
}
|
||||
|
||||
async getAlerts(): Promise<any[]> {
|
||||
const { data, error } = await supabase
|
||||
.from('aethex_alerts')
|
||||
.select('*')
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(50);
|
||||
|
||||
if (error) return [];
|
||||
return data || [];
|
||||
}
|
||||
|
||||
async getMetrics(): Promise<{
|
||||
totalProfiles: number;
|
||||
totalProjects: number;
|
||||
|
|
@ -124,7 +205,6 @@ export class SupabaseStorage implements IStorage {
|
|||
totalXP: number;
|
||||
avgLevel: number;
|
||||
}> {
|
||||
// Get profiles for metrics
|
||||
const profiles = await this.getProfiles();
|
||||
const projects = await this.getProjects();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue