mirror of
https://github.com/SubleXBle/Fail2Ban-Report.git
synced 2026-02-11 03:09:03 -06:00
Create blocklist-stats.php
added new stats
This commit is contained in:
42
includes/blocklist-stats.php
Normal file
42
includes/blocklist-stats.php
Normal 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);
|
||||
Reference in New Issue
Block a user