From fcf2eb663f1c106bd0ad9e71feff9f1cae87a1ba Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 2 Oct 2017 12:17:21 +0200 Subject: [PATCH 1/2] Specify one common place for defining the IP of a non-local FTL instance. Fixes #589 Signed-off-by: DL6ER --- api.php | 3 ++- api_FTL.php | 3 ++- scripts/pi-hole/php/FTL.php | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/api.php b/api.php index d1f48c0c..4092540d 100644 --- a/api.php +++ b/api.php @@ -13,6 +13,7 @@ require("scripts/pi-hole/php/password.php"); require("scripts/pi-hole/php/auth.php"); check_cors(); +$FTL_IP = "127.0.0.1"; $data = array(); @@ -74,7 +75,7 @@ elseif (isset($_GET['disable']) && $auth) } // Other API functions -if(!testFTL() && !isset($_GET["PHP"])) +if(!testFTL($FTL_IP) && !isset($_GET["PHP"])) { $data = array_merge($data, array("FTLnotrunning" => true)); } diff --git a/api_FTL.php b/api_FTL.php index 7e259a69..c8231440 100644 --- a/api_FTL.php +++ b/api_FTL.php @@ -12,7 +12,8 @@ if(!isset($api)) die("Direct call to api_FTL.php is not allowed!"); } -$socket = connectFTL("127.0.0.1"); +// $FTL_IP is defined in api.php +$socket = connectFTL($FTL_IP); if (isset($_GET['type'])) { $data["type"] = "FTL"; diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index 4b20e528..590444ae 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -6,10 +6,19 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -function testFTL() +function testFTL($address) { - $ret = shell_exec("pidof pihole-FTL"); - return intval($ret); + if($address === "127.0.0.1") + { + $ret = shell_exec("pidof pihole-FTL"); + return intval($ret); + } + else + { + // We cannot relly test for a distant FTL instance + // in the same way, so we return true here + return true; + } } function connectFTL($address, $port=4711, $quiet=true) From 2f3dc0befe91761a09fcae4f2c38aa5efe71f479 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 2 Oct 2017 12:27:42 +0200 Subject: [PATCH 2/2] Oh :codacy: ... Signed-off-by: DL6ER --- scripts/pi-hole/php/FTL.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index 590444ae..0c07ce5d 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -13,12 +13,12 @@ function testFTL($address) $ret = shell_exec("pidof pihole-FTL"); return intval($ret); } - else - { - // We cannot relly test for a distant FTL instance - // in the same way, so we return true here - return true; - } + // We cannot relly test for a distant FTL instance + // in the same way, so for any other IP address + // we simply return true here and rely on the API + // socket connection itself to fail if there is nothing + // on that address + return true; } function connectFTL($address, $port=4711, $quiet=true)