136 lines
7.1 KiB
PHP
Executable File
136 lines
7.1 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
$action = $_GET['action'] ?? 'full_check';
|
|
$db = new PDO('pgsql:host=localhost;dbname=adx_system', 'admin', 'admin123');
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$db->exec("SET search_path TO admin,public");
|
|
|
|
switch($action) {
|
|
|
|
case 'full_check':
|
|
case 'status':
|
|
$start = microtime(true);
|
|
$results = ['timestamp'=>date('Y-m-d H:i:s'),'checks'=>[],'summary'=>['ok'=>0,'warn'=>0,'critical'=>0]];
|
|
|
|
// 1. Screen audit
|
|
$html_dir = '/opt/wevads-arsenal/public/';
|
|
$total_screens = count(glob($html_dir.'*.html'));
|
|
$screens_with_fetch = 0; $screens_raw_php = 0; $screens_tiny = 0;
|
|
foreach(glob($html_dir.'*.html') as $f) {
|
|
$c = file_get_contents($f); $sz = filesize($f);
|
|
if(preg_match('/<script[^>]*>.*?fetch\(/s', $c)) $screens_with_fetch++;
|
|
$body = '';
|
|
if(preg_match('/<body[^>]*>(.*)<\/body>/s', $c, $m)) {
|
|
$body = preg_replace('/<script[^>]*>.*?<\/script>/s', '', $m[1]);
|
|
if(strpos($body, '<?php') !== false) $screens_raw_php++;
|
|
}
|
|
if($sz < 1000) $screens_tiny++;
|
|
}
|
|
$screen_health = ($screens_raw_php == 0 && $screens_tiny < 3) ? 'ok' : ($screens_raw_php > 0 ? 'critical' : 'warn');
|
|
$results['checks']['screens'] = [
|
|
'status'=>$screen_health, 'total'=>$total_screens, 'api_connected'=>$screens_with_fetch,
|
|
'disconnected'=>$total_screens - $screens_with_fetch, 'raw_php'=>$screens_raw_php, 'tiny'=>$screens_tiny
|
|
];
|
|
$results['summary'][$screen_health]++;
|
|
|
|
// 2. API audit
|
|
$total_apis = count(glob($html_dir.'api/*.php'));
|
|
$api_ok = 0; $api_err = 0;
|
|
$critical_apis = ['hamid-chef.php','provider-router.php','ia-provider-factory.php','send-factory.php',
|
|
'brain-combo.php','offer-engine.php','account-creator.php','ads-platform.php','youtube-channels.php',
|
|
'healing.php','warmup.php','semi-auto-send.php','arsenal-health.php'];
|
|
$api_details = [];
|
|
foreach($critical_apis as $api) {
|
|
$url = "http://127.0.0.1:5890/api/{$api}?action=status";
|
|
$ctx = stream_context_create(['http'=>['timeout'=>3]]);
|
|
$resp = @file_get_contents($url, false, $ctx);
|
|
$valid = ($resp && strlen($resp) > 5 && $resp[0] === '{' && strpos($resp, 'Fatal error') === false && strpos($resp, 'Parse error') === false);
|
|
$api_details[] = ['api'=>$api, 'status'=>$valid ? 'ok' : 'error'];
|
|
if($valid) $api_ok++; else $api_err++;
|
|
}
|
|
$api_health = ($api_err == 0) ? 'ok' : (($api_err > 3) ? 'critical' : 'warn');
|
|
$results['checks']['apis'] = ['status'=>$api_health,'total'=>$total_apis,'critical_ok'=>$api_ok,'critical_err'=>$api_err,'details'=>$api_details];
|
|
$results['summary'][$api_health]++;
|
|
|
|
// 3. Database
|
|
try {
|
|
$tables = $db->query("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='admin'")->fetchColumn();
|
|
$contacts = $db->query("SELECT COUNT(*) FROM send_contacts")->fetchColumn();
|
|
$offers = $db->query("SELECT COUNT(*) FROM affiliate.offers")->fetchColumn();
|
|
$personas = $db->query("SELECT COUNT(*) FROM personas")->fetchColumn();
|
|
$ia = $db->query("SELECT COUNT(*) FROM ia_provider_accounts")->fetchColumn();
|
|
$warmup = $db->query("SELECT COUNT(*) FROM warmup_accounts")->fetchColumn();
|
|
$o365 = $db->query("SELECT COUNT(*) FROM o365_accounts")->fetchColumn();
|
|
$brain = $db->query("SELECT COUNT(*) FROM brain_winners")->fetchColumn();
|
|
$ads = $db->query("SELECT COUNT(*) FROM ads_accounts")->fetchColumn();
|
|
$camp = $db->query("SELECT COUNT(*) FROM campaigns")->fetchColumn();
|
|
$yt = $db->query("SELECT COUNT(*) FROM youtube_channels")->fetchColumn();
|
|
$dbsz = $db->query("SELECT pg_size_pretty(pg_database_size('adx_system'))")->fetchColumn();
|
|
$results['checks']['database'] = [
|
|
'status'=>'ok','tables'=>(int)$tables,'db_size'=>$dbsz,
|
|
'data'=>['contacts'=>(int)$contacts,'offers'=>(int)$offers,'personas'=>(int)$personas,
|
|
'ia_accounts'=>(int)$ia,'warmup'=>(int)$warmup,'o365'=>(int)$o365,
|
|
'brain_winners'=>(int)$brain,'ads_accounts'=>(int)$ads,'campaigns'=>(int)$camp,'youtube'=>(int)$yt]
|
|
];
|
|
$results['summary']['ok']++;
|
|
} catch(Exception $e) {
|
|
$results['checks']['database'] = ['status'=>'critical','error'=>$e->getMessage()];
|
|
$results['summary']['critical']++;
|
|
}
|
|
|
|
// 4. Infrastructure
|
|
$ovh_up = @fsockopen('151.80.235.110', 80, $en, $es, 2) ? true : false;
|
|
$disk = trim(shell_exec("df -h / | tail -1 | awk '{print $5}'"));
|
|
$load = trim(shell_exec("cat /proc/loadavg | cut -d' ' -f1-3"));
|
|
$mem = trim(shell_exec("free -m | awk 'NR==2{printf \"%d/%dMB (%.0f%%)\", $3,$2,$3*100/$2}'"));
|
|
$results['checks']['infrastructure'] = [
|
|
'status'=>$ovh_up ? 'ok' : 'warn', 'hetzner'=>'online', 'ovh_tracking'=>$ovh_up ? 'online' : 'offline',
|
|
'disk_usage'=>$disk, 'load'=>$load, 'memory'=>$mem
|
|
];
|
|
$results['summary'][$ovh_up ? 'ok' : 'warn']++;
|
|
|
|
// 5. Vault
|
|
$gold = count(glob('/opt/wevads/vault/*.gold'));
|
|
$results['checks']['vault'] = ['status'=>($gold > 1000) ? 'ok' : 'warn','gold_files'=>$gold];
|
|
$results['summary'][($gold > 1000) ? 'ok' : 'warn']++;
|
|
|
|
// 6. Ads
|
|
$ctx2 = stream_context_create(['http'=>['timeout'=>3]]);
|
|
$ads_r = @file_get_contents("http://127.0.0.1:5890/api/ads-platform.php?action=gare_flux", false, $ctx2);
|
|
$ads_ok = ($ads_r && strpos($ads_r, '"flux"') !== false);
|
|
$results['checks']['ads'] = ['status'=>$ads_ok ? 'ok' : 'warn', 'flux_api'=>$ads_ok];
|
|
$results['summary'][$ads_ok ? 'ok' : 'warn']++;
|
|
|
|
$elapsed = round((microtime(true) - $start) * 1000);
|
|
$results['elapsed_ms'] = $elapsed;
|
|
$results['overall'] = ($results['summary']['critical'] > 0) ? 'CRITICAL' : (($results['summary']['warn'] > 0) ? 'WARNING' : 'HEALTHY');
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
|
break;
|
|
|
|
case 'screens':
|
|
$dir = '/opt/wevads-arsenal/public/';
|
|
$out = [];
|
|
foreach(glob($dir.'*.html') as $f) {
|
|
$c = file_get_contents($f); $sz = filesize($f); $bn = basename($f);
|
|
$has_fetch = (bool)preg_match('/<script[^>]*>.*?fetch\(/s', $c);
|
|
$has_theme = (strpos($c,'#0a0e1a')!==false || strpos($c,'#0f172a')!==false || strpos($c,'linear-gradient')!==false);
|
|
$body = '';
|
|
if(preg_match('/<body[^>]*>(.*)<\/body>/s', $c, $m)) {
|
|
$body = preg_replace('/<script[^>]*>.*?<\/script>/s', '', $m[1]);
|
|
}
|
|
$has_php = (strpos($body,'<?php') !== false);
|
|
$alerts = preg_match_all('/onclick="alert\(/', $c);
|
|
$status = 'ok';
|
|
if($has_php) $status = 'critical';
|
|
elseif($sz < 2000) $status = 'warn';
|
|
elseif(!$has_fetch && $sz > 5000) $status = 'disconnected';
|
|
$out[] = ['name'=>$bn,'size'=>$sz,'api'=>$has_fetch,'theme'=>$has_theme,'php'=>$has_php,'alerts'=>$alerts,'status'=>$status];
|
|
}
|
|
echo json_encode(['status'=>'success','total'=>count($out),'screens'=>$out]);
|
|
break;
|
|
|
|
default:
|
|
echo json_encode(['status'=>'success','service'=>'Sentinel V5','actions'=>['full_check','status','screens']]);
|
|
}
|