mirror of
				https://github.com/billz/raspap-webgui.git
				synced 2025-03-01 10:31:47 +00:00 
			
		
		
		
	Merge pull request #1714 from RaspAP/fix/dhcp-roundup
Roundup of fixes for DHCP handling
This commit is contained in:
		| @@ -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); | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -7,7 +7,7 @@ | ||||
|       <div class="input-group"> | ||||
|         <input type="hidden" name="no-resolv" value="0"> | ||||
|         <div class="form-check form-switch"> | ||||
|           <input class="form-check-input" id="no-resolv" type="checkbox" name="no-resolv" value="1" <?php echo $conf['no-resolv'] ? ' checked="checked"' : "" ?> aria-describedby="no-resolv-description"> | ||||
|           <input class="form-check-input" id="no-resolv" type="checkbox" name="no-resolv" value="1" <?php echo ($conf['no-resolv'] ?? false) ? ' checked="checked"' : '' ?> aria-describedby="no-resolv-description"> | ||||
|           <label class="form-check-label" for="no-resolv"><?php echo _("Only ever query DNS servers configured below") ?></label> | ||||
|         </div> | ||||
|         <p id="no-resolv-description"> | ||||
| @@ -19,9 +19,8 @@ | ||||
|       <div class="js-dhcp-upstream-servers"> | ||||
|         <?php foreach ($upstreamServers as $server): ?> | ||||
|           <div class="mb-3 input-group input-group-sm js-dhcp-upstream-server"> | ||||
|             <input type="text" class="form-control" name="server[]" value="<?php echo $server ?>"> | ||||
|             <input type="text" class="form-control" name="server[]" value="<?php echo $server; ?>"> | ||||
|             <div class="input-group-text js-remove-dhcp-upstream-server"><i class="fas fa-minus"></i></div> | ||||
|             </div> | ||||
|           </div> | ||||
|         <?php endforeach ?> | ||||
|       </div> | ||||
|   | ||||
| @@ -3,7 +3,7 @@ | ||||
|   <div class="row"> | ||||
|     <div class="mb-3 col-md-6"> | ||||
|       <label for="code">Interface</label> | ||||
|         <?php SelectorOptions('interface', $interfaces, $ap_iface, 'cbxdhcpiface', 'loadInterfaceDHCPSelect', $DHCPDisabled); ?> | ||||
|         <?php SelectorOptions('interface', $interfaces, $ap_iface, 'cbxdhcpiface', 'loadInterfaceDHCPSelect'); ?> | ||||
|     </div> | ||||
|   </div> | ||||
|  | ||||
|   | ||||
| @@ -4,11 +4,11 @@ | ||||
|   <p><?php echo _("Enable these options to log <code>dhcpcd</code> and <code>dnsmasq</code> activity.") ?></p> | ||||
|  | ||||
|   <div class="form-check form-switch"> | ||||
|     <input class="form-check-input" id="log-dhcp" type="checkbox" name="log-dhcp" value="1" <?php echo $conf['log-dhcp'] ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-requests"> | ||||
|     <input class="form-check-input" id="log-dhcp" type="checkbox" name="log-dhcp" value="1" <?php echo !empty($conf['log-dhcp']) ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-requests"> | ||||
|     <label class="form-check-label" for="log-dhcp"><?php echo _("Log DHCP requests") ?></label> | ||||
|   </div> | ||||
|   <div class="form-check form-switch"> | ||||
|     <input class="form-check-input" id="log-queries" type="checkbox" name="log-queries" value="1" <?php echo $conf['log-queries'] ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-queries"> | ||||
|     <input class="form-check-input" id="log-queries" type="checkbox" name="log-queries" value="1" <?php echo !empty($conf['log-queries']) ? ' checked="checked"' : "" ?> aria-describedby="log-dhcp-queries"> | ||||
|     <label class="form-check-label align-middle" for="log-queries"><?php echo _("Log DNS queries") ?></label> | ||||
|     <input type="button" class="btn btn-outline btn-warning btn-sm align-top ms-4" id="js-cleardnsmasq-log" value="<?php echo _("Clear log"); ?>" /> | ||||
|   </div> | ||||
| @@ -16,7 +16,7 @@ | ||||
|   <div class="row"> | ||||
|     <div class="mb-3 col-md-8 mt-2"> | ||||
|       <?php | ||||
|       if ($conf['log-dhcp'] == 1 || $conf['log-queries'] == 1) { | ||||
|       if (($conf['log-dhcp'] ?? 0) == 1 || ($conf['log-queries'] ?? 0) == 1) { | ||||
|           echo '<textarea class="logoutput text-secondary" id="dnsmasq-log">'.htmlspecialchars($logdata, ENT_QUOTES).'</textarea>'; | ||||
|       } else { | ||||
|           echo '<textarea class="logoutput my-3"></textarea>'; | ||||
|   | ||||
| @@ -47,7 +47,7 @@ | ||||
|         <div class="input-group"> | ||||
|           <input type="hidden" name="dhcp-ignore" value="0"> | ||||
|             <div class="form-check form-switch"> | ||||
|               <input class="form-check-input" id="dhcp-ignore" type="checkbox" name="dhcp-ignore" value="1" <?php echo $conf['dhcp-ignore'] ? ' checked="checked"' : "" ?> aria-describedby="dhcp-ignore-description"> | ||||
|               <input class="form-check-input" id="dhcp-ignore" type="checkbox" name="dhcp-ignore" value="1" <?php echo !empty($conf['dhcp-ignore']) ? ' checked="checked"' : "" ?> aria-describedby="dhcp-ignore-description"> | ||||
|               <label class="form-check-label" for="dhcp-ignore"><?php echo _("Limit network access to static clients") ?></label> | ||||
|             </div> | ||||
|             <p id="dhcp-ignore-description"> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user