From af0b405cd64bb58d990917a0e60f2e03366e0635 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 17:36:26 +0100 Subject: [PATCH] Enable/disable all lists from /etc/pihole/adlists.default from the Settings page --- php/savesettings.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ settings.php | 22 +++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/php/savesettings.php b/php/savesettings.php index 7460305c..31fda2ed 100644 --- a/php/savesettings.php +++ b/php/savesettings.php @@ -34,6 +34,34 @@ function validDomain($domain_name) "8.20.247.20" => "Comodo" ]; +$adlists = []; +function readAdlists() +{ + global $adlists; + $adlists = []; + $handle = fopen("/etc/pihole/adlists.default", "r"); + if ($handle) + { + while (($line = fgets($handle)) !== false) + { + if(substr($line, 0, 2) === "#h") + { + // Commented list + array_push($adlists, [false,rtrim(substr($line, 1))]); + } + elseif(substr($line, 0, 1) === "h") + { + // Active list + array_push($adlists, [true,rtrim($line)]); + } + } + fclose($handle); + } +} + + // Read available adlists + readAdlists(); + if(isset($_POST["field"])) { $error = ""; @@ -294,6 +322,24 @@ function validDomain($domain_name) break; + case "adlists": + foreach ($adlists as $key => $value) + { + if(isset($_POST["adlist-".$key])) + { + $action = "enable"; + } + else + { + $action = "disable"; + } + exec("sudo pihole -a adlist ".$action." ".escapeshellcmd ($value[1])); + } + + // Reread available adlists + readAdlists(); + break; + default: // Option not found $debug = true; diff --git a/settings.php b/settings.php index 2743bc71..1f85cf0d 100644 --- a/settings.php +++ b/settings.php @@ -477,6 +477,28 @@ */ ?> +
+
+

Pi-Hole's Block Lists

+
+
+
+
+
+ $value) { ?> +
+
+
+ +
+
+ +
+

System Administration