Temporarily disable Pi-Hole: Difference between revisions
From WickyWiki
| Line 45: | Line 45: | ||
<syntaxhighlight lang=php> | <syntaxhighlight lang=php> | ||
<?php | <?php | ||
echo "<html><head><title>Disable Pi-Hole Adblocker</title></head>"; | |||
echo "<body><h1>Temporarily disable Pi-Hole Adblocker</h1>"; | |||
$run = $_GET['run']; | $run = $_GET['run']; | ||
$until = $_GET['until']; | $until = $_GET['until']; | ||
| Line 65: | Line 67: | ||
$output=$_GET['output']; | $output=$_GET['output']; | ||
if ($until == "unknown") { | if ($until == "unknown") { | ||
echo " | echo ""; | ||
} | } | ||
elseif ($until == "failed") { | elseif ($until == "failed") { | ||
echo "<hr/> | echo "<hr/><h2>Failure. Please contact the system administrator</h2>"; | ||
} | } | ||
else { | else { | ||
echo "<hr/> | echo "<hr/><h2>Disabled until $until</h2>"; | ||
} | } | ||
} | } | ||
else { $output=$_GET['output']; | else { $output=$_GET['output']; | ||
echo "< | echo "<h2>Click button:</h2>"; | ||
echo "<input type=submit value='Disable | echo "<form action='/wjv-pause-pihole.php'><input type=hidden name=run value='5'/>"; | ||
echo " | echo "<input type=submit style='font-size:30px;white-space:normal;height:120px;width:280px' value='Disable for 5 minutes'/></form>"; | ||
echo "<input type=submit value='Disable | echo "<form action='/wjv-pause-pihole.php'><input type=hidden name=run value='10'/>"; | ||
echo "<input type=submit style='font-size:30px;white-space:normal;height:120px;width:280px' value='Disable for 10 minutes'/></form>"; | |||
} | } | ||
echo "<hr/> Output: $output<hr/>"; | echo "<hr/><h2>Output: $output<hr/></h2></body></html>"; | ||
?> | ?> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 17:59, 29 November 2022
Create scripts
sudo nano /home/pi/wjv-pause-pihole-5m.sh sudo /usr/local/bin/pihole disable 5m
sudo nano /home/pi/wjv-pause-pihole-10m.sh sudo /usr/local/bin/pihole disable 10m
Make executable
sudo chmod +x /home/pi/wjv-pause-pihole-*.sh
Install all scripts to root
sudo cp -v /home/pi/wjv-*.* /root/.
Create sudoers file, add lines
Allow webserver user to execute the scripts.
sudo visudo /etc/sudoers.d/wjv-pause-pihole www-data ALL=NOPASSWD: /root/wjv-pause-pihole-5m.sh www-data ALL=NOPASSWD: /root/wjv-pause-pihole-10m.sh
PHP page
sudo nano /var/www/html/wjv-pause-pihole.php
<?php
echo "<html><head><title>Disable Pi-Hole Adblocker</title></head>";
echo "<body><h1>Temporarily disable Pi-Hole Adblocker</h1>";
$run = $_GET['run'];
$until = $_GET['until'];
if (isset($run)) {
$output = shell_exec("sudo /root/wjv-pause-pihole-" . $run . "m.sh");
$output = str_replace(array("\n", "\r"),"",htmlentities($output, ENT_QUOTES));
if (strpos($output,"Blocking already disabled")) {
$until = "unknown";
}
elseif (strpos($output,"Pi-hole Disabled")) {
$until = date('H:i:s', strtotime("+". $run . " minutes"));
}
else {
$until = "failed";
}
header("Location: ?output=$output&until=$until");
die();
}
elseif (isset($until)) {
$output=$_GET['output'];
if ($until == "unknown") {
echo "";
}
elseif ($until == "failed") {
echo "<hr/><h2>Failure. Please contact the system administrator</h2>";
}
else {
echo "<hr/><h2>Disabled until $until</h2>";
}
}
else { $output=$_GET['output'];
echo "<h2>Click button:</h2>";
echo "<form action='/wjv-pause-pihole.php'><input type=hidden name=run value='5'/>";
echo "<input type=submit style='font-size:30px;white-space:normal;height:120px;width:280px' value='Disable for 5 minutes'/></form>";
echo "<form action='/wjv-pause-pihole.php'><input type=hidden name=run value='10'/>";
echo "<input type=submit style='font-size:30px;white-space:normal;height:120px;width:280px' value='Disable for 10 minutes'/></form>";
}
echo "<hr/><h2>Output: $output<hr/></h2></body></html>";
?>