Skip to content

Commit

Permalink
Fixing FTL information on settings page after a FTL restart (pi-hole#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rdwebdesign authored Apr 15, 2023
2 parents 7b12c33 + 3b150a1 commit efddf9c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 11 deletions.
39 changes: 39 additions & 0 deletions scripts/pi-hole/js/restartdns.js
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 3 additions & 0 deletions scripts/pi-hole/php/savesettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)

$error = '';
$success = '';
$FTLrestarted = false;

if (isset($_POST['field'])) {
// Handle CSRF
Expand Down Expand Up @@ -445,6 +446,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)

case 'restartdns':
pihole_execute('-a restartdns');
$FTLrestarted = true;
$success = 'The DNS server has been restarted';

break;
Expand Down Expand Up @@ -554,6 +556,7 @@ function addStaticDHCPLease($mac, $ip, $hostname)

if ($privacylevel > $level) {
pihole_execute('-a restartdns');
$FTLrestarted = true;
$success .= 'The privacy level has been decreased and the DNS resolver has been restarted';
} elseif ($privacylevel < $level) {
$success .= 'The privacy level has been increased';
Expand Down
34 changes: 23 additions & 11 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,13 @@
<div class="box-body">
<div class="row">
<div class="col-lg-12">
<?php
$FTLpid = intval(pidofFTL());
<?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>
Expand All @@ -256,20 +259,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 @@ -298,10 +300,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 efddf9c

Please sign in to comment.