diff --git a/config/defaults.json b/config/defaults.json index 8713d5dd..c9770cc1 100644 --- a/config/defaults.json +++ b/config/defaults.json @@ -1,15 +1,15 @@ { - "hostapd":{ - "modes":{ - "n":{ - "settings":[ + "hostapd": { + "modes": { + "n": { + "settings": [ "hw_mode=g", "ieee80211n=1", "wmm_enabled=1" ] }, - "ac":{ - "settings":[ + "ac": { + "settings": [ "hw_mode=a", "# N", "ieee80211n=1", @@ -25,90 +25,117 @@ "vht_oper_centr_freq_seg0_idx={VHT_FREQ_IDX}" ] }, - "g":{ - "settings":[ + "g": { + "settings": [ "hw_mode=g", "ieee80211n=0" ] }, - "a":{ - "settings":[ + "a": { + "settings": [ "hw_mode=a", "ieee80211n=0" ] }, - "b":{ - "settings":[ + "b": { + "settings": [ "hw_mode=b", "ieee80211n=0" ] } + } + }, + "dhcp": { + "wlan0": { + "static ip_address": [ "10.3.141.1" ], + "static routers": [ "10.3.141.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] }, - "dhcp":{ - "wlan0":{ - "static ip_address":[ "10.3.141.1/24" ], - "static routers":[ "10.3.141.1" ], - "static domain_name_server":[ "1.1.1.1 8.8.8.8" ], - "subnetmask":[ "255.255.255.0" ] - }, - "wlan1":{ - "static ip_address":[ "10.9.141.1/24" ], - "static routers":[ "10.9.141.1" ], - "static domain_name_server":[ "1.1.1.1 8.8.8.8" ], - "subnetmask":[ "255.255.255.0" ] - }, - "uap0":{ - "static ip_address":[ "192.168.50.1/24" ], - "static routers":[ "192.168.50.1" ], - "static domain_name_server":[ "1.1.1.1 8.8.8.8" ], - "subnetmask":[ "255.255.255.0" ] - }, - "options":{ - "# RaspAP default configuration":null, - "hostname":null, - "clientid":null, - "persistent":null, - "option rapid_commit":null, - "option domain_name_servers, domain_name, domain_search, host_name":null, - "option classless_static_routes":null, - "option ntp_servers":null, - "require dhcp_server_identifier":null, - "slaac private":null, - "nohook lookup-hostname":null - } + "wlan1": { + "static ip_address": [ "10.9.141.1" ], + "static routers": [ "10.9.141.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] }, - "dnsmasq":{ - "wlan0":{ - "dhcp-range":[ "10.3.141.50,10.3.141.254,255.255.255.0,12h" ] - }, - "wlan1":{ - "dhcp-range":[ "10.9.141.50,10.9.141.254,255.255.255.0,12h" ] - }, - "uap0":{ - "dhcp-range":[ "192.168.50.50,192.168.50.150,12h" ] - } + "wlan2": { + "static ip_address": [ "10.6.141.1" ], + "static routers": [ "10.6.141.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] }, - "wireguard":{ - "server":{ - "Address":[ "10.8.2.1/24" ], - "ListenPort":[ "51820" ], - "DNS":[ "9.9.9.9" ], - "PostUp":[ "iptables -A FORWARD -i wlan0 -o wg0 -j ACCEPT; iptables -A FORWARD -i wg0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE" ], - "PostDown":[ "iptables -D FORWARD -i wlan0 -o wg0 -j ACCEPT; iptables -D FORWARD -i wg0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -D POSTROUTING -o wg0 -j MASQUERADE" ], - "PostUpEx":[ "iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d %s -j REJECT" ], - "PreDown":[ "iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d %s -j REJECT" ] - }, - "peer":{ - "Address":[ "10.8.1.2/24" ], - "Endpoint":[ "10.8.2.1:51820" ], - "ListenPort":[ "21841" ], - "AllowedIPs":[ "10.8.2.0/24" ], - "PersistentKeepalive":[ "15" ] - } - }, - "txpower": { - "dbm": [ "auto", "30", "20", "17", "10", "6", "3", "1", "0" ] - } + "uap0": { + "static ip_address": ["192.168.50.1" ], + "static routers": [ "192.168.50.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] + }, + "eth0": { + "static ip_address": [ "192.168.55.1" ], + "static routers": [ "192.168.55.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] + }, + "enx": { + "static ip_address": [ "192.168.60.1" ], + "static routers": [ "192.168.60.1" ], + "static domain_name_server": [ "1.1.1.1 8.8.8.8" ], + "subnetmask": [ "255.255.255.0" ] + }, + "options": { + "# RaspAP default configuration": null, + "hostname": null, + "clientid": null, + "persistent": null, + "option rapid_commit": null, + "option domain_name_servers, domain_name, domain_search, host_name": null, + "option classless_static_routes": null, + "option ntp_servers": null, + "require dhcp_server_identifier": null, + "slaac private": null, + "nohook lookup-hostname": null + } + }, + "dnsmasq": { + "wlan0": { + "dhcp-range": [ "10.3.141.50,10.3.141.254,255.255.255.0,12h" ] + }, + "wlan1": { + "dhcp-range": [ "10.9.141.50,10.9.141.254,255.255.255.0,12h" ] + }, + "wlan2": { + "dhcp-range": [ "10.6.141.50,10.6.141.254,255.255.255.0,12h" ] + }, + "uap0": { + "dhcp-range": [ "192.168.50.50,192.168.50.150,12h" ] + }, + "eth0": { + "dhcp-range": [ "192.168.55.50,192.168.55.150,12h" ] + }, + "enx": { + "dhcp-range": [ "192.168.60.50,192.168.60.150,12h" ] + } + }, + "wireguard": { + "server": { + "Address": [ "10.8.2.1/24" ], + "ListenPort": [ "51820" ], + "DNS": [ "9.9.9.9" ], + "PostUp": [ "iptables -A FORWARD -i wlan0 -o %i -j ACCEPT; iptables -A FORWARD -i %i -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -A POSTROUTING -o %i -j MASQUERADE" ], + "PostDown": [ "iptables -D FORWARD -i wlan0 -o %i -j ACCEPT; iptables -D FORWARD -i %i -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT; iptables -t nat -D POSTROUTING -o %i -j MASQUERADE" ], + "PostUpEx": [ "iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d %s -j REJECT" ], + "PreDown": [ "iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL ! -d %s -j REJECT" ] + }, + "peer": { + "Address": [ "10.8.1.2/24" ], + "Endpoint": [ "10.8.2.1:51820" ], + "ListenPort": [ "21841" ], + "AllowedIPs": [ "10.8.2.0/24" ], + "PersistentKeepalive": [ "15" ] + } + }, + "txpower": { + "dbm": [ "auto", "30", "20", "17", "10", "6", "3", "1", "0" ] } } diff --git a/src/RaspAP/Networking/Hotspot/DhcpcdManager.php b/src/RaspAP/Networking/Hotspot/DhcpcdManager.php index 9b8f58db..b49e9285 100644 --- a/src/RaspAP/Networking/Hotspot/DhcpcdManager.php +++ b/src/RaspAP/Networking/Hotspot/DhcpcdManager.php @@ -41,7 +41,7 @@ class DhcpcdManager { // determine static IP, routers, DNS $jsonData = $this->getInterfaceConfig($ap_iface); - //error_log("DhcpcdManager::buildConfig() jsonData =" . print_r($jsonData, true)); + $ip_address = empty($jsonData['StaticIP']) ? getDefaultNetValue('dhcp', $ap_iface, 'static ip_address') : $jsonData['StaticIP']; @@ -485,6 +485,21 @@ class DhcpcdManager } } } + } else { + // fallback to defaults + $rangeRaw = getDefaultNetValue('dnsmasq', $iface, 'dhcp-range'); + if ($rangeRaw) { + $result['DHCPEnabled'] = true; + $rangeParts = explode(',', $rangeRaw); + $result['RangeStart'] = $rangeParts[0] ?? null; + $result['RangeEnd'] = $rangeParts[1] ?? null; + $result['RangeMask'] = $rangeParts[2] ?? null; + $leaseSpec = $rangeParts[3] ?? null; + if ($leaseSpec && preg_match('/^(\d+)([smhd])?$/i', $leaseSpec, $m)) { + $result['leaseTime'] = $m[1]; + $result['leaseTimeInterval'] = $m[2] ?? 'h'; + } + } } // dhcpcd @@ -513,6 +528,11 @@ class DhcpcdManager $result['FallbackEnabled'] = (bool) preg_match('/fallback\s+static_' . preg_quote($iface, '/') . '/i', $block); $result['DefaultRoute'] = (bool) preg_match('/\bgateway\b/', $block); $result['NoHookWPASupplicant'] = (bool) preg_match('/nohook\s+wpa_supplicant/i', $block); + } else { + $result['StaticIP'] = getDefaultNetValue('dhcp', $iface, 'static ip_address'); + $result['SubnetMask'] = getDefaultNetValue('dhcp', $iface, 'subnetmask'); + $result['StaticRouters'] = getDefaultNetValue('dhcp', $iface, 'static routers'); + $result['StaticDNS'] = getDefaultNetValue('dhcp', $iface, 'static domain_name_server'); } } return $result; diff --git a/src/RaspAP/Networking/Hotspot/DnsmasqManager.php b/src/RaspAP/Networking/Hotspot/DnsmasqManager.php index 49bb8ee7..6076ff44 100644 --- a/src/RaspAP/Networking/Hotspot/DnsmasqManager.php +++ b/src/RaspAP/Networking/Hotspot/DnsmasqManager.php @@ -61,8 +61,17 @@ class DnsmasqManager * @return array $config * @throws \RuntimeException */ - public function buildConfig(array $syscfg, string $iface, bool $wifiAPEnable, bool $bridgedEnable): array + public function buildConfig(?array $syscfg, string $iface, bool $wifiAPEnable, bool $bridgedEnable): array { + // fallback: if no syscfg for interface seed with defaults + if ($syscfg === null) { + $syscfg = []; + $dhcp_range = getDefaultNetValue('dnsmasq', $iface, 'dhcp-range'); + if ($dhcp_range !== false) { + $syscfg['dhcp-range'] = $dhcp_range; + } + } + if ($wifiAPEnable == 1) { // Enable uap0 configuration for ap-sta mode // Set dhcp-range from system config, fallback to default if undefined