Adding a javascript countdown while checking FTL status

Signed-off-by: RD WebDesign <github@rdwebdesign.com.br>
This commit is contained in:
RD WebDesign
2023-02-13 21:36:05 -03:00
parent d0101870ac
commit 3b150a1d43
3 changed files with 63 additions and 16 deletions
+39
View File
@@ -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 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);
+1 -5
View File
@@ -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');
}
+23 -11
View File
@@ -240,10 +240,13 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array('sysadmin', 'dns', 'piho
<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());
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>
@@ -256,20 +259,19 @@ if ($FTLpid !== 0) {
</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">
@@ -298,10 +300,20 @@ if ($FTLpid !== 0) {
</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>