From 45a50edc41c042c155cfc249cb376f4f3a62b2c4 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 8 May 2021 14:24:15 -0300 Subject: [PATCH] use special multibyte shell escaping to support unicode ssid names with qr code --- app/img/wifi-qr-code.php | 2 +- includes/functions.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php index 068e5f95..c2505a9c 100644 --- a/app/img/wifi-qr-code.php +++ b/app/img/wifi-qr-code.php @@ -42,7 +42,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 29f34136..4f79870a 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -518,6 +518,18 @@ function cache($key, $callback) } } +// 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) { + return '"' . str_replace(array('"', '%'), '', $arg) . '"'; + } else { + return "'" . str_replace("'", "'\\''", $arg) . "'"; + } +} + function dnsServers() { $data = json_decode(file_get_contents("./config/dns-servers.json"));