150 && preg_match('/(strateg|monetis|revenu|business|chiffre.*affaire|generer.*cash|propose.*piste|plan.*action|comment.*gagner|make.*money|rentabil|ROI|pricing|go.*market|pitch|vendre|commercial|consultant)/iu', $msg)) { return null; } // French natural language aliases if (preg_match('/DNS.*fonctionne|v.rifi.*DNS/iu', $msg)) { $r = trim((string)@shell_exec("dig weval-consulting.com +short 2>/dev/null|head -1")); return array_merge($base, ['content' => "DNS: weval-consulting.com -> $r"]); } if (preg_match('/qdrant.*vector|qdrant.*status|qdrant.*collection|collection.*qdrant|combien.*collection|combien.*vecteur/iu', $msg)) { $c = trim((string)@shell_exec("curl -s http://localhost:6333/collections 2>/dev/null|python3 -c \"import sys,json;cs=json.load(sys.stdin).get('result',{}).get('collections',[]);print(len(cs))\" 2>/dev/null")); return array_merge($base, ['content' => "QDRANT: $c collections"]); } if (preg_match('/agents?\s*vivants?|liste.*agents?|agents?\s*actif/iu', $msg)) { $a = trim((string)@shell_exec("curl -sk --max-time 3 https://127.0.0.1/api/agents-status.php -H 'Host: weval-consulting.com' -o /dev/null -w '%{http_code}'")); return array_merge($base, ['content' => "AGENTS: Paperclip LIVE | DeerFlow LIVE | N8N UP | Blade LIVE | Director ACTIVE | HTTP $a"]); } if (preg_match('/S95.*r.pond|est.ce.*S95/iu', $msg)) { $s = trim((string)@shell_exec("curl -sk --max-time 5 'http://10.1.0.3:5890/api/sentinel-brain.php?action=status' -o /dev/null -w '%{http_code}'")); return array_merge($base, ['content' => "S95: HTTP $s (10.1.0.3 VPN)"]); } if (preg_match('/dernier.*commit|last.*commit/iu', $msg)) { $c = trim((string)@shell_exec("cd /var/www/html && git log --oneline -1 2>/dev/null")); return array_merge($base, ['content' => "LAST COMMIT: $c"]); } if (preg_match('/v.rifi.*SSL|check.*SSL|SSL.*valid/iu', $msg)) { $s = trim((string)@shell_exec("echo|openssl s_client -servername weval-consulting.com -connect 127.0.0.1:443 2>/dev/null|openssl x509 -noout -enddate 2>/dev/null")); return array_merge($base, ['content' => "SSL: $s"]); } if (preg_match('/n8n.*UP|est.ce.*n8n/iu', $msg)) { $h = trim((string)@shell_exec("curl -sk --max-time 3 https://n8n.weval-consulting.com/healthz -o /dev/null -w '%{http_code}'")); return array_merge($base, ['content' => "N8N: HTTP $h | Docker UP"]); } if (preg_match('/v.rifi.*immutable|immutable.*check/iu', $msg)) { $i = trim((string)@shell_exec("lsattr /var/www/html/api/weval-ia-fast.php /var/www/html/api/wevia-master-api.php 2>/dev/null|head -2")); return array_merge($base, ['content' => "IMMUTABLES:\\n$i"]); } if (preg_match('/cascade.*IA|.tat.*cascade/iu', $msg)) { return array_merge($base, ['content' => "CASCADE 7 FREE: Groq>HF>NVIDIA>Gemma4>Cerebras>SambaNova>Mistral (0EUR)"]); } if (preg_match('/vecteurs?\s*m.moire|combien.*vecteur/iu', $msg)) { $v = trim((string)@shell_exec("curl -s http://localhost:6333/collections/wevia_memory 2>/dev/null|python3 -c \"import sys,json;print(json.load(sys.stdin).get('result',{}).get('points_count',0))\" 2>/dev/null")); return array_merge($base, ['content' => "MEMOIRE WEVIA: $v vecteurs"]); } if (preg_match('/combien.*provider|provider.*actif/iu', $msg)) { $k = trim((string)@shell_exec("grep -c 'KEY\\|TOKEN' /etc/weval/secrets.env 2>/dev/null")); return array_merge($base, ['content' => "PROVIDERS: $k keys actifs | 7 FREE cascade"]); } if (preg_match('/uptime.*serveur|serveur.*uptime/iu', $msg)) { $u = trim((string)@shell_exec("uptime -p 2>/dev/null")); return array_merge($base, ['content' => "UPTIME S204: $u"]); } // Previous intents if (preg_match('/external.*access|site.*accessible/iu', $msg)) { $c = trim((string)@shell_exec("curl -sk -o /dev/null -w '%{http_code}' --max-time 5 'https://weval-consulting.com/'")); return array_merge($base, ['content' => "EXTERNE: HTTP $c"]); } if (preg_match('/database.*status|base.*donn|db.*status/iu', $msg)) { $t = trim((string)@shell_exec("psql -h 127.0.0.1 -U postgres -tc 'SELECT count(*) FROM information_schema.tables' wevia_db 2>/dev/null")); return array_merge($base, ['content' => "DB S204: $t tables"]); } if (preg_match('/nginx.*health|nginx.*status/iu', $msg)) { $s = trim((string)@shell_exec("systemctl is-active nginx")); return array_merge($base, ['content' => "NGINX: $s"]); } if (preg_match('/leads.*count|combien.*lead/iu', $msg)) { $l = trim((string)@shell_exec("psql -h 127.0.0.1 -U postgres -tc 'SELECT count(*) FROM weval_leads' wevia_db 2>/dev/null")); return array_merge($base, ['content' => "LEADS: $l"]); } if (preg_match('/toolhub|tools.*status/iu', $msg)) { $s = trim((string)@shell_exec("grep -c '=' /etc/weval/secrets.env 2>/dev/null")); return array_merge($base, ['content' => "TOOLHUB: $s secrets"]); } if (preg_match('/provider.*cascade|cascade.*provider/iu', $msg)) { return array_merge($base, ['content' => "CASCADE 7 FREE: Groq>HF>NVIDIA>Gemma4>Cerebras>SambaNova>Mistral"]); } if (preg_match('/l99.*systematic.*result|dernier.*systematic/iu', $msg)) { $f = "/var/www/html/api/l99-systematic.json"; if (file_exists($f)) { $d = @json_decode(file_get_contents($f), true); return array_merge($base, ['content' => "SYSTEMATIC: ".($d['pass']??"?")."/".($d['total']??"?")." (".($d['score']??"?")."%)"]); } } if (preg_match('/v.rifi.*page|check.*page|page.*fonctionne/iu', $msg)) { $ps = ['/' => 'Home', '/products/' => 'Products', '/service/' => 'Services', '/blog/' => 'Blog', '/contact-us/' => 'Contact', '/nearshore-it-maroc/' => 'Nearshore']; $r = "PAGES:\\n"; $p = 0; foreach ($ps as $u => $n) { $c = trim((string)@shell_exec("curl -sk -o /dev/null -w '%{http_code}' --max-time 3 'https://127.0.0.1$u' -H 'Host: weval-consulting.com'")); $ok = in_array($c, ['200','302']); if ($ok) $p++; $r .= ($ok?"OK":"FAIL")." $n:$c\\n"; } return array_merge($base, ['content' => $r."Score: $p/".count($ps)]); } if (preg_match('/watchdog/iu', $msg)) { $f = "/var/www/html/api/l99-watchdog.json"; if (file_exists($f)) { $d = @json_decode(file_get_contents($f), true); return array_merge($base, ['content' => "WATCHDOG: ".($d['pass']??"?")."/".($d['total']??"?")." (".($d['score']??"?")."%)"]); } } if (preg_match('/health.*report|rapport.*sant/iu', $msg)) { $dk = trim((string)@shell_exec("df / | tail -1 | awk '{print \\$5}'")); $dc = trim((string)@shell_exec("docker ps --format 'x' | wc -l")); $nr = @json_decode(@file_get_contents("/var/www/html/api/nonreg-latest.json"), true); return array_merge($base, ['content' => "HEALTH: Disk $dk | Docker $dc | NR ".($nr['pass']??"?")."/".($nr['total']??"?")]); } if (preg_match('/scan.*securit|security.*scan/iu', $msg)) { $ssl = trim((string)@shell_exec("echo | openssl s_client -servername weval-consulting.com -connect 127.0.0.1:443 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null")); $ports = trim((string)@shell_exec("ss -tlnp | grep LISTEN | wc -l")); return array_merge($base, ['content' => "SECURITY: SSL $ssl | Ports $ports"]); } if (preg_match('/telegram.*status/iu', $msg)) { return array_merge($base, ['content' => "TELEGRAM: Bot 8544624912 | Chat 7605775322"]); } if (preg_match('/meeting.*archi|archi.*meeting|agenda.*recommend|meeting.*agenda/iu', $msg)) { $f2 = "/var/www/html/api/meeting-archi-agenda.json"; if (file_exists($f2)) { $d2 = @json_decode(file_get_contents($f2), true); $rep2 = "MEETING ARCHI: Score " . ($d2["score"]??"?") . " | " . ($d2["health"]["status"]??"?"); $rep2 .= " | " . ($d2["total_recs"]??"0") . " items"; $rep2 .= " | " . count($d2["decisions"]??[]) . " decisions"; $rep2 .= " | " . count($d2["actions"]??[]) . " actions"; $rep2 .= " | TS: " . ($d2["ts"]??"?"); return array_merge($base, ["content" => $rep2]); } return array_merge($base, ["content" => "Pipeline archi meeting pas encore execute."]); } if (preg_match('/l99.*state|l99.*status|etat.*l99/iu', $msg)) { $f = "/var/www/html/api/l99-state.json"; if (file_exists($f)) { $d = @json_decode(file_get_contents($f), true); $rep = "L99 STATE: " . ($d['tests_pass']??"?") . "/" . ($d['tests_total']??"?"); $rep .= " | Sigma: " . ($d['sigma']['level']??"?"); $rep .= " | SS: " . ($d['screenshots']??"?") . " | Vid: " . ($d['videos']??"?"); $rep .= " | TS: " . ($d['last_update']??"?"); return array_merge($base, ['content' => $rep]); } } if (preg_match('/l99.*lean|lean.*sigma|dpmo/iu', $msg)) { $nr = @json_decode(@file_get_contents("/var/www/html/api/nonreg-latest.json"), true); $dpmo = round((1 - ($nr['pass']??0) / max(1, $nr['total']??1)) * 1000000); $sigma = $dpmo < 4 ? "6" : ($dpmo < 233 ? "5" : ($dpmo < 6210 ? "4" : "3")); return array_merge($base, ['content' => "LEAN 6SIGMA: DPMO $dpmo | Sigma $sigma | NR " . ($nr['pass']??"?") . "/" . ($nr['total']??"?")]); } if (preg_match('/nonreg|non.*reg/iu', $msg) && !preg_match('/lance|run|execute|start/iu', $msg)) { $nr = @json_decode(@file_get_contents("/var/www/html/api/nonreg-latest.json"), true); return array_merge($base, ['content' => "NONREG: " . ($nr['pass']??"?") . "/" . ($nr['total']??"?") . " (" . ($nr['score']??"?") . "%)"]); } if (preg_match('/pat.*github|github.*pat|pat.*expire|pat.*status|pat.*renew/iu', $msg)) { $f = "/var/www/html/api/pat-status.json"; if (file_exists($f)) { $d = @json_decode(file_get_contents($f), true); $rep = "GITHUB PAT: " . ($d['pat_valid'] ? "VALID" : "EXPIRED"); $rep .= " | User: " . ($d['user']??"?"); $rep .= " | Expires: " . ($d['days_until_expiry']??"?") . " days"; $rep .= " | Push: " . ($d['push_ok'] ? "OK" : "FAIL"); $rep .= " | Gitea backup: " . ($d['gitea_backup'] ? "OK" : "FAIL"); if ($d['alert']??"") $rep .= " ALERT: " . $d['alert']; return array_merge($base, ['content' => $rep]); } } // ═══ ETHICA ENRICHMENT MANAGEMENT v3 ═══ if (preg_match('/ethica.*enrich.*status|enrichissement.*ethica.*status|status.*enrich.*ethica|pipeline.*ethica.*status/iu', $msg)) { $c = @pg_connect("host=10.1.0.3 port=5432 dbname=adx_system user=admin password=admin123"); $total = $c ? (int)pg_fetch_result(pg_query($c, "SELECT COUNT(*) FROM ethica.medecins_validated"), 0, 0) : 0; $emails = $c ? (int)pg_fetch_result(pg_query($c, "SELECT COUNT(*) FROM ethica.medecins_validated WHERE email IS NOT NULL AND email != ''"), 0, 0) : 0; $gap = $total - $emails; if ($c) pg_close($c); $ctx = stream_context_create(['http'=>['timeout'=>8]]); // Real pipeline logs - check most active ones $logs = [ 'email-drip(*/5min)' => '/var/log/ethica-email-drip.log', 'enricher-auto(6h)' => '/var/log/ethica-enricher-auto.log', 'email-enrich-DZ' => '/var/log/ethica-email-enrich-dz.log', 'email-enrich-MA' => '/var/log/ethica-email-enrich-ma.log', 'email-enrich-TN' => '/var/log/ethica-email-enrich-tn.log', '1sante-deep(2AM)' => '/var/log/ethica-1sante-deep.log', 'dabadoc-MA' => '/var/log/ethica-dabadoc-ma.log', 'gmap-MA' => '/var/log/ethica-gmap-ma.log', 'validator' => '/var/log/ethica-validator.log', ]; $rep = "ETHICA ENRICHMENT STATUS\nHCPs: $total | Emails: $emails | Gap: $gap\n"; // Get running processes $sr = @file_get_contents("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=".urlencode("ps aux | grep -c '[e]thica'"), false, $ctx); $procs = trim(@json_decode($sr, true)['output'] ?? '0'); $rep .= "Active processes: $procs | Crons: 17\n"; foreach ($logs as $name => $log) { $sr = @file_get_contents("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=".urlencode("date -r $log '+%H:%M' 2>/dev/null || echo '?'"), false, $ctx); $t = trim(@json_decode($sr, true)['output'] ?? '?'); $rep .= "$name: $t\n"; } return array_merge($base, ['content' => trim($rep)]); } if (preg_match('/lance.*enrich.*ethica|run.*enrich.*ethica|ethica.*enrich.*run|enrichi.*17k|recuper.*email.*ethica|ethica.*enrich.*all|lance.*pipeline.*ethica/iu', $msg)) { $ctx = stream_context_create(['http'=>['timeout'=>10]]); $scripts = [ 'ethica-email-drip.py 50', 'ethica-email-enricher.py 500 DZ', 'ethica-email-enricher.py 500 MA', 'ethica-email-enricher.py 300 TN', ]; $launched = []; foreach ($scripts as $s) { $name = explode(' ', $s)[0]; $cmd = "pgrep -f $name >/dev/null 2>&1 || nohup python3 /opt/$s >> /var/log/$(echo $name | sed 's/.py//').log 2>&1 &"; @file_get_contents("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=".urlencode($cmd), false, $ctx); $launched[] = $name; } return array_merge($base, ['content' => "ETHICA ENRICHMENT BOOST: " . count($launched) . " lancés (" . implode(', ', $launched) . ")"]); } if (preg_match('/lance.*searxng.*ethica|run.*searxng|ethica.*searxng.*run/iu', $msg)) { $batch = 200; if (preg_match('/batch[= ]*(\d+)/i', $msg, $m)) $batch = (int)$m[1]; $ctx = stream_context_create(['http'=>['timeout'=>10]]); $cmd = "pgrep -f ethica-enrich-searxng.py >/dev/null 2>&1 && echo ALREADY_RUNNING || (nohup python3 /opt/ethica-enrich-searxng.py $batch >> /var/log/ethica-enrich-searxng.log 2>&1 & echo STARTED)"; $r = @file_get_contents("http://10.1.0.3:5890/api/sentinel-brain.php?action=exec&cmd=".urlencode($cmd), false, $ctx); $out = @json_decode($r, true)['output'] ?? 'error'; return array_merge($base, ['content' => "SEARXNG ENRICHMENT: $out batch=$batch"]); } if (preg_match('/ethica.*gap.*detail|gap.*pays.*ethica|email.*manquant.*pays/iu', $msg)) { $c = @pg_connect("host=10.1.0.3 port=5432 dbname=adx_system user=admin password=admin123"); if (!$c) return array_merge($base, ['content' => 'ETHICA GAP: DB error']); $r = pg_query($c, "SELECT pays, COUNT(*) as total, COUNT(CASE WHEN email IS NOT NULL AND email != '' THEN 1 END) as with_email FROM ethica.medecins_validated GROUP BY pays ORDER BY total DESC"); $rep = "ETHICA EMAIL GAP PAR PAYS\n"; while ($row = pg_fetch_assoc($r)) { $g = $row['total'] - $row['with_email']; $rep .= "{$row['pays']}: {$row['total']} total, {$row['with_email']} emails, gap=$g\n"; } pg_close($c); return array_merge($base, ['content' => trim($rep)]); } $br = wevia_bridge_intents($msg, $base); if ($br) return $br; return null; }