implement activity logging feature with UI for viewing logs

This commit is contained in:
tom.hempel
2026-06-01 21:40:50 +02:00
parent 890232f58f
commit da394c5525
8 changed files with 1129 additions and 13 deletions

View File

@ -7,6 +7,20 @@ require_once __DIR__ . '/../common.php';
require_once __DIR__ . '/../db_init.php';
require_once __DIR__ . '/../lib/response.php';
require_once __DIR__ . '/../lib/validate.php';
require_once __DIR__ . '/../lib/api_log.php';
// Parse route early (for access logs)
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$path = parse_url($requestUri, PHP_URL_PATH);
$base = dirname($_SERVER['SCRIPT_NAME']);
$route = trim(substr($path, strlen($base)), '/');
$route = preg_replace('/\.php$/', '', $route);
$route = strtolower($route);
$method = $_SERVER['REQUEST_METHOD'];
qdb_api_log_begin($method, $route !== '' ? $route : '(root)');
register_shutdown_function('qdb_api_log_finish');
// CORS
header('Access-Control-Allow-Origin: *');
@ -20,16 +34,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header('Content-Type: application/json; charset=UTF-8');
// Parse route: strip /api/ prefix and .php suffix, normalize
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
$path = parse_url($requestUri, PHP_URL_PATH);
$base = dirname($_SERVER['SCRIPT_NAME']);
$route = trim(substr($path, strlen($base)), '/');
$route = preg_replace('/\.php$/', '', $route);
$route = strtolower($route);
$method = $_SERVER['REQUEST_METHOD'];
// Dispatch table: route -> handler file
$routes = [
'questionnaires' => __DIR__ . '/../handlers/questionnaires.php',
@ -51,6 +55,7 @@ $routes = [
'dev' => __DIR__ . '/../handlers/dev.php',
'dev/import' => __DIR__ . '/../handlers/dev.php',
'health' => __DIR__ . '/../handlers/health.php',
'activity-log' => __DIR__ . '/../handlers/activity_log.php',
];
try {
@ -66,6 +71,7 @@ try {
require $handlerFile;
} catch (Throwable $e) {
qdb_api_log_note_exception($e);
error_log("Unhandled error on $method $route: " . $e->getMessage());
json_error('SERVER_ERROR', 'Internal server error', 500);
}