diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index c2710011..650c9fef 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -6,10 +6,10 @@ require_once '../../includes/config.php'; $interface = $_GET['iface']; if (isset($interface)) { + // fetch dnsmasq.conf settings for interface exec('cat '. RASPI_DNSMASQ_PREFIX.$interface.'.conf', $return); $conf = ParseConfig($return); - // populate data $dhcpdata['DHCPEnabled'] = empty($conf) ? false : true; $arrRange = explode(",", $conf['dhcp-range']); $dhcpdata['RangeStart'] = $arrRange[0]; @@ -20,12 +20,11 @@ if (isset($interface)) { $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; $dhcpdata['dhcpHost'] = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; $upstreamServers = is_array($conf['server']) ? $conf['server'] : [ $conf['server'] ]; - $dhcpdata['upstreamServers'] = array_filter($upstreamServers); $dhcpdata['upstreamServersEnabled'] = empty($conf['server']) ? false: true; + $dhcpdata['upstreamServers'] = array_filter($upstreamServers); preg_match('/([0-9]*)([a-z])/i', $dhcpdata['leaseTime'], $arrRangeLeaseTime); $dhcpdata['leaseTime'] = $arrRangeLeaseTime[1]; $dhcpdata['leaseTimeInterval'] = $arrRangeLeaseTime[2]; - if (isset($conf['dhcp-option'])) { $arrDns = explode(",", $conf['dhcp-option']); if ($arrDns[0] == '6') { @@ -37,5 +36,20 @@ if (isset($interface)) { } } } + + // fetch dhcpcd.conf settings for interface + $conf = file_get_contents(RASPI_DHCPCD_CONFIG); + preg_match('/^#\sRaspAP\s'.$interface.'.*?(?=\s*^\s*$)/ms', $conf, $matched); + preg_match('/metric\s(\d*)/', $matched[0], $metric); + preg_match('/static\sip_address=(.*)/', $matched[0], $static_ip); + preg_match('/static\srouters=(.*)/', $matched[0], $static_routers); + preg_match('/static\sdomain_name_servers=(.*)/', $matched[0], $static_dns); + preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); + $dhcpdata['Metric'] = $metric[1]; + $dhcpdata['StaticIP'] = $static_ip[1]; + $dhcpdata['StaticRouters'] = $static_routers[1]; + $dhcpdata['StaticDNS'] = $static_dns[1]; + $dhcpdata['FallbackEnabled'] = empty($fallback) ? false: true; + echo json_encode($dhcpdata); }