diff --git a/includes/hostapd.php b/includes/hostapd.php index 48066769..29c33e35 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -16,6 +16,7 @@ $wifi->getWifiInterface(); */ function DisplayHostAPDConfig() { + $reg_domain = 'GB'; $hostapd = new HostapdManager(); $hotspot = new HotspotService(); $status = new StatusMessage(); @@ -30,10 +31,14 @@ function DisplayHostAPDConfig() $arr80211w = $hotspot->get80211wOptions(); $languageCode = strtok($_SESSION['locale'], '_'); $countryCodes = getCountryCodes($languageCode); - $reg_domain = $hotspot->getRegDomain(); $interfaces = $hotspot->getInterfaces(); $arrTxPower = getDefaultNetOpts('txpower','dbm'); $managedModeEnabled = false; + try { + $reg_domain = $hotspot->getRegDomain(); + } catch (RuntimeException $e) { + error_log('Failed to get regulatory domain: ' . $e->getMessage()); + } if (isset($_POST['interface'])) { $interface = $_POST['interface']; diff --git a/src/RaspAP/Networking/Hotspot/HotspotService.php b/src/RaspAP/Networking/Hotspot/HotspotService.php index 0984634c..2f6a3c60 100644 --- a/src/RaspAP/Networking/Hotspot/HotspotService.php +++ b/src/RaspAP/Networking/Hotspot/HotspotService.php @@ -295,10 +295,22 @@ class HotspotService * Gets the current regulatory domain * * @return string + * @throws RuntimeException if unable to determine regulatory domain */ public function getRegDomain(): string { $domain = shell_exec("iw reg get | grep -o 'country [A-Z]\{2\}' | awk 'NR==1{print $2}'"); + + if ($domain === null) { + throw new \RuntimeException('Failed to execute regulatory domain command'); + } + + $domain = trim($domain); + + if (empty($domain)) { + throw new \RuntimeException('Unable to determine regulatory domain'); + } + return $domain; }