Compare commits

..

No commits in common. "aa589ab64d1d22d178d0de68a814ef008fc07414" and "89a531eec4dda1b27f8a54c21ff7a95de8ef175b" have entirely different histories.

6 changed files with 39 additions and 159 deletions

View File

@ -1,2 +0,0 @@
curl -X POST http://localhost:8000/block-all-critical -H "Content-Type: application/json" -d '{"min_score": 80}'
{"message":"Blocco massivo completato: 0 IP bloccati, 260 falliti","blocked":0,"failed":260,"total_critical":260,"details":[{"ip":"157.240.231.60","score":99.99,"status":"failed"},{"ip":"5.134.122.207","score":99.91,"status":"failed"},{"ip":"79.6.115.203","score":99.75,"status":"failed"},{"ip":"37.13.179.85","score":99.15,"status":"failed"},{"ip":"129.69.0.42","score":99.03,"status":"failed"},{"ip":"104.18.36.146","score":97.96,"status":"failed"},{"ip":"88.39.149.52","score":97.14,"status":"failed"},{"ip":"216.58.204.150","score":96.31,"status":"failed"},{"ip":"83.230.138.36","score":96.05,"status":"failed"},{"ip":"80.211.249.119","score":95.86,"status":"failed"},{"ip":"104.18.38.59","score":95.85,"status":"failed"},{"ip":"216.58.204.142","score":95.83,"status":"failed"},{"ip":"185.30.182.159","score":95.56,"status":"failed"},{"ip":"142.251.140.100","score":94.94,"status":"failed"},{"ip":"146.247.137.195","score":94.86,"status":"failed"},{"ip":"172.64.146.98","score":93.8,"status":"failed"},{"ip":"34.252.43.174","score":93.6,"status":"failed"},{"ip":"199.232.194.27","score":93.53,"status":"failed"},{"ip":"151.58.164.255","score":93.49,"status":"failed"},{"ip":"146.247.137.121","score":93.25,"status":"failed"},{"ip":"192.178.202.119","score":92.71,"status":"failed"},{"ip":"195.32.16.194","score":92.39,"status":"failed"},{"ip":"5.90.193.36","score":92.27,"status":"failed"},{"ip":"51.161.172.246","score":92.12,"status":"failed"},{"ip":"83.217.187.128","score":92.05,"status":"failed"},{"ip":"23.216.150.188","score":92.04,"status":"failed"},{"ip":"34.160.109.235","score":91.95,"status":"failed"},{"ip":"13.107.246.43","score":91.93,"status":"failed"},{"ip":"151.101.66.27","score":91.93,"status":"failed"},{"ip":"10.0.237.18","score":91.75,"status":"failed"},{"ip":"5.63.17.10","score":91.66,"status":"failed"},{"ip":"74.125.45.108","score":91.66,"status":"failed"},{"ip":"109.54.106.99","score":91.63,"status":"failed"},{"ip":"103.169.126.50","score":91.49,"status":"failed"},{"ip":"103.169.126.52","score":91.49,"status":"failed"},{"ip":"93.39.92.133","score":91.26,"status":"failed"},{"ip":"103.169.126.16","score":91.18,"status":"failed"},{"ip":"52.123.255.227","score":91.18,"status":"failed"},{"ip":"77.89.41.174","score":91.13,"status":"failed"},{"ip":"93.148.252.209","score":91.12,"status":"failed"},{"ip":"94.101.54.84","score":90.95,"status":"failed"},{"ip":"23.239.11.118","score":90.86,"status":"failed"},{"ip":"52.123.129.14","score":90.66,"status":"failed"},{"ip":"151.78.177.243","score":90.6,"status":"failed"},{"ip":"151.19.103.232","score":90.53,"status":"failed"},{"ip":"35.219.227.195","score":90.29,"status":"failed"},{"ip":"103.169.126.48","score":90.28,"status":"failed"},{"ip":"103.169.126.197","score":90.26,"status":"failed"},{"ip":"151.5.26.99","score":90.24,"status":"failed"},{"ip":"103.169.126.203","score":90.2,"status":"failed"}]}[root@ids ids]#

View File

@ -2,9 +2,9 @@ import { useQuery, useMutation } from "@tanstack/react-query";
import { queryClient, apiRequest } from "@/lib/queryClient";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Shield, Plus, Trash2, CheckCircle2, XCircle, Search, ChevronLeft, ChevronRight } from "lucide-react";
import { Shield, Plus, Trash2, CheckCircle2, XCircle, Search } from "lucide-react";
import { format } from "date-fns";
import { useState, useEffect, useMemo } from "react";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
@ -31,8 +31,6 @@ import {
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
const ITEMS_PER_PAGE = 50;
const whitelistFormSchema = insertWhitelistSchema.extend({
ipAddress: z.string()
.min(7, "Inserisci un IP valido")
@ -43,17 +41,10 @@ const whitelistFormSchema = insertWhitelistSchema.extend({
}, "Ogni ottetto deve essere tra 0 e 255"),
});
interface WhitelistResponse {
items: Whitelist[];
total: number;
}
export default function WhitelistPage() {
const { toast } = useToast();
const [isAddDialogOpen, setIsAddDialogOpen] = useState(false);
const [searchInput, setSearchInput] = useState("");
const [debouncedSearch, setDebouncedSearch] = useState("");
const [currentPage, setCurrentPage] = useState(1);
const [searchQuery, setSearchQuery] = useState("");
const form = useForm<z.infer<typeof whitelistFormSchema>>({
resolver: zodResolver(whitelistFormSchema),
@ -65,33 +56,16 @@ export default function WhitelistPage() {
},
});
useEffect(() => {
const timer = setTimeout(() => {
setDebouncedSearch(searchInput);
setCurrentPage(1);
}, 300);
return () => clearTimeout(timer);
}, [searchInput]);
const queryParams = useMemo(() => {
const params = new URLSearchParams();
params.set("limit", ITEMS_PER_PAGE.toString());
params.set("offset", ((currentPage - 1) * ITEMS_PER_PAGE).toString());
if (debouncedSearch.trim()) {
params.set("search", debouncedSearch.trim());
}
return params.toString();
}, [currentPage, debouncedSearch]);
const { data, isLoading } = useQuery<WhitelistResponse>({
queryKey: ["/api/whitelist", currentPage, debouncedSearch],
queryFn: () => fetch(`/api/whitelist?${queryParams}`).then(r => r.json()),
refetchInterval: 10000,
const { data: whitelist, isLoading } = useQuery<Whitelist[]>({
queryKey: ["/api/whitelist"],
});
const whitelistItems = data?.items || [];
const totalCount = data?.total || 0;
const totalPages = Math.ceil(totalCount / ITEMS_PER_PAGE);
// Filter whitelist based on search query
const filteredWhitelist = whitelist?.filter((item) =>
item.ipAddress.toLowerCase().includes(searchQuery.toLowerCase()) ||
item.reason?.toLowerCase().includes(searchQuery.toLowerCase()) ||
item.comment?.toLowerCase().includes(searchQuery.toLowerCase())
);
const addMutation = useMutation({
mutationFn: async (data: z.infer<typeof whitelistFormSchema>) => {
@ -229,9 +203,9 @@ export default function WhitelistPage() {
<div className="relative">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Cerca per IP, motivo, note o sorgente..."
value={searchInput}
onChange={(e) => setSearchInput(e.target.value)}
placeholder="Cerca per IP, motivo o note..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-9"
data-testid="input-search-whitelist"
/>
@ -241,36 +215,9 @@ export default function WhitelistPage() {
<Card data-testid="card-whitelist">
<CardHeader>
<CardTitle className="flex items-center justify-between gap-2 flex-wrap">
<div className="flex items-center gap-2">
<Shield className="h-5 w-5" />
IP Protetti ({totalCount})
</div>
{totalPages > 1 && (
<div className="flex items-center gap-2 text-sm font-normal">
<Button
variant="outline"
size="icon"
onClick={() => setCurrentPage(p => Math.max(1, p - 1))}
disabled={currentPage === 1}
data-testid="button-prev-page"
>
<ChevronLeft className="h-4 w-4" />
</Button>
<span data-testid="text-pagination">
Pagina {currentPage} di {totalPages}
</span>
<Button
variant="outline"
size="icon"
onClick={() => setCurrentPage(p => Math.min(totalPages, p + 1))}
disabled={currentPage === totalPages}
data-testid="button-next-page"
>
<ChevronRight className="h-4 w-4" />
</Button>
</div>
)}
<CardTitle className="flex items-center gap-2">
<Shield className="h-5 w-5" />
IP Protetti ({filteredWhitelist?.length || 0}{searchQuery && whitelist ? ` di ${whitelist.length}` : ''})
</CardTitle>
</CardHeader>
<CardContent>
@ -278,9 +225,9 @@ export default function WhitelistPage() {
<div className="text-center py-8 text-muted-foreground" data-testid="text-loading">
Caricamento...
</div>
) : whitelistItems.length > 0 ? (
) : filteredWhitelist && filteredWhitelist.length > 0 ? (
<div className="space-y-3">
{whitelistItems.map((item) => (
{filteredWhitelist.map((item) => (
<div
key={item.id}
className="p-4 rounded-lg border hover-elevate"
@ -325,45 +272,12 @@ export default function WhitelistPage() {
</div>
</div>
))}
{/* Bottom pagination */}
{totalPages > 1 && (
<div className="flex items-center justify-center gap-4 mt-6 pt-4 border-t">
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage(p => Math.max(1, p - 1))}
disabled={currentPage === 1}
data-testid="button-prev-page-bottom"
>
<ChevronLeft className="h-4 w-4 mr-1" />
Precedente
</Button>
<span className="text-sm text-muted-foreground" data-testid="text-pagination-bottom">
Pagina {currentPage} di {totalPages} ({totalCount} totali)
</span>
<Button
variant="outline"
size="sm"
onClick={() => setCurrentPage(p => Math.min(totalPages, p + 1))}
disabled={currentPage === totalPages}
data-testid="button-next-page-bottom"
>
Successiva
<ChevronRight className="h-4 w-4 ml-1" />
</Button>
</div>
)}
</div>
) : (
<div className="text-center py-12 text-muted-foreground" data-testid="text-empty">
<Shield className="h-12 w-12 mx-auto mb-4 opacity-50" />
<p className="font-medium">Nessun IP in whitelist</p>
{debouncedSearch ? (
<p className="text-sm mt-2">Prova con un altro termine di ricerca</p>
) : (
<p className="text-sm mt-2">Aggiungi indirizzi IP fidati per proteggerli dal blocco automatico</p>
)}
<p className="text-sm mt-2">Aggiungi indirizzi IP fidati per proteggerli dal blocco automatico</p>
</div>
)}
</CardContent>

View File

@ -2,7 +2,7 @@
-- PostgreSQL database dump
--
\restrict bngYLsJZNRm4sGjAcrPW2v7ZwM0VwW8FjcxWfRcYzZDDKc2X525bYmyFEXzl1yh
\restrict VfY2jMibUtM7epqSxI0eI9IK5petlVg4wE8lvRgi6qIK19f865uN5QWYQxOQJY8
-- Dumped from database version 16.11 (df20cf9)
-- Dumped by pg_dump version 16.10
@ -387,5 +387,5 @@ ALTER TABLE ONLY public.public_blacklist_ips
-- PostgreSQL database dump complete
--
\unrestrict bngYLsJZNRm4sGjAcrPW2v7ZwM0VwW8FjcxWfRcYzZDDKc2X525bYmyFEXzl1yh
\unrestrict VfY2jMibUtM7epqSxI0eI9IK5petlVg4wE8lvRgi6qIK19f865uN5QWYQxOQJY8

View File

@ -122,12 +122,8 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Whitelist
app.get("/api/whitelist", async (req, res) => {
try {
const limit = parseInt(req.query.limit as string) || 50;
const offset = parseInt(req.query.offset as string) || 0;
const search = req.query.search as string || undefined;
const result = await storage.getAllWhitelist({ limit, offset, search });
res.json(result);
const whitelist = await storage.getAllWhitelist();
res.json(whitelist);
} catch (error) {
console.error('[DB ERROR] Failed to fetch whitelist:', error);
res.status(500).json({ error: "Failed to fetch whitelist" });
@ -484,7 +480,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
const routers = await storage.getAllRouters();
const detectionsResult = await storage.getAllDetections({ limit: 1000 });
const recentLogs = await storage.getRecentLogs(1000);
const whitelistResult = await storage.getAllWhitelist({ limit: 1 });
const whitelist = await storage.getAllWhitelist();
const latestTraining = await storage.getLatestTraining();
const detectionsList = detectionsResult.detections;
@ -507,7 +503,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
recent: recentLogs.length
},
whitelist: {
total: whitelistResult.total
total: whitelist.length
},
latestTraining: latestTraining
});

View File

@ -55,7 +55,7 @@ export interface IStorage {
getUnblockedDetections(): Promise<Detection[]>;
// Whitelist
getAllWhitelist(options?: { limit?: number; offset?: number; search?: string }): Promise<{ items: Whitelist[]; total: number }>;
getAllWhitelist(): Promise<Whitelist[]>;
getWhitelistByIp(ipAddress: string): Promise<Whitelist | undefined>;
createWhitelist(whitelist: InsertWhitelist): Promise<Whitelist>;
deleteWhitelist(id: string): Promise<boolean>;
@ -271,40 +271,12 @@ export class DatabaseStorage implements IStorage {
}
// Whitelist
async getAllWhitelist(options?: { limit?: number; offset?: number; search?: string }): Promise<{ items: Whitelist[]; total: number }> {
const limit = options?.limit || 50;
const offset = options?.offset || 0;
const search = options?.search?.trim().toLowerCase();
const conditions: any[] = [eq(whitelist.active, true)];
if (search) {
conditions.push(
sql`(
LOWER(${whitelist.ipAddress}) LIKE ${'%' + search + '%'}
OR LOWER(COALESCE(${whitelist.reason}, '')) LIKE ${'%' + search + '%'}
OR LOWER(COALESCE(${whitelist.comment}, '')) LIKE ${'%' + search + '%'}
OR LOWER(COALESCE(${whitelist.source}, '')) LIKE ${'%' + search + '%'}
)`
);
}
const whereClause = and(...conditions);
const [countResult] = await db
.select({ count: sql<number>`cast(count(*) as integer)` })
.from(whitelist)
.where(whereClause);
const items = await db
async getAllWhitelist(): Promise<Whitelist[]> {
return await db
.select()
.from(whitelist)
.where(whereClause)
.orderBy(desc(whitelist.createdAt))
.limit(limit)
.offset(offset);
return { items, total: countResult.count };
.where(eq(whitelist.active, true))
.orderBy(desc(whitelist.createdAt));
}
async getWhitelistByIp(ipAddress: string): Promise<Whitelist | undefined> {

View File

@ -1,13 +1,7 @@
{
"version": "1.0.108",
"lastUpdate": "2026-02-14T10:47:54.686Z",
"version": "1.0.107",
"lastUpdate": "2026-02-14T10:15:20.502Z",
"changelog": [
{
"version": "1.0.108",
"date": "2026-02-14",
"type": "patch",
"description": "Deployment automatico v1.0.108"
},
{
"version": "1.0.107",
"date": "2026-02-14",
@ -301,6 +295,12 @@
"date": "2025-11-24",
"type": "patch",
"description": "Deployment automatico v1.0.59"
},
{
"version": "1.0.58",
"date": "2025-11-24",
"type": "patch",
"description": "Deployment automatico v1.0.58"
}
]
}