From cc4370151f4a885b11700b05d80ad4cfdb43804c Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 18 Jul 2025 01:29:13 -0700 Subject: [PATCH 1/2] Fix: Persist dhcp-host option to dnsmasq cfg --- includes/hostapd.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/hostapd.php b/includes/hostapd.php index bf44a020..0d7c9819 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -408,6 +408,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom $config[] = 'interface='.$_POST['interface']; $config[] = 'domain-needed'; $config[] = 'dhcp-range='.$dhcp_range; + if (!empty($syscfg['dhcp-host'])) { + $config[] = 'dhcp-host='.$syscfg['dhcp-host']; + } if (!empty($syscfg['dhcp-option'])) { $config[] = 'dhcp-option='.$syscfg['dhcp-option']; } From fcca855c444951c94475951811bb60927b177cb7 Mon Sep 17 00:00:00 2001 From: billz Date: Fri, 18 Jul 2025 01:51:17 -0700 Subject: [PATCH 2/2] Use ParseConfig() to read/write multiple dhcp-* values --- includes/hostapd.php | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/includes/hostapd.php b/includes/hostapd.php index 0d7c9819..5def9a71 100755 --- a/includes/hostapd.php +++ b/includes/hostapd.php @@ -380,8 +380,9 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom $return = iwRegSet($country_code, $status); } - // Fetch dhcp-range, lease time from system config - $syscfg = parse_ini_file(RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', false, INI_SCANNER_RAW); + // Parse dnsmasq config for selected interface + exec('cat '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $lines); + $syscfg = ParseConfig($lines); if ($wifiAPEnable == 1) { // Enable uap0 configuration for ap-sta mode @@ -402,24 +403,39 @@ function SaveHostAPDConfig($wpa_array, $enc_types, $modes, $interfaces, $reg_dom $config = join(PHP_EOL, $config); file_put_contents("/tmp/dnsmasqdata", $config); system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); - } elseif ($bridgedEnable !==1) { - $dhcp_range = ($syscfg['dhcp-range'] =='') ? getDefaultNetValue('dnsmasq',$ap_iface,'dhcp-range') : $syscfg['dhcp-range']; - $config = [ '# RaspAP '.$_POST['interface'].' configuration' ]; - $config[] = 'interface='.$_POST['interface']; + + } elseif ($bridgedEnable !== 1) { + $dhcp_range = ($syscfg['dhcp-range'] == '') + ? getDefaultNetValue('dnsmasq', $ap_iface, 'dhcp-range') + : $syscfg['dhcp-range']; + $config = [ '# RaspAP ' . $_POST['interface'] . ' configuration' ]; + $config[] = 'interface=' . $_POST['interface']; $config[] = 'domain-needed'; - $config[] = 'dhcp-range='.$dhcp_range; + $config[] = 'dhcp-range=' . $dhcp_range; + // handle multiple dhcp-host + option entries if (!empty($syscfg['dhcp-host'])) { - $config[] = 'dhcp-host='.$syscfg['dhcp-host']; + if (is_array($syscfg['dhcp-host'])) { + foreach ($syscfg['dhcp-host'] as $host) { + $config[] = 'dhcp-host=' . $host; + } + } else { + $config[] = 'dhcp-host=' . $syscfg['dhcp-host']; + } } if (!empty($syscfg['dhcp-option'])) { - $config[] = 'dhcp-option='.$syscfg['dhcp-option']; + if (is_array($syscfg['dhcp-option'])) { + foreach ($syscfg['dhcp-option'] as $opt) { + $config[] = 'dhcp-option=' . $opt; + } + } else { + $config[] = 'dhcp-option=' . $syscfg['dhcp-option']; + } } $config[] = PHP_EOL; $config = join(PHP_EOL, $config); file_put_contents("/tmp/dnsmasqdata", $config); - system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); + //system('sudo cp /tmp/dnsmasqdata ' . RASPI_DNSMASQ_PREFIX . $ap_iface . '.conf', $return); } - // Set dhcp values from system config, fallback to default if undefined $jsonData = json_decode(getNetConfig($ap_iface), true); $ip_address = empty($jsonData['StaticIP']) @@ -766,3 +782,4 @@ function parseUserHostapdCfg() return $tmp; } } +