Skip to content

Commit

Permalink
Adding a javascript countdown while checking FTL status
Browse files Browse the repository at this point in the history
Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
  • Loading branch information
rdwebdesign committed Feb 14, 2023
1 parent f555b84 commit dfbf462
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 16 deletions.
39 changes: 39 additions & 0 deletions 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: <a href='settings.php' class='btn btn-sm btn-primary'>Reload FTL details.</a>";
var warningMsg = "FTL was not able to reload after " + timeleft + " seconds.";
var counterMsg = "FTL is reoaling: ";

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);
6 changes: 1 addition & 5 deletions scripts/pi-hole/php/func.php
Expand Up @@ -691,12 +691,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');
}

Expand Down
34 changes: 23 additions & 11 deletions settings.php
Expand Up @@ -237,10 +237,13 @@
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<?php
$FTLpid = intval(pidofFTL($FTLrestarted));
<?php
// Try to get FTL PID
$FTLpid = intval(pidofFTL($FTLrestarted));

if ($FTLpid !== 0) {
$FTLversion = exec('/usr/bin/pihole-FTL version'); ?>
$FTLversion = exec('/usr/bin/pihole-FTL version');
?>
<table class="table table-striped table-bordered nowrap">
<tbody>
<tr>
Expand All @@ -253,20 +256,19 @@
</tr>
<tr>
<th scope="row">Time FTL started:</th>
<td><?php print_r(get_FTL_data($FTLpid, 'lstart'));
echo ' '.$timezone; ?></td>
<td><?php echo get_FTL_data($FTLpid, 'lstart').' '.$timezone; ?></td>
</tr>
<tr>
<th scope="row">User / Group:</th>
<td><?php print_r(get_FTL_data($FTLpid, 'euser')); ?> / <?php print_r(get_FTL_data($FTLpid, 'egroup')); ?></td>
<td><?php echo get_FTL_data($FTLpid, 'euser').' / '.get_FTL_data($FTLpid, 'egroup'); ?></td>
</tr>
<tr>
<th scope="row">Total CPU utilization:</th>
<td><?php print_r(get_FTL_data($FTLpid, '%cpu')); ?>%</td>
<td><?php echo get_FTL_data($FTLpid, '%cpu'); ?>%</td>
</tr>
<tr>
<th scope="row">Memory utilization:</th>
<td><?php print_r(get_FTL_data($FTLpid, '%mem')); ?>%</td>
<td><?php echo get_FTL_data($FTLpid, '%mem'); ?>%</td>
</tr>
<tr>
<th scope="row">
Expand Down Expand Up @@ -295,10 +297,20 @@
</tbody>
</table>
See also our <a href="https://docs.pi-hole.net/ftldns/dns-cache/" rel="noopener" target="_blank">DNS cache documentation</a>.
<?php
} else { ?>
<?php
} elseif ($FTLrestarted) {
// Show a countdown and a message if FTL was restarted
?>
<div id="restart-countdown"></div>
<script src="<?php echo fileversion('scripts/pi-hole/js/restartdns.js'); ?>"></script>
<?php
} else {
// Show a message if FTL is offline
?>
<div>The FTL service is offline!</div>
<?php } ?>
<?php
}
?>
</div>
</div>
</div>
Expand Down

0 comments on commit dfbf462

Please sign in to comment.