From 695ea7b969b4b53e560e359a573037ed099d5deb Mon Sep 17 00:00:00 2001 From: glaszig Date: Wed, 26 Feb 2020 17:51:04 +0000 Subject: [PATCH 1/3] show wifi qr code in "hotspot > security" section resolves #469. --- app/img/wifi-qr-code.php | 49 ++++++++++++++++++++++++++++++++++++++++ installers/common.sh | 2 +- templates/hostapd.php | 32 ++++++++++++++------------ 3 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 app/img/wifi-qr-code.php diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php new file mode 100644 index 00000000..f99bdcf9 --- /dev/null +++ b/app/img/wifi-qr-code.php @@ -0,0 +1,49 @@ +

-
- - +
+
+ + +
+
+ + +
+
+ + +
-
-
-
- - -
-
-
-
- - +
+
+ RaspAP Wifi QR code +
+
From ad1ca08de3ae4ca7ca0b0257a93f8dba47669271 Mon Sep 17 00:00:00 2001 From: glaszig Date: Thu, 27 Feb 2020 23:52:35 +0000 Subject: [PATCH 2/3] escape qrencode arguments in multibyte-safe way --- app/img/wifi-qr-code.php | 3 ++- includes/functions.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php index f99bdcf9..d0be9670 100644 --- a/app/img/wifi-qr-code.php +++ b/app/img/wifi-qr-code.php @@ -2,6 +2,7 @@ require_once '../../includes/config.php'; require_once '../../includes/defaults.php'; +require_once '../../includes/functions.php'; function qr_encode($str) { @@ -34,7 +35,7 @@ $ssid = qr_encode($ssid); $password = qr_encode($password); $data = "WIFI:S:$ssid;T:$type;P:$password;$hidden;"; -$command = "qrencode -t svg -m 0 -o - " . escapeshellarg($data); +$command = "qrencode -t svg -m 0 -o - " . mb_escapeshellarg($data); $svg = shell_exec($command); $config_mtime = filemtime(RASPI_HOSTAPD_CONFIG); diff --git a/includes/functions.php b/includes/functions.php index 81fed816..b75cf170 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -332,3 +332,17 @@ function cache($key, $callback) return $data; } } + +// insspired by +// http://markushedlund.com/dev/php-escapeshellarg-with-unicodeutf-8-support +function mb_escapeshellarg($arg) +{ + $isWindows = strtolower(substr(PHP_OS, 0, 3)) === 'win'; + if ($isWindows) { + $escaped_arg = str_replace(array('"', '%'), '', $arg); + } else { + $escaped_arg = str_replace("'", "'\\''", $arg); + } + return "\"$escaped_arg\""; +} + From 806ce229709c0ce923a3f31c9bd387292a5c4e27 Mon Sep 17 00:00:00 2001 From: glaszig Date: Thu, 27 Feb 2020 23:53:48 +0000 Subject: [PATCH 3/3] add etag header to wifi qr code to improve browser caching behavior --- app/img/wifi-qr-code.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php index d0be9670..92e9dce3 100644 --- a/app/img/wifi-qr-code.php +++ b/app/img/wifi-qr-code.php @@ -40,11 +40,13 @@ $svg = shell_exec($command); $config_mtime = filemtime(RASPI_HOSTAPD_CONFIG); $last_modified = gmdate('D, d M Y H:i:s ', $config_mtime) . 'GMT'; +$etag = hash('sha256', $data); $content_length = strlen($svg); header("Content-Type: image/svg+xml"); header("Content-Length: $content_length"); header("Last-Modified: $last_modified"); +header("ETag: \"$etag\""); header("X-QR-Code-Content: $data"); echo shell_exec($command);