Files
html/api/router-activity.php
opus f96f2871c5
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
auto-sync via WEVIA git_sync_all intent 2026-04-21T03:23:36+02:00
2026-04-21 03:23:36 +02:00

53 lines
1.4 KiB
PHP

<?php
/**
* V113 - Router Activity API - show recent V103 multi-agent router matches
* GET /api/router-activity.php?k=WEVADS2026&limit=50
*/
header('Content-Type: application/json');
$k = $_GET['k'] ?? '';
if ($k !== 'WEVADS2026') { http_response_code(403); die(json_encode(['error'=>'auth'])); }
$limit = (int)($_GET['limit'] ?? 50);
$limit = max(1, min(500, $limit));
$log = '/tmp/v103-router.log';
if (!file_exists($log)) {
echo json_encode(['matches'=>[],'count'=>0,'log_missing'=>true]);
exit;
}
$lines = @file($log, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (!$lines) {
echo json_encode(['matches'=>[],'count'=>0]);
exit;
}
$recent = array_slice($lines, -$limit);
$matches = [];
foreach ($recent as $line) {
// Parse: YYYY-MM-DDTHH:MM:SS+00:00 MATCH pattern=<p> msg=<m>
if (preg_match('/^(\S+)\s+MATCH\s+pattern=(\S+)\s+msg=(.*)$/', $line, $m)) {
$matches[] = [
'ts' => $m[1],
'pattern' => substr($m[2], 0, 60),
'msg' => substr($m[3], 0, 200)
];
}
}
// Aggregate by pattern
$byPattern = [];
foreach ($matches as $m) {
$p = $m['pattern'];
if (!isset($byPattern[$p])) $byPattern[$p] = 0;
$byPattern[$p]++;
}
arsort($byPattern);
echo json_encode([
'matches' => array_reverse($matches), // most recent first
'count' => count($matches),
'by_pattern' => $byPattern,
'total_log_lines' => count($lines)
], JSON_UNESCAPED_UNICODE);