Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the FTL information on settings page after a FTL restart #2511

Merged
merged 2 commits into from Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 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
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
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