Skip to content

Commit bf5dab2

Browse files
committed
Fix: gracefully handle unset regulatory domain
1 parent 778b811 commit bf5dab2

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

src/RaspAP/Networking/Hotspot/HotspotService.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,19 +338,18 @@ public function maybeSetRegDomain($countryCode, StatusMessage $status): bool
338338
*/
339339
public function getRegDomain(): string
340340
{
341-
$domain = shell_exec("iw reg get | grep -o 'country [A-Z]\{2\}' | awk 'NR==1{print $2}'");
341+
exec('iw reg get', $output, $returnCode);
342342

343-
if ($domain === null) {
343+
if ($returnCode !== 0) {
344344
throw new \RuntimeException('Failed to execute regulatory domain command');
345345
}
346346

347-
$domain = trim($domain);
348-
349-
if (empty($domain)) {
350-
throw new \RuntimeException('Unable to determine regulatory domain');
347+
foreach ($output as $line) {
348+
if (preg_match('/^country\s+([A-Z]{2}):/', trim($line), $matches)) {
349+
return $matches[1];
350+
}
351351
}
352-
353-
return $domain;
352+
return '';
354353
}
355354

356355
/**

0 commit comments

Comments
 (0)