From d478bf53628185c8ac9c0df4b1fd89b6474ccfd7 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 18 Aug 2021 20:24:36 +0200 Subject: [PATCH] Handle non-ASCII SSID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Non-ASCII SSID has to be stored in wpa_supplicant.conf identical to the string given by wpa_cli scan. This includes the escaped special chars (e.g. รถ = \xc3\xb9 ), with a prescript "P". To obtain a valid psk from wpa_passphrase, the UTF8 string is passed (ssid2utf8 replaces the \x bytes by their binary value) to the exec(). For this to work the shell locale has to be UTF8 (via putenv()). Otherwise the string is converted to the shell encoding. --- includes/configure_client.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index 540f0fef..ddaa4205 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -61,7 +61,7 @@ function DisplayWPAConfig() if (strlen($network['passphrase']) >=8 && strlen($network['passphrase']) <= 63) { unset($wpa_passphrase); unset($line); - exec('wpa_passphrase '.escapeshellarg($ssid). ' ' . escapeshellarg($network['passphrase']), $wpa_passphrase); + exec('wpa_passphrase '. ssid2utf8( escapeshellarg($ssid) ) . ' ' . escapeshellarg($network['passphrase']), $wpa_passphrase); foreach ($wpa_passphrase as $line) { if (preg_match('/^\s*}\s*$/', $line)) { if (array_key_exists('priority', $network)) { @@ -69,7 +69,11 @@ function DisplayWPAConfig() } fwrite($wpa_file, $line.PHP_EOL); } else { - fwrite($wpa_file, $line.PHP_EOL); + if ( strpos($ssid, "\x") !== false && strpos($line, "ssid=\"") !== false ) { + fwrite($wpa_file, "\tssid=P\"".$ssid."\"".PHP_EOL); + } else { + fwrite($wpa_file, $line.PHP_EOL); + } } } } else {