'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=

msg= 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);