Implement "Halt system" button, next to "Restart system" button, on
admin/settings page. Useful for doing clean shutdown before powering off.
(Especially important on RPi, to avoid SD card damage.)
(This affects 4 files, 3 for the web content, 1 for backend script.)
Gilbert Detillieux, 2017-04-05
--- /var/www/html/admin/settings.php.DIST 2017-03-22 14:29:44.762663878 -0500
+++ /var/www/html/admin/settings.php 2017-04-05 14:38:46.226161195 -0500
@@ -803,12 +803,16 @@
</div>
<div class="box-body">
<button type="button" class="btn btn-default confirm-reboot">Restart system</button>
+ <button type="button" class="btn btn-default confirm-halt">Halt system</button>
<button type="button" class="btn btn-default confirm-restartdns">Restart DNS server</button>
<button type="button" class="btn btn-default confirm-flushlogs">Flush logs</button>
<form role="form" method="post" id="rebootform">
<input type="hidden" name="field" value="reboot">
</form>
+ <form role="form" method="post" id="haltform">
+ <input type="hidden" name="field" value="halt">
+ </form>
<form role="form" method="post" id="restartdnsform">
<input type="hidden" name="field" value="restartdns">
</form>
--- /var/www/html/admin/scripts/pi-hole/js/settings.js.DIST 2017-04-05 14:46:28.037360970 -0500
+++ /var/www/html/admin/scripts/pi-hole/js/settings.js 2017-04-05 14:35:59.952924200 -0500
@@ -33,6 +33,22 @@
cancelButtonClass: "btn-success",
dialogClass: "modal-dialog modal-mg" // Bootstrap classes for mid-size modal
});
+$(".confirm-halt").confirm({
+ text: "Are you sure you want to send a halt command to your Pi-Hole?",
+ title: "Confirmation required",
+ confirm(button) {
+ $("#haltform").submit();
+ },
+ cancel(button) {
+ // nothing to do
+ },
+ confirmButton: "Yes, halt",
+ cancelButton: "No, go back",
+ post: true,
+ confirmButtonClass: "btn-danger",
+ cancelButtonClass: "btn-success",
+ dialogClass: "modal-dialog modal-mg" // Bootstrap classes for mid-size modal
+});
$(".confirm-restartdns").confirm({
text: "Are you sure you want to send a restart command to your DNS server?",
--- /var/www/html/admin/scripts/pi-hole/php/savesettings.php.DIST 2017-03-22 14:29:44.742664692 -0500
+++ /var/www/html/admin/scripts/pi-hole/php/savesettings.php 2017-04-05 14:37:26.779392786 -0500
@@ -384,6 +384,11 @@
$success = "The system will reboot in 5 seconds...";
break;
+ case "halt":
+ exec("sudo pihole -a halt");
+ $success = "The system will halt in 5 seconds...";
+ break;
+
case "restartdns":
exec("sudo pihole -a restartdns");
$success = "The DNS server has been restarted";
--- /opt/pihole/webpage.sh.DIST 2017-03-22 14:29:49.182483968 -0500
+++ /opt/pihole/webpage.sh 2017-04-05 14:40:32.831823010 -0500
@@ -208,6 +208,12 @@
}
+Halt(){
+
+ nohup bash -c "sleep 5; halt" &> /dev/null </dev/null &
+
+}
+
RestartDNS(){
if [ -x "$(command -v systemctl)" ]; then
@@ -423,6 +429,7 @@
"setexcludedomains" ) SetExcludeDomains;;
"setexcludeclients" ) SetExcludeClients;;
"reboot" ) Reboot;;
+ "halt" ) Halt;;
"restartdns" ) RestartDNS;;
"setquerylog" ) SetQueryLogOptions;;
"enabledhcp" ) EnableDHCP;;