From 677fe42d8440c465a7650ae71c65e5413f67d1d8 Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 26 Sep 2024 01:36:13 -0700 Subject: [PATCH 1/2] Add support for custom hostapd.conf.users file --- includes/hostapd.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 1a016303..9d15a906 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -135,6 +135,7 @@ function DisplayHostAPDConfig() $selectedHwMode = 'w'; } } + exec('sudo /bin/chmod o+r '.RASPI_HOSTAPD_LOG); $logdata = getLogLimited(RASPI_HOSTAPD_LOG); @@ -395,8 +396,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom } $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); + $skip_dhcp = false; if (preg_match('/wlan[2-9]\d*|wlan[1-9]\d+/', $ap_iface)) { - $skip_dhcp = true;; + $skip_dhcp = true; } elseif ($bridgedEnable == 1 || $wifiAPEnable == 1) { $dhcp_cfg = join(PHP_EOL, $config); $status->addMessage(sprintf(_('DHCP configuration for %s enabled.'), $ap_iface), 'success'); @@ -508,6 +510,21 @@ function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable if (isset($_POST['max_num_sta'])) { $config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL; } + + // Parse optional /etc/hostapd/hostapd.conf.users file + if (file_exists(RASPI_HOSTAPD_CONFIG . '.users')) { + exec('cat '. RASPI_HOSTAPD_CONFIG . '.users', $hostapdconfigusers); + foreach ($hostapdconfigusers as $hostapdconfigusersline) { + if (strlen($hostapdconfigusersline) === 0) { + continue; + } + if ($hostapdconfigusersline[0] != "#") { + $arrLine = explode("=", $hostapdconfigusersline); + $config.= $arrLine[0]."=".$arrLine[1].PHP_EOL;; + } + } + } + file_put_contents("/tmp/hostapddata", $config); system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result); return $result; From 5b88728ec1a5e39e2ee707da42940dbe2ca3bc6c Mon Sep 17 00:00:00 2001 From: billz Date: Thu, 26 Sep 2024 04:17:34 -0700 Subject: [PATCH 2/2] Create function parseUserHostapdCfg() --- includes/hostapd.php | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 9d15a906..3b450996 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -511,19 +511,7 @@ function updateHostapdConfig($ignore_broadcast_ssid,$wifiAPEnable,$bridgedEnable $config.= 'max_num_sta='.$_POST['max_num_sta'].PHP_EOL; } - // Parse optional /etc/hostapd/hostapd.conf.users file - if (file_exists(RASPI_HOSTAPD_CONFIG . '.users')) { - exec('cat '. RASPI_HOSTAPD_CONFIG . '.users', $hostapdconfigusers); - foreach ($hostapdconfigusers as $hostapdconfigusersline) { - if (strlen($hostapdconfigusersline) === 0) { - continue; - } - if ($hostapdconfigusersline[0] != "#") { - $arrLine = explode("=", $hostapdconfigusersline); - $config.= $arrLine[0]."=".$arrLine[1].PHP_EOL;; - } - } - } + $config.= parseUserHostapdCfg(); file_put_contents("/tmp/hostapddata", $config); system("sudo cp /tmp/hostapddata " . RASPI_HOSTAPD_CONFIG, $result); @@ -545,3 +533,25 @@ function iwRegSet(string $country_code, $status) return $result; } +/** + * Parses optional /etc/hostapd/hostapd.conf.users file + * + * @return string $tmp + */ +function parseUserHostapdCfg() +{ + if (file_exists(RASPI_HOSTAPD_CONFIG . '.users')) { + exec('cat '. RASPI_HOSTAPD_CONFIG . '.users', $hostapdconfigusers); + foreach ($hostapdconfigusers as $hostapdconfigusersline) { + if (strlen($hostapdconfigusersline) === 0) { + continue; + } + if ($hostapdconfigusersline[0] != "#") { + $arrLine = explode("=", $hostapdconfigusersline); + $tmp.= $arrLine[0]."=".$arrLine[1].PHP_EOL;; + } + } + return $tmp; + } +} +