From 6196bcd311f1781ebd36fbbc0be918700f251531 Mon Sep 17 00:00:00 2001 From: glaszig Date: Sat, 3 Apr 2021 00:43:42 +0100 Subject: [PATCH] add 'default route' toggle to network interface configuration ui --- ajax/networking/get_netcfg.php | 2 ++ app/js/custom.js | 1 + includes/dhcp.php | 1 + templates/dhcp/general.php | 12 ++++++++++++ 4 files changed, 16 insertions(+) diff --git a/ajax/networking/get_netcfg.php b/ajax/networking/get_netcfg.php index 2dd330bb..7e7b8fa7 100644 --- a/ajax/networking/get_netcfg.php +++ b/ajax/networking/get_netcfg.php @@ -45,12 +45,14 @@ if (isset($interface)) { preg_match('/static\srouters=(.*)/', $matched[0], $static_routers); preg_match('/static\sdomain_name_server=(.*)/', $matched[0], $static_dns); preg_match('/fallback\sstatic_'.$interface.'/', $matched[0], $fallback); + preg_match('/(?:no)?gateway/', $matched[0], $gateway); $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['FallbackEnabled'] = empty($fallback) ? false: true; + $dhcpdata['DefaultRoute'] = empty($gateway) || $gateway[0] == "gateway"; echo json_encode($dhcpdata); } diff --git a/app/js/custom.js b/app/js/custom.js index 7a885472..13f0db92 100644 --- a/app/js/custom.js +++ b/app/js/custom.js @@ -186,6 +186,7 @@ function loadInterfaceDHCPSelect() { $('#txtsubnetmask').val(jsonData.SubnetMask); $('#txtgateway').val(jsonData.StaticRouters); $('#chkfallback')[0].checked = jsonData.FallbackEnabled; + $('#default-route').prop('checked', jsonData.DefaultRoute); $('#txtrangestart').val(jsonData.RangeStart); $('#txtrangeend').val(jsonData.RangeEnd); $('#txtrangeleasetime').val(jsonData.leaseTime); diff --git a/includes/dhcp.php b/includes/dhcp.php index bc323200..38d69ea5 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -244,6 +244,7 @@ function updateDHCPConfig($iface,$status) $cfg[] = 'profile static_'.$iface; $cfg[] = 'fallback static_'.$iface; } + $cfg[] = $_POST['DefaultRoute'] == '1' ? 'gateway' : 'nogateway'; $dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG); if (!preg_match('/^interface\s'.$iface.'$/m', $dhcp_cfg)) { $cfg[] = PHP_EOL; diff --git a/templates/dhcp/general.php b/templates/dhcp/general.php index 49758696..83bc3504 100644 --- a/templates/dhcp/general.php +++ b/templates/dhcp/general.php @@ -55,6 +55,18 @@ +
+
+
+ + +
+

+ gateway/nogateway option for this interface in the DHCPCD configuration.") ?> +

+
+
+
DHCP options