diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index 757a9c1e..5b7bf2e1 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -18,14 +18,14 @@ if (isset($interface)) { } else { $arrRange = explode(",", $conf['dhcp-range'][0]); } - $dhcpdata['RangeStart'] = $arrRange[0]; - $dhcpdata['RangeEnd'] = $arrRange[1]; - $dhcpdata['RangeMask'] = $arrRange[2]; - $dhcpdata['leaseTime'] = $arrRange[3]; - $dhcpHost = $conf["dhcp-host"]; + $dhcpdata['RangeStart'] = $arrRange[0] ?? null; + $dhcpdata['RangeEnd'] = $arrRange[1] ?? null; + $dhcpdata['RangeMask'] = $arrRange[2] ?? null; + $dhcpdata['leaseTime'] = $arrRange[3] ?? null; + $dhcpHost = $conf["dhcp-host"] ?? null; $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; $dhcpdata['dhcpHost'] = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; - $upstreamServers = is_array($conf['server']) ? $conf['server'] : [ $conf['server'] ]; + $upstreamServers = is_array($conf['server'] ?? null) ? $conf['server'] : [ $conf['server'] ?? '' ]; $dhcpdata['upstreamServersEnabled'] = empty($conf['server']) ? false: true; $dhcpdata['upstreamServers'] = array_filter($upstreamServers); preg_match('/([0-9]*)([a-z])/i', $dhcpdata['leaseTime'], $arrRangeLeaseTime); @@ -35,10 +35,10 @@ if (isset($interface)) { $arrDns = explode(",", $conf['dhcp-option']); if ($arrDns[0] == '6') { if (count($arrDns) > 1) { - $dhcpdata['DNS1'] = $arrDns[1]; + $dhcpdata['DNS1'] = $arrDns[1] ?? null; } if (count($arrDns) > 2) { - $dhcpdata['DNS2'] = $arrDns[2]; + $dhcpdata['DNS2'] = $arrDns[2] ?? null; } } } @@ -53,13 +53,15 @@ if (isset($interface)) { preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); preg_match('/(?:no)?gateway/', $matched[0], $gateway); preg_match('/nohook\swpa_supplicant/', $matched[0], $nohook_wpa_supplicant); - $dhcpdata['Metric'] = $metric[1]; - $dhcpdata['StaticIP'] = strpos($static_ip[1],'/') ? substr($static_ip[1], 0, strpos($static_ip[1],'/')) : $static_ip[1]; - $dhcpdata['SubnetMask'] = cidr2mask($static_ip[1]); - $dhcpdata['StaticRouters'] = $static_routers[1]; - $dhcpdata['StaticDNS'] = $static_dns[1]; + $dhcpdata['Metric'] = $metric[1] ?? null; + $dhcpdata['StaticIP'] = isset($static_ip[1]) && strpos($static_ip[1], '/') !== false + ? substr($static_ip[1], 0, strpos($static_ip[1], '/')) + : ($static_ip[1] ?? ''); + $dhcpdata['SubnetMask'] = cidr2mask($static_ip[1] ?? ''); + $dhcpdata['StaticRouters'] = $static_routers[1] ?? null; + $dhcpdata['StaticDNS'] = $static_dns[1] ?? null; $dhcpdata['FallbackEnabled'] = empty($fallback) ? false: true; $dhcpdata['DefaultRoute'] = $gateway[0] == "gateway"; - $dhcpdata['NoHookWPASupplicant'] = $nohook_wpa_supplicant[0] == "nohook wpa_supplicant"; + $dhcpdata['NoHookWPASupplicant'] = ($nohook_wpa_supplicant[0] ?? '') == "nohook wpa_supplicant"; echo json_encode($dhcpdata); } diff --git a/includes/dhcp.php b/includes/dhcp.php index 4f89c13e..47b8edfa 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -52,8 +52,8 @@ function DisplayDHCPConfig() $conf = ParseConfig($return); exec('cat '. RASPI_DNSMASQ_PREFIX.$ap_iface.'.conf', $return); $conf = array_merge(ParseConfig($return)); - $hosts = (array)$conf['dhcp-host']; - $upstreamServers = (array)$conf['server']; + $hosts = (array)($conf['dhcp-host'] ?? []); + $upstreamServers = (array)($conf['server'] ?? []); exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces); exec('cat ' . RASPI_DNSMASQ_LEASES, $leases); @@ -280,10 +280,10 @@ function updateDnsmasqConfig($iface,$status) $config .='log-facility='.RASPI_DHCPCD_LOG.PHP_EOL; $config .='conf-dir=/etc/dnsmasq.d'.PHP_EOL; // handle log option - if ($_POST['log-dhcp'] == "1") { + if (($_POST['log-dhcp'] ?? '') == "1") { $config .= "log-dhcp".PHP_EOL; } - if ($_POST['log-queries'] == "1") { + if (($_POST['log-queries'] ?? '') == "1") { $config .= "log-queries".PHP_EOL; } $config .= PHP_EOL; @@ -317,12 +317,12 @@ function updateDHCPConfig($iface,$status) if ($_POST['Metric'] !== '') { $cfg[] = 'metric '.$_POST['Metric']; } - if ($_POST['Fallback'] == 1) { + if (($_POST['Fallback'] ?? 0) == 1) { $cfg[] = 'profile static_'.$iface; $cfg[] = 'fallback static_'.$iface; } - $cfg[] = $_POST['DefaultRoute'] == '1' ? 'gateway' : 'nogateway'; - if (( substr($iface, 0, 2) === "wl") && $_POST['NoHookWPASupplicant'] == '1') { + $cfg[] = ($_POST['DefaultRoute'] ?? '') == '1' ? 'gateway' : 'nogateway'; + if (substr($iface, 0, 2) === "wl" && ($_POST['NoHookWPASupplicant'] ?? '') == '1') { $cfg[] = 'nohook wpa_supplicant'; } $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); diff --git a/includes/functions.php b/includes/functions.php index b50bafb4..3099defc 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -54,7 +54,7 @@ function cidr2mask($cidr) { $ipParts = explode('/', $cidr); $ip = $ipParts[0]; - $prefixLength = $ipParts[1]; + $prefixLength = $ipParts[1] ?? null; $ipLong = ip2long($ip); $netmaskLong = bindec(str_pad(str_repeat('1', $prefixLength), 32, '0')); @@ -338,9 +338,9 @@ function CSRFValidate() { if(isset($_POST['csrf_token'])) { $post_token = $_POST['csrf_token']; - $header_token = $_SERVER['HTTP_X_CSRF_TOKEN']; + $header_token = $_SERVER['HTTP_X_CSRF_TOKEN'] ?? null; - if (empty($post_token) && empty($header_token)) { + if (empty($post_token) && is_null($header_token)) { return false; } $request_token = $post_token; @@ -458,6 +458,9 @@ function ParseConfig($arrConfig, $wg = false) if (strpos($line, "=") !== false) { list($option, $value) = array_map("trim", explode("=", $line, 2)); + } else { + $option = $line; + $value = ""; } if (empty($config[$option])) { $config[$option] = $value ?: true; diff --git a/templates/dhcp/advanced.php b/templates/dhcp/advanced.php index 28256114..59db1be9 100644 --- a/templates/dhcp/advanced.php +++ b/templates/dhcp/advanced.php @@ -7,7 +7,7 @@
@@ -19,9 +19,8 @@
dhcpcd and dnsmasq
activity.") ?>