Use API gateway endpoint

Signed-off-by: Christian König <ckoenig@posteo.de>
This commit is contained in:
Christian König
2022-06-08 08:29:19 +02:00
parent 0ff11d6349
commit 0ccf727edd
2 changed files with 17 additions and 6 deletions

View File

@@ -544,4 +544,15 @@ function piholeStatus() {
return $ret;
}
//Returns the default gateway address and interface
function getGateway() {
$gateway= callFTLAPI("gateway");
if (array_key_exists("FTLnotrunning", $gateway)) {
$ret = array("ip" => -1);
} else {
$ret = array_combine(["ip", "iface"], explode(" ", $gateway[0]));
}
return $ret;
}
?>

View File

@@ -8,6 +8,7 @@
require "scripts/pi-hole/php/header.php";
require "scripts/pi-hole/php/savesettings.php";
require_once "scripts/pi-hole/php/FTL.php";
require_once "scripts/pi-hole/php/func.php";
// Reread ini file as things might have been changed
// DEFAULT_FTLCONFFILE is set in "scripts/pi-hole/php/FTL.php";
$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
@@ -77,12 +78,11 @@ if (isset($setupVars["PIHOLE_INTERFACE"])) {
$piHoleInterface = "unknown";
}
// 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");
}
// if the route did not return anything or $piHoleInterface is unknown
if (empty($IPv4GW)) {
// get the gateway IP
$IPv4GW=getGateway()["ip"];
// if the default gateway address is unknown or FTL is not running
if ($IPv4GW == "0.0.0.0"|| $IPv4GW == -1) {
$IPv4GW = "unknown";
}