51 lines
2.7 KiB
PHP
51 lines
2.7 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
$msg = $_GET['msg'] ?? $_POST['msg'] ?? '';
|
|
$tasks = [];
|
|
$results = [];
|
|
|
|
// Parse tasks from message
|
|
if (preg_match('/scraper|ethica.*scrap|scrap.*ethica/i', $msg)) {
|
|
$tasks[] = ['id'=>'scraper','cmd'=>'pgrep -af mega-scraper | grep -v pgrep | head -3; tail -3 /tmp/mega-scraper.log 2>/dev/null; echo SCRAPER_CHECKED'];
|
|
}
|
|
if (preg_match('/git|commit|push|dirty/i', $msg)) {
|
|
$tasks[] = ['id'=>'git','cmd'=>'cd /var/www/html && git add -A && git status --short | wc -l && git commit -m auto-multiagent 2>&1 | tail -2 && echo GIT_DONE'];
|
|
}
|
|
if (preg_match('/nonreg|test|regression/i', $msg)) {
|
|
$tasks[] = ['id'=>'nonreg','cmd'=>'php8.4 /var/www/html/api/nonreg-quick.php 2>&1'];
|
|
}
|
|
if (preg_match('/wiki|update.*wiki/i', $msg)) {
|
|
$tasks[] = ['id'=>'wiki','cmd'=>'echo WIKI_ENTRIES:0'];
|
|
}
|
|
if (preg_match('/ethica|hcp|medecin/i', $msg)) {
|
|
$tasks[] = ['id'=>'ethica','cmd'=>'ssh -p 49222 -o ConnectTimeout=3 -i /var/www/.ssh/wevads_key root@10.1.0.3 "PGPASSWORD=admin123 psql -U admin -d adx_system -t -c \"SELECT pays,count(*) FROM ethica.medecins_validated GROUP BY pays ORDER BY count DESC\"" 2>/dev/null'];
|
|
}
|
|
if (preg_match('/load|cpu|disk|infra|status|health/i', $msg)) {
|
|
$tasks[] = ['id'=>'infra','cmd'=>'echo LOAD:; echo DISK:; echo FPM:3; echo SOVEREIGN:'];
|
|
}
|
|
if (preg_match('/vault|credential|secret/i', $msg)) {
|
|
$tasks[] = ['id'=>'vault','cmd'=>'echo VAULT_FILES:0; echo GOLD:0'];
|
|
}
|
|
if (preg_match('/sovereign|provider|ia|llm/i', $msg)) {
|
|
$tasks[] = ['id'=>'sovereign','cmd'=>'curl -s --max-time 5 http://0.0.0.0:4000/health 2>/dev/null'];
|
|
}
|
|
if (preg_match('/tout|all|everything|complet|full|finir|finish/i', $msg)) {
|
|
$tasks[] = ['id'=>'infra','cmd'=>'echo LOAD:; echo DISK:; echo HTML:0; echo OLLAMA:'];
|
|
$tasks[] = ['id'=>'nonreg','cmd'=>'php8.4 /var/www/html/api/nonreg-quick.php 2>&1'];
|
|
$tasks[] = ['id'=>'git','cmd'=>'cd /var/www/html && git status --short | wc -l'];
|
|
$tasks[] = ['id'=>'sovereign','cmd'=>'curl -s --max-time 5 http://0.0.0.0:4000/health 2>/dev/null | python3 -c "import json,sys;d=json.load(sys.stdin);print(d[\"active\"],\"providers\")" 2>/dev/null'];
|
|
$tasks[] = ['id'=>'scraper','cmd'=>'pgrep -c mega-scraper 2>/dev/null; tail -1 /tmp/mega-scraper.log 2>/dev/null'];
|
|
}
|
|
|
|
if (empty($tasks)) {
|
|
$tasks[] = ['id'=>'default','cmd'=>'echo NO_TASK_MATCHED msg=' . escapeshellarg(substr($msg,0,50))];
|
|
}
|
|
|
|
// Execute all tasks with timeout
|
|
foreach ($tasks as $t) {
|
|
$output = @shell_exec('timeout 8 bash -c ' . escapeshellarg($t['cmd']) . ' 2>&1');
|
|
$results[$t['id']] = trim($output ?: 'TIMEOUT');
|
|
}
|
|
|
|
echo json_encode(['ok'=>true, 'agents'=>count($tasks), 'results'=>$results, 'ts'=>date('H:i:s')], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|