v1.9.3: Fix wifi_connect (escaping shell + URL) + log dédié
Bugs corrigés: - launcher.php passait SSID/PASS au shell sans escapeshellarg(): un mot de passe avec $/&/;/espace cassait silencieusement la commande avant que nmcli ne soit appelé. Cause probable des retours clients "ça bloque au cliquer sur Se connecter". - wifi.html n'encodait pas SSID/PASS dans l'URL: caractères &/+/= corrompaient la requête. Observabilité: - Nouveau fichier logs/wifi_connect.log avec timestamps stricts - launcher.php log la requête entrante (IP, longueurs SSID/PASS) - connexion.sh: fonction log_wc(), snapshots NM avant/après, capture stdout+stderr nmcli, code retour explicite, fallback SSID dérivé du serial si deviceName indisponible. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1268,6 +1268,17 @@ if ($type == "wifi_connect") {
|
||||
$SSID=$_GET['SSID'];
|
||||
$PASS=$_GET['pass'];
|
||||
|
||||
// Dedicated WiFi connect log (separate from app.log for easier debugging)
|
||||
$wifi_log = '/var/www/nebuleair_pro_4g/logs/wifi_connect.log';
|
||||
$log_wc = function($msg) use ($wifi_log) {
|
||||
$ts = date('Y-m-d H:i:s');
|
||||
@file_put_contents($wifi_log, "[$ts] [launcher.php] $msg\n", FILE_APPEND);
|
||||
};
|
||||
$log_wc("=== wifi_connect request received ===");
|
||||
$log_wc("SSID='" . $SSID . "' (len=" . strlen($SSID) . ")");
|
||||
$log_wc("PASS=[HIDDEN] (len=" . strlen($PASS) . ")");
|
||||
$log_wc("client_ip=" . ($_SERVER['REMOTE_ADDR'] ?? '?'));
|
||||
|
||||
// Get device name and hostname for instructions
|
||||
try {
|
||||
$db = new PDO("sqlite:$database_path");
|
||||
@@ -1279,13 +1290,20 @@ if ($type == "wifi_connect") {
|
||||
$db = null;
|
||||
} catch (PDOException $e) {
|
||||
$deviceName = 'NebuleAir';
|
||||
$log_wc("WARN: PDO error reading deviceName: " . $e->getMessage());
|
||||
}
|
||||
$hostname = trim(shell_exec('hostname 2>/dev/null')) ?: 'aircarto';
|
||||
$log_wc("deviceName='$deviceName' hostname='$hostname'");
|
||||
|
||||
// Launch connection script in background
|
||||
// Launch connection script in background.
|
||||
// CRITICAL: escapeshellarg() each argument so SSIDs with spaces or passwords
|
||||
// with special characters ($, &, ;, etc.) are passed correctly to bash.
|
||||
$script_path = '/var/www/nebuleair_pro_4g/connexion.sh';
|
||||
$log_file = '/var/www/nebuleair_pro_4g/logs/app.log';
|
||||
shell_exec("$script_path $SSID $PASS >> $log_file 2>&1 &");
|
||||
$ssid_arg = escapeshellarg($SSID);
|
||||
$pass_arg = escapeshellarg($PASS);
|
||||
$cmd = "$script_path $ssid_arg $pass_arg >> $wifi_log 2>&1 &";
|
||||
$log_wc("Launching: $script_path <ssid> <pass> (background, output -> wifi_connect.log)");
|
||||
shell_exec($cmd);
|
||||
|
||||
// Return JSON response with instructions
|
||||
header('Content-Type: application/json');
|
||||
|
||||
Reference in New Issue
Block a user