Create blocklist-stats.php

added new stats
This commit is contained in:
SubleXBle
2025-08-06 13:08:34 +02:00
committed by GitHub
parent d9b8346196
commit 0efec17ff1

View File

@@ -0,0 +1,42 @@
<?php
// Set correct path to your blocklist directory
$blocklistDir = '/var/www/vhosts/suble.org/xbkupx/Fail2Ban-Report/archive/';
$stats = [];
foreach (glob($blocklistDir . '*.blocklist.json') as $filepath) {
$filename = basename($filepath);
// Extract jail name (remove .blocklist.json)
$jail = preg_replace('/\.blocklist\.json$/', '', $filename);
if (!$jail) continue;
// Read JSON
$json = file_get_contents($filepath);
if (!$json) continue;
$entries = json_decode($json, true);
if (!is_array($entries)) continue;
// Initialize counters
$active = 0;
$pending = 0;
foreach ($entries as $entry) {
if (!isset($entry['active'])) continue;
if ($entry['active'] === true) {
$active++;
} else {
$pending++;
}
}
// Store result
$stats[$jail] = [
'active' => $active,
'pending' => $pending
];
}
// Output JSON
header('Content-Type: application/json');
echo json_encode($stats);