94 lines
4.3 KiB
PHP
94 lines
4.3 KiB
PHP
<?php
|
|
// WEVIA REGRESSION SCANNER — cron 0 * * * * (hourly)
|
|
// Scans ALL HTML pages + APIs for 500/404/blank/broken
|
|
// Auto-detects regressions vs last scan
|
|
set_time_limit(300);
|
|
$LOG="/var/log/wevia-regression-scanner.log";
|
|
$SF="/var/www/html/api/wevia-regression-status.json";
|
|
$ts=date("H:i");
|
|
$issues=[];$total=0;$ok_count=0;$results=[];
|
|
|
|
function lg($m){global $LOG,$ts;file_put_contents($LOG,"$ts $m\n",FILE_APPEND);}
|
|
|
|
// Discover all HTML pages
|
|
$pages=[];
|
|
foreach(glob("/var/www/html/*.html") as $f) $pages[]=basename($f);
|
|
foreach(glob("/var/www/html/products/*.html") as $f) $pages[]="products/".basename($f);
|
|
foreach(glob("/var/www/html/test-report/*.html") as $f) $pages[]="test-report/".basename($f);
|
|
foreach(glob("/var/www/html/blog/*.html") as $f) $pages[]="blog/".basename($f);
|
|
foreach(glob("/var/www/html/wevia-ia/*.html") as $f) $pages[]="wevia-ia/".basename($f);
|
|
|
|
// API endpoints
|
|
$apis = ['api/wevia-master-api.php?action=health','api/wevia-action-engine.php?action=help',
|
|
'api/wevia-dashboard.php','api/wevia-quality-status.json','api/wevia-auth-status.json',
|
|
'api/l99-ux-results.json','api/nonreg-latest.json','api/architecture-index.json',
|
|
'api/weval-ia-fast.php','api/wevia-autonomous.php'];
|
|
|
|
$all = array_merge(array_map(fn($p)=>[$p,'page'], $pages), array_map(fn($a)=>[$a,'api'], $apis));
|
|
$total = count($all);
|
|
|
|
foreach($all as [$path,$type]) {
|
|
$url = "https://weval-consulting.com/$path";
|
|
$ch = curl_init($url);
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>1, CURLOPT_TIMEOUT=>8,
|
|
CURLOPT_SSL_VERIFYPEER=>0, CURLOPT_FOLLOWLOCATION=>1, CURLOPT_NOBODY=>0]);
|
|
$body = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$size = curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD);
|
|
curl_close($ch);
|
|
|
|
$status = 'ok';
|
|
$detail = '';
|
|
|
|
if ($code >= 500) { $status = 'error'; $detail = "HTTP $code (server error)"; }
|
|
elseif ($code == 404) { $status = 'missing'; $detail = "HTTP 404 (not found)"; }
|
|
elseif ($code == 0) { $status = 'unreachable'; $detail = "Connection failed"; }
|
|
elseif ($type === 'page' && $code == 200 && $size < 200) { $status = 'blank'; $detail = "Blank page ($size bytes)"; }
|
|
elseif ($type === 'page' && $code == 200 && strpos($body, '<title>Error</title>') !== false) { $status = 'error_page'; $detail = "Error page detected"; }
|
|
elseif ($type === 'api' && $code == 200 && strpos($body, '<!doctype') !== false && strpos($body, '"ok"') === false) { $status = 'html_instead_json'; $detail = "Returns HTML instead of JSON"; }
|
|
|
|
if ($status === 'ok') $ok_count++;
|
|
else $issues[] = ['path'=>$path, 'type'=>$type, 'status'=>$status, 'detail'=>$detail, 'code'=>$code, 'size'=>(int)$size];
|
|
|
|
$results[$path] = ['status'=>$status, 'code'=>$code, 'size'=>(int)$size];
|
|
}
|
|
|
|
// Compare with last scan for regression detection
|
|
$lastScan = @json_decode(@file_get_contents($SF), true);
|
|
$regressions = [];
|
|
if ($lastScan && !empty($lastScan['results'])) {
|
|
foreach ($results as $path => $r) {
|
|
$prev = $lastScan['results'][$path] ?? null;
|
|
if ($prev && $prev['status'] === 'ok' && $r['status'] !== 'ok') {
|
|
$regressions[] = "REGRESSION: $path was OK, now {$r['status']} (HTTP {$r['code']})";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Save
|
|
$output = [
|
|
'timestamp' => date('Y-m-d H:i:s'),
|
|
'total' => $total,
|
|
'ok' => $ok_count,
|
|
'issues_count' => count($issues),
|
|
'regressions_count' => count($regressions),
|
|
'issues' => $issues,
|
|
'regressions' => $regressions,
|
|
'results' => $results,
|
|
'pages_scanned' => count($pages),
|
|
'apis_scanned' => count($apis),
|
|
];
|
|
file_put_contents($SF, json_encode($output, JSON_PRETTY_PRINT));
|
|
|
|
// Email on regressions
|
|
if (!empty($regressions)) {
|
|
$body = "WEVIA REGRESSION DETECTED - " . date('Y-m-d H:i') . "\n\n";
|
|
foreach ($regressions as $r) $body .= "! $r\n";
|
|
$body .= "\nTotal: $ok_count/$total OK | " . count($issues) . " issues\n";
|
|
foreach ($issues as $i) $body .= " [{$i['status']}] {$i['path']}: {$i['detail']}\n";
|
|
@mail('ymahboub@weval-consulting.com', '[WEVIA REGRESSION] ' . count($regressions) . ' regressions detected', $body, "From: wevia@weval-consulting.com");
|
|
}
|
|
|
|
lg("Scan: $ok_count/$total OK | " . count($issues) . " issues | " . count($regressions) . " regressions");
|
|
echo "$ts Scan: $ok_count/$total OK | " . count($issues) . " issues | " . count($regressions) . " regressions\n";
|