From 5020e8b5a030118d42a73f4c94434987be0e651b Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 17:52:31 -0800 Subject: [PATCH 1/7] Resolve php warnings on undefined vars --- templates/dhcp/general.php | 2 +- templates/dhcp/logging.php | 6 +++--- templates/dhcp/static_leases.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/dhcp/general.php b/templates/dhcp/general.php index 6eaea7cf..b788c87a 100644 --- a/templates/dhcp/general.php +++ b/templates/dhcp/general.php @@ -3,7 +3,7 @@
- +
diff --git a/templates/dhcp/logging.php b/templates/dhcp/logging.php index a82954a5..975b64a3 100644 --- a/templates/dhcp/logging.php +++ b/templates/dhcp/logging.php @@ -4,11 +4,11 @@

dhcpcd and dnsmasq activity.") ?>

- aria-describedby="log-dhcp-requests"> + aria-describedby="log-dhcp-requests">
- aria-describedby="log-dhcp-queries"> + aria-describedby="log-dhcp-queries"> " />
@@ -16,7 +16,7 @@
'.htmlspecialchars($logdata, ENT_QUOTES).''; } else { echo ''; diff --git a/templates/dhcp/static_leases.php b/templates/dhcp/static_leases.php index caddc6bb..e92772ae 100644 --- a/templates/dhcp/static_leases.php +++ b/templates/dhcp/static_leases.php @@ -47,7 +47,7 @@
- aria-describedby="dhcp-ignore-description"> + aria-describedby="dhcp-ignore-description">

From 26bd632babfe2ed91df8f657fdfb05c37889f0b5 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 17:54:17 -0800 Subject: [PATCH 2/7] Resolve php warnings w/ null coalescing operator --- includes/dhcp.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 4f89c13e..5a63b585 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); From f811d21dc738d18693a3e69b5bd114b2f36867b5 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 17:56:41 -0800 Subject: [PATCH 3/7] Resolve undefined array key php warnings --- ajax/networking/get_netcfg.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) 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); } From b7a6d334e3fb18f02e9abea0b2bcd0c49bf47d26 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 18:19:15 -0800 Subject: [PATCH 4/7] Fix ParseConfig() handling of name-only options, thx @meandthemachine --- includes/functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/includes/functions.php b/includes/functions.php index b50bafb4..859f67ed 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')); @@ -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; From 168dd186794818ec4f0a40a77e8e4b449ec24c41 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 18:21:20 -0800 Subject: [PATCH 5/7] Fix template bug when upstream server is defined --- templates/dhcp/advanced.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/dhcp/advanced.php b/templates/dhcp/advanced.php index 28256114..041a9555 100644 --- a/templates/dhcp/advanced.php +++ b/templates/dhcp/advanced.php @@ -19,9 +19,8 @@

- +
-
From 26c64d42e68efcb9de82669452942d0d5bd8ee13 Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 16 Dec 2024 18:39:33 -0800 Subject: [PATCH 6/7] Fix php warnings w/ null coalescing operator for $_POST keys --- includes/dhcp.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/dhcp.php b/includes/dhcp.php index 5a63b585..47b8edfa 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -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); From 3898b82287ae15107c9a9b503a18ccd631a1fb9a Mon Sep 17 00:00:00 2001 From: billz Date: Tue, 17 Dec 2024 11:32:50 -0800 Subject: [PATCH 7/7] Fix remaining dhcp undefined array key warnings --- includes/functions.php | 4 ++-- templates/dhcp/advanced.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 859f67ed..3099defc 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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; diff --git a/templates/dhcp/advanced.php b/templates/dhcp/advanced.php index 041a9555..59db1be9 100644 --- a/templates/dhcp/advanced.php +++ b/templates/dhcp/advanced.php @@ -7,7 +7,7 @@
- aria-describedby="no-resolv-description"> + aria-describedby="no-resolv-description">