From 433434f4b794b2503c7917cfb6bcff8958fcd411 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 18 Aug 2021 20:37:45 +0200 Subject: [PATCH 1/7] Correct non-ASCII SSID read from wpa_supplicant --- includes/wifi_functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index b7b543df..e29882bc 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -18,6 +18,7 @@ function knownWifiStations(&$networks) switch (strtolower($lineArr[0])) { case 'ssid': $ssid = trim($lineArr[1], '"'); + $ssid = str_replace('P"','',$ssid); $network['ssid'] = $ssid; break; case 'psk': From 5630258d9a0074c8e1faf282092f0cef5918e662 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 18 Aug 2021 21:04:30 +0200 Subject: [PATCH 2/7] Fix SSID name of wifi client --- includes/get_clients.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/get_clients.php b/includes/get_clients.php index 279fbef8..c05ef61b 100644 --- a/includes/get_clients.php +++ b/includes/get_clients.php @@ -70,7 +70,7 @@ function getClients($simple=true) $cl["device"][$i]["isAP"] = !empty($retiw); unset($retiw); exec("iw dev $dev link 2> /dev/null", $retiw); - if (!$simple && !empty($ssid=preg_only_match("/.*SSID: ([\w ]*).*/", $retiw)) ) { + if (!$simple && !empty($ssid=preg_only_match("/.*SSID:\s*([^\"]*).*/", $retiw)) ) { $cl["device"][$i]["connected"] = "y"; $cl["device"][$i]["ssid"] = $ssid; $cl["device"][$i]["ap-mac"] = preg_only_match("/^Connected to ([0-9a-f\:]*).*$/", $retiw); 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 3/7] 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 { From 077a9cd675a3dd949a6da34b49e59d012c4dab4b Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 18 Aug 2021 21:57:30 +0200 Subject: [PATCH 4/7] Convert non ASCII ssid for display to utf8 Convert hex bytes to binary. Assumes utf8 encoding --- includes/wifi_functions.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index e29882bc..b080f10f 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -181,3 +181,12 @@ function reinitializeWPA($force) return $result; } +/* + * Replace escaped bytes (hex) by binary - assume UTF8 encoding + * + * @param string $ssid + */ +function ssid2utf8($ssid) { + return evalHexSequence($ssid); +} + From 3aa564cdec0318d2f1f275fad8f9db491af923aa Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Tue, 31 Aug 2021 16:18:00 +0200 Subject: [PATCH 5/7] only lower case hex sequences in non-ASCII SSID --- includes/functions.php | 4 ++++ includes/wifi_functions.php | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 8ccd2430..b4774c2f 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -765,6 +765,10 @@ function evalHexSequence($string) return preg_replace_callback('/\\\x(..)/', $evaluator, $string); } +function hexSequence2lower($string) { + return preg_replace_callback('/\\\\x([0-9A-F]{2})/', function($b){ return '\x'.strtolower($b[1]); }, $string); +} + /* File upload callback object * */ diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index b080f10f..0ff1175d 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -73,7 +73,6 @@ function nearbyWifiStations(&$networks, $cached = true) $arrNetwork = preg_split("/[\t]+/", $network); // split result into array $ssid = trim($arrNetwork[4]); - $ssid = evalHexSequence($ssid); // exclude raspap ssid if (empty($ssid) || $ssid == $ap_ssid) { @@ -117,7 +116,7 @@ function connectedWifiStations(&$networks) exec('iwconfig ' .$_SESSION['wifi_client_interface'], $iwconfig_return); foreach ($iwconfig_return as $line) { if (preg_match('/ESSID:\"([^"]+)\"/i', $line, $iwconfig_ssid)) { - $networks[$iwconfig_ssid[1]]['connected'] = true; + $networks[hexSequence2lower($iwconfig_ssid[1])]['connected'] = true; } } } From 7344c323eedde2fc2a82e6d024e4287302cb95af Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 18 Aug 2021 22:10:33 +0200 Subject: [PATCH 6/7] Fix display of non-ASCII SSID --- ajax/networking/wifi_stations.php | 1 + includes/get_clients.php | 2 ++ templates/dashboard.php | 2 +- templates/wifi_stations/network.php | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ajax/networking/wifi_stations.php b/ajax/networking/wifi_stations.php index aca5bc89..ecc9c098 100644 --- a/ajax/networking/wifi_stations.php +++ b/ajax/networking/wifi_stations.php @@ -14,6 +14,7 @@ knownWifiStations($networks); nearbyWifiStations($networks, !isset($_REQUEST["refresh"])); connectedWifiStations($networks); sortNetworksByRSSI($networks); +foreach ($networks as $ssid => $network) $networks[$ssid]["ssidutf8"] = ssid2utf8( $ssid ); $connected = array_filter($networks, function($n) { return $n['connected']; } ); $known = array_filter($networks, function($n) { return !$n['connected'] && $n['configured']; } ); diff --git a/includes/get_clients.php b/includes/get_clients.php index c05ef61b..c167a538 100644 --- a/includes/get_clients.php +++ b/includes/get_clients.php @@ -1,6 +1,7 @@
-
+
diff --git a/templates/wifi_stations/network.php b/templates/wifi_stations/network.php index e0a9684c..4d20fb2f 100644 --- a/templates/wifi_stations/network.php +++ b/templates/wifi_stations/network.php @@ -4,7 +4,7 @@ -
+
From 45bd02ecb7d6341b77175421e837ae5949fb7302 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Wed, 8 Sep 2021 14:28:43 +0200 Subject: [PATCH 7/7] Improve detection of escaped hex bytes in ssid name --- includes/configure_client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/configure_client.php b/includes/configure_client.php index ddaa4205..19269025 100755 --- a/includes/configure_client.php +++ b/includes/configure_client.php @@ -69,7 +69,7 @@ function DisplayWPAConfig() } fwrite($wpa_file, $line.PHP_EOL); } else { - if ( strpos($ssid, "\x") !== false && strpos($line, "ssid=\"") !== false ) { + if ( preg_match('/\\\\x[0-9A-Fa-f]{2}/',$ssid) && strpos($line, "ssid=\"") !== false ) { fwrite($wpa_file, "\tssid=P\"".$ssid."\"".PHP_EOL); } else { fwrite($wpa_file, $line.PHP_EOL);