From af0b405cd64bb58d990917a0e60f2e03366e0635 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Thu, 15 Dec 2016 17:36:26 +0100 Subject: [PATCH 001/132] 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

From 51f1bfe1755a9c3f3c1f28daabf1d6baa32736a1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 16 Dec 2016 13:47:18 +0100 Subject: [PATCH 002/132] Generalized the functions to allow different ad files to be loaded --- php/savesettings.php | 22 ++++++++++++---------- settings.php | 9 ++++++++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/php/savesettings.php b/php/savesettings.php index 6406f2da..821cc0b9 100644 --- a/php/savesettings.php +++ b/php/savesettings.php @@ -34,12 +34,13 @@ function validDomain($domain_name) "8.20.247.20" => "Comodo" ]; -$adlists = []; -function readAdlists() +$adlistsdefault = []; +$adlistsuser = []; +function readAdlists(&$list, $listname) { - global $adlists; - $adlists = []; - $handle = fopen("/etc/pihole/adlists.default", "r"); + // Reset list + $list = []; + $handle = @fopen("/etc/pihole/adlists.".$listname, "r"); if ($handle) { while (($line = fgets($handle)) !== false) @@ -47,12 +48,12 @@ function readAdlists() if(substr($line, 0, 2) === "#h") { // Commented list - array_push($adlists, [false,rtrim(substr($line, 1))]); + array_push($list, [false,rtrim(substr($line, 1))]); } elseif(substr($line, 0, 1) === "h") { // Active list - array_push($adlists, [true,rtrim($line)]); + array_push($list, [true,rtrim($line)]); } } fclose($handle); @@ -60,7 +61,8 @@ function readAdlists() } // Read available adlists - readAdlists(); + readAdlists($adlistsdefault,"default"); + readAdlists($adlistsuser,"user"); $error = ""; $success = ""; @@ -324,7 +326,7 @@ function readAdlists() break; case "adlists": - foreach ($adlists as $key => $value) + foreach ($adlistsdefault as $key => $value) { if(isset($_POST["adlist-".$key])) { @@ -338,7 +340,7 @@ function readAdlists() } // Reread available adlists - readAdlists(); + readAdlists($adlistsdefault,"default"); break; default: diff --git a/settings.php b/settings.php index e903054e..1377f0fe 100644 --- a/settings.php +++ b/settings.php @@ -485,7 +485,14 @@
- $value) { ?> + + $value) { ?> +
+
+
+ + + $value) { ?>
From 7b87301e7ce6ae879cb1408c606fc8da48d1e8d0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 16 Dec 2016 15:16:14 +0100 Subject: [PATCH 003/132] Be able to add lists to the user-defined list + tell the user that the list maintained by us will be reset on every update --- php/savesettings.php | 10 ++++++++++ settings.php | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/php/savesettings.php b/php/savesettings.php index 821cc0b9..343befe6 100644 --- a/php/savesettings.php +++ b/php/savesettings.php @@ -339,8 +339,18 @@ function readAdlists(&$list, $listname) exec("sudo pihole -a adlist ".$action." ".escapeshellcmd ($value[1])); } + if(strlen($_POST["newuserlists"]) > 1) + { + $domains = array_filter(preg_split('/\r\n|[\r\n]/', $_POST["newuserlists"])); + foreach($domains as $domain) + { + exec("sudo pihole -a adlist adduser ".escapeshellcmd($domain)); + } + } + // Reread available adlists readAdlists($adlistsdefault,"default"); + readAdlists($adlistsuser,"user"); break; default: diff --git a/settings.php b/settings.php index 1377f0fe..3e451985 100644 --- a/settings.php +++ b/settings.php @@ -9,7 +9,7 @@ @@ -485,7 +485,7 @@
- + $value) { ?>
@@ -497,6 +497,9 @@
+
+ +