Files
html/api/wevia-pdns-prompt-intent.php
2026-04-17 18:50:02 +02:00

64 lines
3.7 KiB
PHP

<?php
// WEVIA intent sidecar - pdns_activate_prompt (V33 Opus wire 17avr)
// Cause racine V33: utilisateur tape "activate powerdns" sans "confirmed"
// → orchestrator ne détecte pas pdns_activate_gated → UX cassée
// Fix: intent guide qui répond AVANT activation, explique la procédure
function wevia_pdns_prompt_intent($msg) {
// Détecte intention activation sans le mot magique "confirmed"
$activation_words = preg_match('/activ.*powerdns|activ.*pdns|go.*live.*pdns|start.*pdns|enable.*pdns|finir.*pdns|finish.*pdns|phase.*1.*finish|cf-bypass.*phase.*1/i', $msg);
$has_confirmation = preg_match('/confirmed|valide|ok.*activ|yes.*activ|go.*confirmed/i', $msg);
if (!$activation_words || $has_confirmation) return null;
// Pre-checks état actuel
$bin_ok = trim(shell_exec('test -f /usr/sbin/pdns_server && echo YES || echo NO'));
$service_state = trim(shell_exec('systemctl is-enabled pdns 2>&1'));
$conf_new = trim(shell_exec('test -f /etc/powerdns/pdns.conf.new && echo YES || echo NO'));
$script_ready = trim(shell_exec('test -x /usr/local/sbin/wevads-pdns-activate.sh && echo YES || echo NO'));
$port_free = trim(shell_exec('ss -tulpn 2>/dev/null | grep -q "10.1.0.2:53 " && echo BUSY || echo FREE'));
// Zones bind check
$zones_exist = trim(shell_exec('ls /etc/powerdns/bind-zones/ 2>/dev/null | wc -l'));
$preflight_ok = ($bin_ok === 'YES' && $service_state === 'masked' && $conf_new === 'YES' && $script_ready === 'YES' && $port_free === 'FREE');
return [
'intent' => 'pdns_activate_prompt',
'type' => 'UX_GUIDE',
'preflight' => [
'binary_installed' => $bin_ok,
'service_masked' => ($service_state === 'masked') ? 'YES' : 'NO:'.$service_state,
'conf_staging_ready' => $conf_new,
'activation_script_exec' => $script_ready,
'port_10_1_0_2_53' => $port_free,
'bind_zones_count' => (int)$zones_exist,
'all_green' => $preflight_ok,
],
'blockers' => $preflight_ok ? [] : [
($bin_ok !== 'YES') ? 'pdns_server binary missing' : null,
($service_state !== 'masked') ? 'service not masked safely' : null,
($conf_new !== 'YES') ? 'pdns.conf.new staging missing' : null,
($script_ready !== 'YES') ? 'activation script missing' : null,
($port_free !== 'FREE') ? 'port 10.1.0.2:53 already bound' : null,
((int)$zones_exist === 0) ? 'no bind zones yet (dev.wevup.app not created)' : null,
],
'next_actions' => [
'option_safe' => "Tape dans chat: 'cf bypass status' pour revoir l'etat",
'option_create_zones' => "Tape dans chat: 'create pdns zone dev.wevup.app' pour creer une zone test d'abord",
'option_activate' => "Tape dans chat (MOT MAGIQUE): 'pdns go live confirmed' pour activer REELLEMENT — attention: bind 10.1.0.2:53, masked removed, pdns started",
],
'rollback_if_fail' => "Le script fait 6 pre-checks et rollback auto si fail. Le GOLD /var/backups/gold_cf_bypass_s204_20260417_180728 permet revert total.",
'message' => $preflight_ok
? "PRE-FLIGHT ALL GREEN. Pour activer REELLEMENT PowerDNS, tape le mot magique: 'pdns go live confirmed'. Sinon 'create pdns zone dev.wevup.app' d'abord."
: "PRE-FLIGHT BLOCKERS detected. Fix blockers avant activation. Voir blockers[]."
];
}
// If called as standalone endpoint
if (basename($_SERVER['SCRIPT_NAME']) === 'wevia-pdns-prompt-intent.php') {
header('Content-Type: application/json');
$msg = $_GET['msg'] ?? $_POST['msg'] ?? '';
echo json_encode(wevia_pdns_prompt_intent($msg), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}