diff --git a/app/img/wg-qr-code.php b/app/img/wg-qr-code.php index 7a66e6fc..c487fbc1 100755 --- a/app/img/wg-qr-code.php +++ b/app/img/wg-qr-code.php @@ -13,6 +13,7 @@ if (!isset($_SERVER['HTTP_REFERER'])) { exec("sudo cat " .RASPI_WIREGUARD_PATH.'client.conf', $return); $peer_conf = implode(PHP_EOL,$return); $peer_conf.= PHP_EOL; +$peer_conf_sanitized = str_replace(["\r", "\n"], '', $peer_conf); $command = "qrencode -t svg -m 0 -o - " . mb_escapeshellarg($peer_conf); $svg = shell_exec($command); $etag = hash('sha256', $peer_conf); @@ -23,6 +24,6 @@ header("Content-Type: image/svg+xml"); header("Content-Length: $content_length"); header("Last-Modified: $last_modified"); header("ETag: \"$etag\""); -header("X-QR-Code-Content: $peer_conf"); +header("X-QR-Code-Content: $peer_conf_sanitized"); echo shell_exec($command); diff --git a/app/img/wifi-qr-code.php b/app/img/wifi-qr-code.php index acecfe85..19171094 100755 --- a/app/img/wifi-qr-code.php +++ b/app/img/wifi-qr-code.php @@ -12,12 +12,12 @@ if (!isset($_SERVER['HTTP_REFERER'])) { $hostapd = parse_ini_file(RASPI_HOSTAPD_CONFIG, false, INI_SCANNER_RAW); -// assume wpa encryption and get the passphrase +// assume WPA encryption and get the passphrase $type = "WPA"; $password = isset($hostapd['wpa_psk']) ? $hostapd['wpa_psk'] : $hostapd['wpa_passphrase']; -// use wep if configured -$wep_default_key = intval($hostapd['wep_default_key']); +// use WEP if configured +$wep_default_key = intval($hostapd['wep_default_key'] ?? 0); $wep_key = 'wep_key' . $wep_default_key; if (array_key_exists($wep_key, $hostapd)) { $type = "WEP"; @@ -30,7 +30,7 @@ if (empty($password)) { } $ssid = $hostapd['ssid']; -$hidden = intval($hostapd['ignore_broadcast_ssid']) != 0 ? "H:true" : ""; +$hidden = intval($hostapd['ignore_broadcast_ssid'] ?? 0) !== 0 ? "H:true" : ""; $ssid = qr_encode($ssid); $password = qr_encode($password); diff --git a/includes/dashboard.php b/includes/dashboard.php index f77c6e55..3e1b3e14 100755 --- a/includes/dashboard.php +++ b/includes/dashboard.php @@ -35,8 +35,7 @@ function DisplayDashboard(): void $ethernetClients = $dashboard->getEthernetClients(); $totalClients = $wirelessClients + $ethernetClients; $plugins = $pluginManager->getInstalledPlugins(); - $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); - $bridgedEnable = $arrHostapdConf['BridgedEnable']; + $bridgedEnable = getBridgedState(); // handle page actions if (!empty($_POST)) { diff --git a/includes/functions.php b/includes/functions.php index f41e1ecb..54b4939c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -713,7 +713,6 @@ function formatDateAgo($datetime, $full = false) function initializeApp() { $_SESSION["theme_url"] = getThemeOpt(); - $_SESSION["toggleState"] = getSidebarState(); $_SESSION["bridgedEnabled"] = getBridgedState(); $_SESSION["providerID"] = getProviderID(); } @@ -739,22 +738,17 @@ function getColorOpt() return $color; } -function getSidebarState() -{ - if(isset($_COOKIE['sidebarToggled'])) { - if ($_COOKIE['sidebarToggled'] == 'true' ) { - return "toggled"; - } - } -} - -// Returns bridged AP mode status function getBridgedState() { - $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); - // defaults to false + + $hostapdIni = RASPI_CONFIG . '/hostapd.ini'; + if (!file_exists($hostapdIni)) { + return 0; + } else { + $arrHostapdConf = parse_ini_file($hostapdIni); + } return $arrHostapdConf['BridgedEnable']; -} + } // Returns VPN provider ID, if defined function getProviderID() diff --git a/includes/hostapd.php b/includes/hostapd.php index 3b450996..9aad4f30 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -46,7 +46,12 @@ function DisplayHostAPDConfig() SaveHostAPDConfig($arrSecurity, $arrEncType, $arr80211Standard, $interfaces, $reg_domain, $status); } } - $arrHostapdConf = parse_ini_file(RASPI_CONFIG.'/hostapd.ini'); + + $arrHostapdConf = []; + $hostapdIni = RASPI_CONFIG . '/hostapd.ini'; + if (file_exists($hostapdIni)) { + $arrHostapdConf = parse_ini_file($hostapdIni); + } if (!RASPI_MONITOR_ENABLED) { if (isset($_POST['StartHotspot']) || isset($_POST['RestartHotspot'])) { @@ -136,6 +141,9 @@ function DisplayHostAPDConfig() } } + $arrConfig['ignore_broadcast_ssid'] ??= 0; + $arrConfig['max_num_sta'] ??= 0; + $arrConfig['wep_default_key'] ??= 0; exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG); $logdata = getLogLimited(RASPI_HOSTAPD_LOG); @@ -281,6 +289,15 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom $good_input = false; } + $ignore_broadcast_ssid = $_POST['hiddenSSID'] ?? '0'; + if (!ctype_digit($ignore_broadcast_ssid)) { + $status->addMessage('Parameter hiddenSSID not a number.', 'danger'); + $good_input = false; + } elseif ((int)$ignore_broadcast_ssid < 0 || (int)$ignore_broadcast_ssid >= 3) { + $status->addMessage('Parameter hiddenSSID contains an invalid configuration value.', 'danger'); + $good_input = false; + } + /* if (isset($_POST['hiddenSSID'])) { if (!is_int((int)$_POST['hiddenSSID'])) { $status->addMessage('Parameter hiddenSSID not a number.', 'danger'); @@ -294,6 +311,7 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom } else { $ignore_broadcast_ssid = '0'; } + */ if (! in_array($_POST['interface'], $interfaces)) { $status->addMessage('Unknown interface '.htmlspecialchars($_POST['interface'], ENT_QUOTES), 'danger'); @@ -364,14 +382,17 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom // Set dhcp values from system config, fallback to default if undefined $jsonData = json_decode(getNetConfig($ap_iface), true); - $ip_address = ($jsonData['StaticIP'] == '') ? getDefaultNetValue('dhcp',$ap_iface,'static ip_address') : $jsonData['StaticIP']; - $domain_name_server = ($jsonData['StaticDNS'] =='') ? getDefaultNetValue('dhcp',$ap_iface,'static domain_name_server') : $jsonData['StaticDNS']; - $routers = ($jsonData['StaticRouters'] == '') ? getDefaultNetValue('dhcp',$ap_iface,'static routers') : $jsonData['StaticRouters']; - $netmask = ($jsonData['SubnetMask'] == '' || $jsonData['SubnetMask'] == '0.0.0.0') ? getDefaultNetValue('dhcp',$ap_iface,'subnetmask') : $jsonData['SubnetMask']; + $ip_address = empty($jsonData['StaticIP']) + ? getDefaultNetValue('dhcp', $ap_iface, 'static ip_address') : $jsonData['StaticIP']; + $domain_name_server = empty($jsonData['StaticDNS']) + ? getDefaultNetValue('dhcp', $ap_iface, 'static domain_name_server') : $jsonData['StaticDNS']; + $routers = empty($jsonData['StaticRouters']) + ? getDefaultNetValue('dhcp', $ap_iface, 'static routers') : $jsonData['StaticRouters']; + $netmask = (empty($jsonData['SubnetMask']) || $jsonData['SubnetMask'] === '0.0.0.0') + ? getDefaultNetValue('dhcp', $ap_iface, 'subnetmask') : $jsonData['SubnetMask']; if (isset($ip_address) && !preg_match('/.*\/\d+/', $ip_address)) { $ip_address.='/'.mask2cidr($netmask); } - if ($bridgedEnable == 1) { $config = array_keys(getDefaultNetOpts('dhcp','options')); $config[] = PHP_EOL.'# RaspAP br0 configuration'; @@ -392,7 +413,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom $config[] = 'static ip_address='.$ip_address; $config[] = 'static routers='.$routers; $config[] = 'static domain_name_server='.$domain_name_server; - if (! is_null($jsonData['Metric'])) { $config[] = 'metric '.$jsonData['Metric']; } + if (!empty($jsonData['Metric'])) { + $config[] = 'metric ' . $jsonData['Metric']; + } } $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); diff --git a/includes/locale.php b/includes/locale.php index a9f07f65..9f83b5a6 100755 --- a/includes/locale.php +++ b/includes/locale.php @@ -11,7 +11,7 @@ * * Refer to: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 */ -if (empty($_SESSION['locale']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) { +if (empty($_SESSION['locale']) && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) { $lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); switch ($lang) { case "de": @@ -90,9 +90,10 @@ if (empty($_SESSION['locale']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) >= 2) // Use: 'sudo raspi-configure' and select 'Localisation Options' // activate the locale setting -putenv("LANG=" . $_SESSION['locale']); -setlocale(LC_ALL, $_SESSION['locale']); - +if (!empty($_SESSION['locale'])) { + putenv("LANG=" . $_SESSION['locale']); + setlocale(LC_ALL, $_SESSION['locale']); +} bindtextdomain(LOCALE_DOMAIN, LOCALE_ROOT); bind_textdomain_codeset(LOCALE_DOMAIN, 'UTF-8'); diff --git a/includes/navbar.php b/includes/navbar.php index 50050239..c794f64a 100755 --- a/includes/navbar.php +++ b/includes/navbar.php @@ -13,7 +13,7 @@