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 { Input } from "@/components/ui/input"; import { AlertTriangle, Search, Shield, Eye, Globe, MapPin, Building2 } from "lucide-react"; import { format } from "date-fns"; import { useState } from "react"; import type { Detection } from "@shared/schema"; import { getFlag } from "@/lib/country-flags"; export default function Detections() { const [searchQuery, setSearchQuery] = useState(""); const { data: detections, isLoading } = useQuery({ queryKey: ["/api/detections"], refetchInterval: 5000, }); const filteredDetections = detections?.filter((d) => d.sourceIp.toLowerCase().includes(searchQuery.toLowerCase()) || d.anomalyType.toLowerCase().includes(searchQuery.toLowerCase()) ); 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; }; const getAnomalyTypeLabel = (type: string) => { const labels: Record = { ddos: "DDoS Attack", port_scan: "Port Scanning", brute_force: "Brute Force", botnet: "Botnet Activity", suspicious: "Suspicious Activity" }; return labels[type] || type; }; return (

Rilevamenti

Anomalie rilevate dal sistema IDS

{/* Search and Filters */}
setSearchQuery(e.target.value)} className="pl-9" data-testid="input-search" />
{/* Detections List */} Rilevamenti ({filteredDetections?.length || 0}) {isLoading ? (
Caricamento...
) : filteredDetections && filteredDetections.length > 0 ? (
{filteredDetections.map((detection) => (
{/* Flag Emoji */} {detection.countryCode && ( {getFlag(detection.country, detection.countryCode)} )} {detection.sourceIp} {getRiskBadge(detection.riskScore)} {getAnomalyTypeLabel(detection.anomalyType)}

{detection.reason}

{/* Geolocation Info */} {(detection.country || detection.organization || detection.asNumber) && (
{detection.country && (
{detection.city ? `${detection.city}, ${detection.country}` : detection.country}
)} {detection.organization && (
{detection.organization}
)} {detection.asNumber && (
{detection.asNumber} {detection.asName && `- ${detection.asName}`}
)}
)}

Risk Score

{parseFloat(detection.riskScore).toFixed(1)}/100

Confidence

{parseFloat(detection.confidence).toFixed(1)}%

Log Count

{detection.logCount}

Rilevato

{format(new Date(detection.detectedAt), "dd/MM HH:mm")}

Prima: {format(new Date(detection.firstSeen), "dd/MM HH:mm:ss")} Ultima: {format(new Date(detection.lastSeen), "dd/MM HH:mm:ss")}
{detection.blocked ? ( Bloccato ) : ( Attivo )}
))}
) : (

Nessun rilevamento trovato

{searchQuery && (

Prova con un altro termine di ricerca

)}
)}
); }