import { useQuery } from "@tanstack/react-query"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Activity, Shield, Server, AlertTriangle, CheckCircle2, TrendingUp } from "lucide-react"; import { format } from "date-fns"; import type { Detection, Router, TrainingHistory } from "@shared/schema"; interface StatsResponse { routers: { total: number; enabled: number }; detections: { total: number; blocked: number; critical: number; high: number }; logs: { recent: number }; whitelist: { total: number }; latestTraining: TrainingHistory | null; } export default function Dashboard() { const { data: stats } = useQuery({ queryKey: ["/api/stats"], refetchInterval: 10000, // Refresh every 10s }); const { data: recentDetections } = useQuery({ queryKey: ["/api/detections"], refetchInterval: 5000, // Refresh every 5s }); const { data: routers } = useQuery({ queryKey: ["/api/routers"], }); const getRiskBadge = (riskScore: string) => { const score = parseFloat(riskScore); if (score >= 85) return CRITICO; if (score >= 70) return ALTO; if (score >= 60) return MEDIO; if (score >= 40) return BASSO; return NORMALE; }; return (

IDS Dashboard

Monitoring real-time del sistema di rilevamento intrusioni

{/* Stats Grid */}
Router Attivi
{stats?.routers.enabled || 0}/{stats?.routers.total || 0}

Router configurati

Rilevamenti
{stats?.detections.total || 0}

{stats?.detections.critical || 0} critici, {stats?.detections.high || 0} alti

IP Bloccati
{stats?.detections.blocked || 0}

IP attualmente bloccati

Log Recenti
{stats?.logs.recent || 0}

Ultimi 1000 log analizzati

{/* Training Status */} {stats?.latestTraining && ( Ultimo Training

Data

{format(new Date(stats.latestTraining.trainedAt), "dd/MM/yyyy HH:mm")}

Record

{stats.latestTraining.recordsProcessed.toLocaleString()}

Feature

{stats.latestTraining.featuresCount}

Stato

{stats.latestTraining.status}
{stats.latestTraining.notes && (

{stats.latestTraining.notes}

)}
)} {/* Recent Detections */} Rilevamenti Recenti
{recentDetections && recentDetections.length > 0 ? ( recentDetections.slice(0, 5).map((detection) => (
{detection.sourceIp} {getRiskBadge(detection.riskScore)} {detection.anomalyType}

{detection.reason}

Risk: {parseFloat(detection.riskScore).toFixed(1)} Confidence: {parseFloat(detection.confidence).toFixed(1)}% {detection.logCount} log
{detection.blocked ? ( Bloccato ) : ( Attivo )}
)) ) : (

Nessun rilevamento recente

Il sistema sta monitorando il traffico

)}
{/* Routers Status */} {routers && routers.length > 0 && ( Router MikroTik
{routers.map((router) => (

{router.name}

{router.enabled ? "Attivo" : "Disabilitato"}

{router.ipAddress}:{router.apiPort}

{router.lastSync && (

Ultima sync: {format(new Date(router.lastSync), "HH:mm:ss")}

)}
))}
)}
); }