Compare commits
3 Commits
64c491f245
...
544b7cfa49
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
544b7cfa49 | ||
|
|
1fc63c657a | ||
|
|
b45b810eb9 |
@ -2,7 +2,7 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict egAwyE4B3wEnHssUVHxJ464Lb0Kmj4HSy1kjprHurOlkfHG9LdbCjmrWhLywb8F
|
||||
\restrict f7Q5mSLZ6vWDok89gagYtp9j07wIocFgGXfuMOImRKtOLNzZO3glMcFoPsKcwyf
|
||||
|
||||
-- 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 egAwyE4B3wEnHssUVHxJ464Lb0Kmj4HSy1kjprHurOlkfHG9LdbCjmrWhLywb8F
|
||||
\unrestrict f7Q5mSLZ6vWDok89gagYtp9j07wIocFgGXfuMOImRKtOLNzZO3glMcFoPsKcwyf
|
||||
|
||||
|
||||
@ -22,8 +22,8 @@ SyslogIdentifier=ids-auto-block
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
|
||||
# Timeout: max 5 minuti per detection+blocking
|
||||
TimeoutStartSec=300
|
||||
# Timeout: max 8 minuti per detection+blocking
|
||||
TimeoutStartSec=480
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@ -58,7 +58,7 @@ def auto_block():
|
||||
"limit": 200,
|
||||
"list_name": "ddos_blocked"
|
||||
},
|
||||
timeout=120
|
||||
timeout=300
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
@ -85,7 +85,7 @@ def auto_block():
|
||||
print(f"[{timestamp}] ERRORE: Node.js backend non raggiungibile su {NODE_API_URL}")
|
||||
return 1
|
||||
except requests.exceptions.Timeout:
|
||||
print(f"[{timestamp}] ERRORE: Timeout blocco IP (120s)")
|
||||
print(f"[{timestamp}] ERRORE: Timeout blocco IP (300s)")
|
||||
return 1
|
||||
except Exception as e:
|
||||
print(f"[{timestamp}] ERRORE imprevisto: {type(e).__name__}: {e}")
|
||||
|
||||
@ -20,7 +20,7 @@ async function mikrotikRequest(
|
||||
method: string,
|
||||
path: string,
|
||||
body?: any,
|
||||
timeoutMs: number = 10000
|
||||
timeoutMs: number = 8000
|
||||
): Promise<{ status: number; data: any }> {
|
||||
const useHttps = router.apiPort === 443;
|
||||
const protocol = useHttps ? "https" : "http";
|
||||
@ -239,14 +239,21 @@ export async function bulkBlockIps(
|
||||
return { blocked: 0, failed: 0, skipped: 0, details: [] };
|
||||
}
|
||||
|
||||
console.log(`[BULK-BLOCK] Starting: ${ipList.length} IPs on ${enabled.length} routers`);
|
||||
console.log(`[BULK-BLOCK] Starting: ${ipList.length} IPs on ${enabled.length} routers (${enabled.map(r => r.ipAddress).join(', ')})`);
|
||||
|
||||
const routerStatus = new Map<string, { ok: number; fail: number; skip: number }>();
|
||||
for (const r of enabled) {
|
||||
routerStatus.set(r.ipAddress, { ok: 0, fail: 0, skip: 0 });
|
||||
}
|
||||
|
||||
const existingCache = new Map<string, Set<string>>();
|
||||
await Promise.allSettled(
|
||||
enabled.map(async (router) => {
|
||||
const start = Date.now();
|
||||
const existing = await getExistingBlockedIps(router, listName);
|
||||
const elapsed = Date.now() - start;
|
||||
existingCache.set(router.ipAddress, existing);
|
||||
console.log(`[BULK-BLOCK] Router ${router.ipAddress}: ${existing.size} IPs already in list`);
|
||||
console.log(`[BULK-BLOCK] Router ${router.ipAddress}: ${existing.size} IPs already in list (${elapsed}ms)`);
|
||||
})
|
||||
);
|
||||
|
||||
@ -279,8 +286,23 @@ export async function bulkBlockIps(
|
||||
const routerResults = await Promise.allSettled(
|
||||
enabled.map(async (router) => {
|
||||
const existing = existingCache.get(router.ipAddress) || new Set();
|
||||
if (existing.has(ip)) return true;
|
||||
if (existing.has(ip)) {
|
||||
const st = routerStatus.get(router.ipAddress);
|
||||
if (st) st.skip++;
|
||||
return true;
|
||||
}
|
||||
const start = Date.now();
|
||||
const result = await addToAddressList(router, ip, listName, `${commentPrefix} ${ip}`, timeoutDuration);
|
||||
const elapsed = Date.now() - start;
|
||||
const st = routerStatus.get(router.ipAddress);
|
||||
if (result.success) {
|
||||
if (st) st.ok++;
|
||||
} else {
|
||||
if (st) st.fail++;
|
||||
if (elapsed > 5000) {
|
||||
console.warn(`[BULK-BLOCK] SLOW: Router ${router.ipAddress} took ${elapsed}ms for IP ${ip}: ${result.error}`);
|
||||
}
|
||||
}
|
||||
return result.success;
|
||||
})
|
||||
);
|
||||
@ -311,6 +333,10 @@ export async function bulkBlockIps(
|
||||
details.push({ ip, status: "already_blocked" });
|
||||
}
|
||||
|
||||
// Report per-router
|
||||
routerStatus.forEach((st, routerIp) => {
|
||||
console.log(`[BULK-BLOCK] Router ${routerIp}: ${st.ok} blocked, ${st.fail} failed, ${st.skip} skipped`);
|
||||
});
|
||||
console.log(`[BULK-BLOCK] Done: ${blocked} blocked, ${failed} failed, ${skippedIps.length} skipped`);
|
||||
|
||||
return { blocked, failed, skipped: skippedIps.length, details };
|
||||
|
||||
16
version.json
16
version.json
@ -1,7 +1,13 @@
|
||||
{
|
||||
"version": "1.0.118",
|
||||
"lastUpdate": "2026-02-16T18:28:03.809Z",
|
||||
"version": "1.0.119",
|
||||
"lastUpdate": "2026-02-17T07:32:28.004Z",
|
||||
"changelog": [
|
||||
{
|
||||
"version": "1.0.119",
|
||||
"date": "2026-02-17",
|
||||
"type": "patch",
|
||||
"description": "Deployment automatico v1.0.119"
|
||||
},
|
||||
{
|
||||
"version": "1.0.118",
|
||||
"date": "2026-02-16",
|
||||
@ -295,12 +301,6 @@
|
||||
"date": "2025-11-25",
|
||||
"type": "patch",
|
||||
"description": "Deployment automatico v1.0.70"
|
||||
},
|
||||
{
|
||||
"version": "1.0.69",
|
||||
"date": "2025-11-25",
|
||||
"type": "patch",
|
||||
"description": "Deployment automatico v1.0.69"
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user