From dac8138fc83af658cb7ec735f8f45c348ada8de4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 4 Jun 2022 23:17:43 +0200 Subject: [PATCH] Base DHCP settings on default gateway address and not on IPV4_ADDRESS from setupVars.conf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- settings.php | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/settings.php b/settings.php index 3cf7f423..26d6c2b5 100644 --- a/settings.php +++ b/settings.php @@ -76,10 +76,16 @@ if (isset($setupVars["PIHOLE_INTERFACE"])) { } else { $piHoleInterface = "unknown"; } -if (isset($setupVars["IPV4_ADDRESS"])) { - $piHoleIPv4 = $setupVars["IPV4_ADDRESS"]; + +// get the gateway address for the default route on the Pi-hole interface +if ($piHoleInterface !== "unknown") { +$IPv4GW=shell_exec("ip -4 route | grep default | grep '${piHoleInterface}' | cut -d ' ' -f 3"); } else { - $piHoleIPv4 = "unknown"; + $IPv4GW = "unknown"; +} +// if the route did not return anything +if (empty($IPv4GW)) { + $IPv4GW = "unknown"; } // DNS settings @@ -432,8 +438,8 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "dns", "piho } else { $DHCP = false; // Try to guess initial settings - if ($piHoleIPv4 !== "unknown") { - $DHCPdomain = explode(".", $piHoleIPv4); + if ($IPv4GW !== "unknown") { + $DHCPdomain = explode(".", $IPv4GW); $DHCPstart = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".201"; $DHCPend = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".251"; $DHCProuter = $DHCPdomain[0] . "." . $DHCPdomain[1] . "." . $DHCPdomain[2] . ".1";