Files
html/api/wedroid-infra-patterns.php
2026-04-12 22:57:03 +02:00

47 lines
2.4 KiB
PHP

<?php
/**
* WEDROID Infra Autonomous Patterns v1.0
* Include from wedroid-brain-api.php
*/
function matchInfraPattern($msg) {
$lower = strtolower($msg);
// PRIORITY 1: Auth test (session-based, runs locally on S204)
if (preg_match("/(test|verif|check).*(auth|login|session|page)/", $lower) || preg_match("/(auth|login).*(test|verif|check)/", $lower) || preg_match("/toutes.*pages/", $lower)) {
return ["special" => "auth_test_local"];
}
// PRIORITY 2: Email/contact check
if (preg_match("/(email|contact|message).*(test|verif|check|routing)/", $lower)) {
return ["special" => "email_check"];
}
// PRIORITY 3: Heal
if (preg_match("/(heal|repair|fix|restart|self.heal)/", $lower)) {
return ["special" => "heal"];
}
// PRIORITY 4: Git
if (preg_match("/(git|commit|push|deploy)/", $lower)) {
return ["special" => "git"];
}
// PRIORITY 5: Alert
if (preg_match("/(alert|telegram|notify|urgence)/", $lower)) {
return ["special" => "alert"];
}
// PRIORITY 6: Infrastructure commands
if (preg_match("/(disk|espace|stockage|df)/", $lower)) {
return ["cmd" => "df -h / | tail -1", "label" => "Disk Usage"];
}
if (preg_match("/(port|service|apache|nginx|postgres|systemctl)/", $lower)) {
return ["cmd" => "for s in apache2 postgresql; do echo \"$s: $(systemctl is-active $s)\"; done && echo \"Ports:\" && for p in 5821 5822 5823 5825 5880 5890; do echo \"$p: $(curl -s -o /dev/null -w %{http_code} --max-time 2 http://127.0.0.1:$p/)\"; done", "label" => "Services & Ports"];
}
if (preg_match("/(cron|schedule|tache)/", $lower)) {
return ["cmd" => "crontab -l 2>/dev/null | grep -v \"^#\" | wc -l", "label" => "Crons"];
}
if (preg_match("/(^log$|logs|erreur|error|journal)/", $lower)) {
return ["cmd" => "echo \"=== Apache ===\"; tail -3 /var/log/apache2/error.log 2>/dev/null; echo \"=== PHP ===\"; tail -3 /var/log/php*.log 2>/dev/null", "label" => "Recent Logs"];
}
if (preg_match("/(diagnostic|status|health|etat)/", $lower)) {
return ["cmd" => "echo \"Disk: $(df -h / | tail -1 | awk \"{print \$5}\")\"; echo \"Apache: $(systemctl is-active apache2)\"; echo \"PG: $(systemctl is-active postgresql)\"; echo \"Ports:\"; for p in 5821 5822 5823 5825 5880 5890; do echo \"$p: $(curl -s -o /dev/null -w %{http_code} --max-time 2 http://127.0.0.1:$p/)\"; done", "label" => "Full Diagnostic"];
}
return null;
}