From e3fd40dbf44d3dad0b2590f37358bde5bc0d35bd Mon Sep 17 00:00:00 2001 From: Philipp Kolmann Date: Sat, 7 Dec 2019 10:44:12 +0100 Subject: [PATCH] I have a different service running on FTL default port and so FTL service was not properly started. I searched quite a long time to discover why the Dashboard never loaded and finally found the reason. This patch counts empty lines and dies properly with a JSON error. This fixed my issue. Also I have pi-hole running with apache2 and so no /var/log/lighttpd/error.log exists. Fix: Try apache2 logging location and if not found then write log to a /tmp file. Signed-off-by: Philipp Kolmann --- scripts/pi-hole/php/FTL.php | 9 ++++++++- scripts/pi-hole/php/auth.php | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/FTL.php b/scripts/pi-hole/php/FTL.php index caddd758..df356753 100644 --- a/scripts/pi-hole/php/FTL.php +++ b/scripts/pi-hole/php/FTL.php @@ -26,7 +26,7 @@ function sendRequestFTL($requestin) global $socket; $request = ">".$requestin; - fwrite($socket, $request) or die("Could not send data to server\n"); + fwrite($socket, $request) or die('{"error":"Could not send data to server"}'); } function getResponseFTL() @@ -35,9 +35,16 @@ function getResponseFTL() $response = []; + $errCount = 0; while(true) { $out = fgets($socket); + file_put_contents('/tmp/pihole.txt', $out, FILE_APPEND); + if ($out == "") $errCount++; + if ($errCount > 100) { + // Tried 100 times, but never got proper reply, fail to prevent busy loop + die('{"error":"Tried 100 times to connect to FTL server, but never got proper reply. Please check Port and logs!"}'); + } if(strrpos($out,"---EOM---") !== false) break; diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 1ea6014d..56f84520 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -10,6 +10,14 @@ require_once('func.php'); $ERRORLOG = getenv('PHP_ERROR_LOG'); if (empty($ERRORLOG)) { $ERRORLOG = '/var/log/lighttpd/error.log'; + + if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) { + $ERRORLOG = '/var/log/apache2/error.log'; + + if (!file_exists($ERRORLOG) || !is_writable($ERRORLOG)) { + $ERRORLOG = '/tmp/pi-hole-error.log'; + } + } } function pi_log($message) {