Create get-json.php

This commit is contained in:
SubleXBle
2025-08-16 20:27:10 +02:00
committed by GitHub
parent a486cd904e
commit 73baba9d1d

View File

@@ -0,0 +1,21 @@
<?php
// includes/get-json.php
require_once __DIR__ . '/paths.php';
$filename = basename($_GET['file'] ?? '');
$filepath = $PATHS["fail2ban"] . '/' . $filename;
// secure: it can only read json from archive
if (
!$filename ||
!preg_match('/^fail2ban-events-\d{8}\.json$/', $filename) ||
strpos(realpath($filepath), realpath($PATHS["fail2ban"])) !== 0 ||
!file_exists($filepath)
) {
http_response_code(404);
exit('Not found');
}
// deliver header and json
header('Content-Type: application/json');
readfile($filepath);