From 3b150a1d43b755c4226af7a3f03d6e583a7083aa Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Mon, 13 Feb 2023 21:36:05 -0300 Subject: [PATCH] Adding a javascript countdown while checking FTL status Signed-off-by: RD WebDesign --- scripts/pi-hole/js/restartdns.js | 39 ++++++++++++++++++++++++++++++++ scripts/pi-hole/php/func.php | 6 +---- settings.php | 34 +++++++++++++++++++--------- 3 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 scripts/pi-hole/js/restartdns.js diff --git a/scripts/pi-hole/js/restartdns.js b/scripts/pi-hole/js/restartdns.js new file mode 100644 index 00000000..248fac07 --- /dev/null +++ b/scripts/pi-hole/js/restartdns.js @@ -0,0 +1,39 @@ +/* Pi-hole: A black hole for Internet advertisements + * (c) 2017 Pi-hole, LLC (https://pi-hole.net) + * Network-wide ad blocking via your own hardware. + * + * This file is copyright under the latest version of the EUPL. + * Please see LICENSE file for your rights under this license. */ + +var timeleft = 60; +var status = -1; +var reloadMsg = + "FTL was restarted: Reload FTL details."; +var warningMsg = "FTL was not able to reload after " + timeleft + " seconds."; +var counterMsg = "FTL is reloading: "; + +var reloadTimer = setInterval(function () { + $.getJSON("api.php?dns-port", function (data) { + if ("FTLnotrunning" in data) { + return; + } + + status = data["dns-port"]; + }); + + if (timeleft <= 0 || status >= 0) { + clearInterval(reloadTimer); + if (status < 0) { + // FTL was not restarted in 60 seconds. Show warning message + document.getElementById("restart-countdown").innerHTML = warningMsg; + } else { + // FTL restartd. + document.getElementById("restart-countdown").innerHTML = reloadMsg; + } + } else { + document.getElementById("restart-countdown").innerHTML = + counterMsg + timeleft + " seconds remaining..."; + } + + timeleft -= 1; +}, 1000); diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 7cf75634..d10ad9bf 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -693,12 +693,8 @@ function convertUnicodeToIDNA($unicode) } // Return PID of FTL (used in settings.php) -function pidofFTL($add_delay = false) +function pidofFTL() { - if ($add_delay) { - usleep(100000); - } - return shell_exec('pidof pihole-FTL'); } diff --git a/settings.php b/settings.php index 21f3cc1e..6ad968d9 100644 --- a/settings.php +++ b/settings.php @@ -240,10 +240,13 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'piho
- + $FTLversion = exec('/usr/bin/pihole-FTL version'); + ?> @@ -256,20 +259,19 @@ if ($FTLpid !== 0) { - + - + - + - +
Time FTL started:
User / Group: /
Total CPU utilization:%%
Memory utilization:%%
@@ -298,10 +300,20 @@ if ($FTLpid !== 0) {
See also our DNS cache documentation. - + +
+ +
The FTL service is offline!
- +