Add request logging, bot blocking, and admin log viewer

This commit is contained in:
2026-07-28 14:51:55 +02:00
parent 13dd72d14d
commit df8394b057
6 changed files with 284 additions and 0 deletions
+22
View File
@@ -89,5 +89,27 @@ if (strpos($path, '/content/') === 0) {
exit;
}
// Bot detection — block known bots/AI scrapers early
if (RequestLogger::detectBot() !== null) {
http_response_code(403);
echo '<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>403 Forbidden</title><meta name="robots" content="noindex,nofollow"></head><body><h1>403 Forbidden</h1><p>Access denied.</p></body></html>';
exit;
}
$cms = new CodePressCMS($config);
// Log page view (not for media/assets)
if (!str_starts_with($path, '/-media/') && !str_starts_with($path, '/-assets/')) {
$requestLogFile = dirname(__DIR__) . '/admin/storage/logs/requests.log';
$logger = new RequestLogger($requestLogFile);
$logger->log(
$_GET['page'] ?? $config['default_page'] ?? 'index',
$_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? 'cli',
$_SERVER['HTTP_USER_AGENT'] ?? '',
$_SERVER['HTTP_REFERER'] ?? '',
$_SERVER['HTTP_HOST'] ?? '',
$_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? ''
);
}
$cms->render();