From d8626bd7902945e18012df97dcbeced97a814792 Mon Sep 17 00:00:00 2001 From: zbchristian <33725910+zbchristian@users.noreply.github.com> Date: Thu, 2 Sep 2021 10:58:34 +0200 Subject: [PATCH 01/10] Zbchristian fix wifi client connect #53 --- includes/wifi_functions.php | 17 +++++++++++++---- templates/wifi_stations.php | 9 ++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index b7b543df..fb7071f4 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -6,9 +6,11 @@ function knownWifiStations(&$networks) { // Find currently configured networks exec(' sudo cat ' . RASPI_WPA_SUPPLICANT_CONFIG, $known_return); + $index = 0; foreach ($known_return as $line) { if (preg_match('/network\s*=/', $line)) { - $network = array('visible' => false, 'configured' => true, 'connected' => false); + $network = array('visible' => false, 'configured' => true, 'connected' => false, 'index' => $index); + ++$index; } elseif (isset($network) && $network !== null) { if (preg_match('/^\s*}\s*$/', $line)) { $networks[$ssid] = $network; @@ -68,6 +70,12 @@ function nearbyWifiStations(&$networks, $cached = true) exec('cat '.RASPI_HOSTAPD_CONFIG.' | sed -rn "s/ssid=(.*)\s*$/\1/p" ', $ap_ssid); $ap_ssid = $ap_ssid[0]; + $index = 0; + if ( !empty($networks) ) { + $lastnet = end($networks); + if ( isset($lastnet['index']) ) $index = $lastnet['index'] + 1; + } + foreach (explode("\n", $scan_results) as $network) { $arrNetwork = preg_split("/[\t]+/", $network); // split result into array @@ -84,8 +92,6 @@ function nearbyWifiStations(&$networks, $cached = true) continue; } - $networks[$ssid]['ssid'] = $ssid; - // If network is saved if (array_key_exists($ssid, $networks)) { $networks[$ssid]['visible'] = true; @@ -93,13 +99,16 @@ function nearbyWifiStations(&$networks, $cached = true) // TODO What if the security has changed? } else { $networks[$ssid] = array( + 'ssid' => $ssid, 'configured' => false, 'protocol' => ConvertToSecurity($arrNetwork[3]), 'channel' => ConvertToChannel($arrNetwork[1]), 'passphrase' => '', 'visible' => true, - 'connected' => false + 'connected' => false, + 'index' => $index ); + ++$index; } // Save RSSI, if the current value is larger than the already stored diff --git a/templates/wifi_stations.php b/templates/wifi_stations.php index 6949a51a..1e3e0d2a 100755 --- a/templates/wifi_stations.php +++ b/templates/wifi_stations.php @@ -19,7 +19,8 @@

- + + @@ -29,7 +30,8 @@

- + + @@ -39,7 +41,8 @@

- + + From 74b6a15a75df36129c0ebf902dd6592ee0ddfc24 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 02/10] 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 fb7071f4..978fb50c 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -20,6 +20,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 5cbb785529b263e4d0e2a153cd67b4482fca207a 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 04/10] 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 634eb7276092612bb5a8841da9a37358b1aea6f8 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 05/10] 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 978fb50c..3f13738a 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -190,3 +190,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 db9f76eb5ce82b8cd1c8d729e6a7487f918043d1 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 06/10] only lower case hex sequences in non-ASCII SSID --- includes/functions.php | 27 +++++++++++++++++++++++++++ includes/wifi_functions.php | 3 +-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 0e8336b8..5a59bfad 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -648,3 +648,30 @@ 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 + * + */ +class validation +{ + public function check_name_length($object) + { + if (strlen($object->file['filename']) > 255) { + $object->set_error('File name is too long.'); + } + } +} + +/* Resolves public IP address + * + * @return string $public_ip + */ +function get_public_ip() +{ + exec('wget https://ipinfo.io/ip -qO -', $public_ip); + return $public_ip[0]; +} + diff --git a/includes/wifi_functions.php b/includes/wifi_functions.php index 3f13738a..dcc57ede 100755 --- a/includes/wifi_functions.php +++ b/includes/wifi_functions.php @@ -81,7 +81,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) { @@ -126,7 +125,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 c33cf5f81a86765021dead2f1902c439c9360e4f 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 07/10] Fix display of non-ASCII SSID --- ajax/networking/wifi_stations.php | 1 + templates/wifi_stations/network.php | 5 ++--- 2 files changed, 3 insertions(+), 3 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/templates/wifi_stations/network.php b/templates/wifi_stations/network.php index 1bdcb786..1199a5e5 100644 --- a/templates/wifi_stations/network.php +++ b/templates/wifi_stations/network.php @@ -3,9 +3,8 @@ -
- + } ?> +
From 4408940a3d3c27d1d637c36b9b93bdf37cb64c52 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 08/10] 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); From 37bc68c91a7a381827d8894c0f51e3b99d0fd31a Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 25 Nov 2021 08:05:38 +0000 Subject: [PATCH 09/10] Update default getColorOpt() --- includes/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index 5a59bfad..b50d1faa 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -615,7 +615,7 @@ function getThemeOpt() function getColorOpt() { if (!isset($_COOKIE['color'])) { - $color = "#d8224c"; + $color = "#2b8080"; } else { $color = $_COOKIE['color']; } From 6b777ff8c25343834ae34d129cb032ba7332a48b Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 25 Nov 2021 09:02:59 +0000 Subject: [PATCH 10/10] Update release version --- README.md | 2 +- includes/defaults.php | 2 +- index.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0cba7a87..b809448b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ![](https://i.imgur.com/xeKD93p.png) -[![Release 2.7.0](https://img.shields.io/badge/release-v2.7.0-green)](https://github.com/raspap/raspap-webgui/releases) [![Awesome](https://awesome.re/badge.svg)](https://github.com/thibmaek/awesome-raspberry-pi) [![Join Insiders](https://img.shields.io/static/v1?label=Join%20Insiders&message=%E2%9D%A4&logo=GitHub&color=ff69b4)](https://github.com/sponsors/RaspAP) ![https://travis-ci.com/github/raspap/raspap-webgui/](https://api.travis-ci.org/RaspAP/raspap-webgui.svg) [![Crowdin](https://badges.crowdin.net/raspap/localized.svg)](https://crowdin.com/project/raspap) [![Twitter URL](https://img.shields.io/twitter/url?label=%40RaspAP&logoColor=%23d8224c&url=https%3A%2F%2Ftwitter.com%2Frasp_ap)](https://twitter.com/rasp_ap) [![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/RaspAP?style=social)](https://www.reddit.com/r/RaspAP/) +[![Release 2.7.1](https://img.shields.io/badge/release-v2.7.1-green)](https://github.com/raspap/raspap-webgui/releases) [![Awesome](https://awesome.re/badge.svg)](https://github.com/thibmaek/awesome-raspberry-pi) [![Join Insiders](https://img.shields.io/static/v1?label=Join%20Insiders&message=%E2%9D%A4&logo=GitHub&color=ff69b4)](https://github.com/sponsors/RaspAP) ![https://travis-ci.com/github/raspap/raspap-webgui/](https://api.travis-ci.org/RaspAP/raspap-webgui.svg) [![Crowdin](https://badges.crowdin.net/raspap/localized.svg)](https://crowdin.com/project/raspap) [![Twitter URL](https://img.shields.io/twitter/url?label=%40RaspAP&logoColor=%23d8224c&url=https%3A%2F%2Ftwitter.com%2Frasp_ap)](https://twitter.com/rasp_ap) [![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/RaspAP?style=social)](https://www.reddit.com/r/RaspAP/) RaspAP is feature-rich wireless router software that _just works_ on many popular [Debian-based devices](#supported-operating-systems), including the Raspberry Pi. Our popular [Quick installer](#quick-installer) creates a known-good default configuration for all current Raspberry Pis with onboard wireless. A fully responsive, mobile-ready interface gives you control over the relevant services and networking options. Advanced DHCP settings, WireGuard and OpenVPN support, [SSL certificates](https://docs.raspap.com/ssl-quick/), security audits, [captive portal integration](https://docs.raspap.com/captive/), themes and [multilingual options](https://docs.raspap.com/translations/) are included. diff --git a/includes/defaults.php b/includes/defaults.php index cf57e803..431b7f4d 100755 --- a/includes/defaults.php +++ b/includes/defaults.php @@ -6,7 +6,7 @@ if (!defined('RASPI_CONFIG')) { $defaults = [ 'RASPI_BRAND_TEXT' => 'RaspAP', - 'RASPI_VERSION' => '2.7.0', + 'RASPI_VERSION' => '2.7.1', 'RASPI_CONFIG_NETWORK' => RASPI_CONFIG.'/networking/defaults.json', 'RASPI_ADMIN_DETAILS' => RASPI_CONFIG.'/raspap.auth', 'RASPI_WIFI_AP_INTERFACE' => 'wlan0', diff --git a/index.php b/index.php index f727ea0c..d8dc0285 100755 --- a/index.php +++ b/index.php @@ -14,7 +14,7 @@ * @author Lawrence Yau * @author Bill Zimmerman * @license GNU General Public License, version 3 (GPL-3.0) - * @version 2.7.0 + * @version 2.7.1 * @link https://github.com/raspap/raspap-webgui/ * @link https://raspap.com/ * @see http://sirlagz.net/2013/02/08/raspap-webgui/