114 lines
3.9 KiB
PHP
114 lines
3.9 KiB
PHP
<?php
|
|
// V45 KPI proxy for WEVIA Control Center
|
|
// Runs server-side, avoids browser mixed-content + 127.0.0.1 issues
|
|
header('Content-Type: application/json');
|
|
header('Cache-Control: no-store');
|
|
header('Access-Control-Allow-Origin: *');
|
|
|
|
$out = [
|
|
'ts' => date('c'),
|
|
'sovereign' => null,
|
|
'providers_up' => null,
|
|
'tools_registry' => null,
|
|
'l99' => null,
|
|
'orch_ready' => null,
|
|
'tracks95_status' => null,
|
|
'cf_bypass_mode' => null,
|
|
'watchdog_health' => null,
|
|
];
|
|
|
|
// 1) Sovereign health
|
|
$ch = curl_init('http://127.0.0.1:4000/health');
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 4]);
|
|
$body = curl_exec($ch);
|
|
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
curl_close($ch);
|
|
if ($code === 200 && $body) {
|
|
$j = @json_decode($body, true);
|
|
$out['sovereign'] = $j ?: ['raw' => substr($body, 0, 200)];
|
|
// providers: sovereign v3 returns active/total + providers array of strings
|
|
if (isset($j['active']) && isset($j['total'])) {
|
|
$out['providers_up'] = ['up' => $j['active'], 'total' => $j['total']];
|
|
} elseif (isset($j['providers']) && is_array($j['providers'])) {
|
|
$out['providers_up'] = ['up' => count($j['providers']), 'total' => count($j['providers'])];
|
|
} else {
|
|
$out['providers_up'] = ['up' => null, 'total' => null];
|
|
}
|
|
} else {
|
|
$out['sovereign'] = ['error' => 'HTTP ' . $code, 'reachable' => false];
|
|
}
|
|
|
|
// 2) Tools registry count
|
|
$reg = @file_get_contents('/var/www/html/api/wevia-tool-registry.json');
|
|
if ($reg) {
|
|
$j = @json_decode($reg, true);
|
|
$out['tools_registry'] = [
|
|
'count' => $j['count'] ?? (isset($j['tools']) ? count($j['tools']) : 0),
|
|
'version' => $j['version'] ?? null,
|
|
];
|
|
}
|
|
|
|
// 3) L99 latest
|
|
$l99 = @file_get_contents('/var/www/html/api/nonreg-latest.json');
|
|
if ($l99) $out['l99'] = @json_decode($l99, true);
|
|
|
|
// 4) Orchestrator readiness (file exists + size)
|
|
if (file_exists('/var/www/html/api/wevia-sse-orchestrator.php')) {
|
|
$st = stat('/var/www/html/api/wevia-sse-orchestrator.php');
|
|
$out['orch_ready'] = [
|
|
'size' => $st['size'],
|
|
'mtime' => date('c', $st['mtime']),
|
|
'readable' => is_readable('/var/www/html/api/wevia-sse-orchestrator.php'),
|
|
];
|
|
}
|
|
|
|
// 5) track.s95 status (via sidecar - only fetch summary)
|
|
$ch = curl_init('http://127.0.0.1:5890/api/wevia-track-s95-prompt-intent.php?type=status');
|
|
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 5]);
|
|
$body = curl_exec($ch);
|
|
curl_close($ch);
|
|
if ($body) {
|
|
$j = @json_decode($body, true);
|
|
$out['tracks95_status'] = $j['phase_2_status'] ?? null;
|
|
}
|
|
|
|
// 6) CF bypass mode (via Sentinel S95)
|
|
$ch = curl_init('https://wevads.weval-consulting.com/api/sentinel-brain.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => http_build_query(['action' => 'exec', 'cmd' => 'cat /opt/wevads/state/cf-bypass-mode.json 2>/dev/null']),
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 5,
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
]);
|
|
$body = curl_exec($ch);
|
|
curl_close($ch);
|
|
if ($body) {
|
|
$j = @json_decode($body, true);
|
|
if ($j && !empty($j['output'])) {
|
|
$inner = @json_decode($j['output'], true);
|
|
$out['cf_bypass_mode'] = $inner ?: ['raw' => $j['output']];
|
|
}
|
|
}
|
|
|
|
// 7) Watchdog health (similar)
|
|
$ch = curl_init('https://wevads.weval-consulting.com/api/sentinel-brain.php');
|
|
curl_setopt_array($ch, [
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => http_build_query(['action' => 'exec', 'cmd' => 'cat /opt/wevads/state/cf-bypass-health.json 2>/dev/null']),
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TIMEOUT => 5,
|
|
CURLOPT_SSL_VERIFYPEER => false,
|
|
]);
|
|
$body = curl_exec($ch);
|
|
curl_close($ch);
|
|
if ($body) {
|
|
$j = @json_decode($body, true);
|
|
if ($j && !empty($j['output']) && $j['output'] !== '') {
|
|
$inner = @json_decode($j['output'], true);
|
|
$out['watchdog_health'] = $inner ?: null;
|
|
}
|
|
}
|
|
|
|
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|