From 4d45afa27bdcc53a9f0e8845c03f811d1c22c135 Mon Sep 17 00:00:00 2001 From: Yusnel Rojas Garcia Date: Fri, 11 Oct 2019 13:24:22 -0400 Subject: [PATCH] support dns options in dnsmasq configuration --- config/dnsmasq.conf | 1 + includes/dhcp.php | 30 ++++++++++++++++++++++++++++++ templates/dhcp.php | 23 +++++++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/config/dnsmasq.conf b/config/dnsmasq.conf index 51873f23..acbf4765 100644 --- a/config/dnsmasq.conf +++ b/config/dnsmasq.conf @@ -1,6 +1,7 @@ # RaspAP wlan0 configuration for wired (ethernet) AP mode interface=wlan0 dhcp-range=10.3.141.50,10.3.141.255,255.255.255.0,12h +dhcp-option=6,1.1.1.1,8.8.8.8 # RaspAP uap0 configuration for wireless client AP mode #interface=lo,uap0 # Use interfaces lo and uap0 diff --git a/includes/dhcp.php b/includes/dhcp.php index 61c40b03..0baadcf8 100755 --- a/includes/dhcp.php +++ b/includes/dhcp.php @@ -55,6 +55,17 @@ function DisplayDHCPConfig() $config .= "dhcp-host=$mac,$ip".PHP_EOL; } } + + if ($_POST['DNS1']){ + $config .= "dhcp-option=6," . $_POST['DNS1']; + + if ($_POST['DNS2']){ + $config .= ','.$_POST['DNS2']; + } + + $config .= PHP_EOL; + } + file_put_contents("/tmp/dnsmasqdata", $config); system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return); } else { @@ -110,6 +121,23 @@ function DisplayDHCPConfig() $dhcpHost = empty($dhcpHost) ? [] : $dhcpHost; $dhcpHost = is_array($dhcpHost) ? $dhcpHost : [ $dhcpHost ]; + $DNS1 = ''; + $DNS2 = ''; + + if (isset($conf['dhcp-option'])){ + $arrDns = explode(",", $conf['dhcp-option']); + + if ($arrDns[0] == '6'){ + if (count($arrDns) > 1){ + $DNS1 = $arrDns[1]; + } + + if (count($arrDns) > 2){ + $DNS2 = $arrDns[2]; + } + } + } + $hselected = ''; $mselected = ''; $dselected = ''; @@ -139,6 +167,8 @@ function DisplayDHCPConfig() "serviceStatus", "RangeStart", "RangeEnd", + "DNS1", + "DNS2", "arrRangeLeaseTime", "mselected", "hselected", diff --git a/templates/dhcp.php b/templates/dhcp.php index 7d1329b0..5e6fed40 100755 --- a/templates/dhcp.php +++ b/templates/dhcp.php @@ -63,7 +63,22 @@ - + +
+
+ + +
+
+ +
+
+ + +
+
+ + " name="savedhcpdsettings" /> " name="stopdhcpd" /> @@ -94,11 +109,11 @@ - - + + + -