From 606568054a81805499b252933c6712648d32f06d Mon Sep 17 00:00:00 2001
From: Adam Warner
Date: Sun, 7 Jun 2020 11:09:20 +0100
Subject: [PATCH 1/9] enable IP sorting on the query/long-term query pages.
Appears to work with a mixture of hostnames/IP's
Signed-off-by: Adam Warner
---
db_queries.php | 2 +-
queries.php | 2 +-
scripts/pi-hole/js/db_queries.js | 2 +-
scripts/pi-hole/js/queries.js | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/db_queries.php b/db_queries.php
index fdb2f0553..c1d0b6c6a 100644
--- a/db_queries.php
+++ b/db_queries.php
@@ -159,7 +159,7 @@
-
+
diff --git a/queries.php b/queries.php
index 3723ed17c..4cc70e6df 100644
--- a/queries.php
+++ b/queries.php
@@ -150,7 +150,7 @@
-
+
diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js
index d2af6535d..184c59eb5 100644
--- a/scripts/pi-hole/js/db_queries.js
+++ b/scripts/pi-hole/js/db_queries.js
@@ -373,7 +373,7 @@ $(function () {
},
{ width: "10%" },
{ width: "40%" },
- { width: "20%" },
+ { width: "20%" , type: "ip-address" },
{ width: "10%" },
{ width: "5%" }
],
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index e9da5b30e..1d2815de5 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -390,7 +390,7 @@ $(function () {
},
{ width: "4%" },
{ width: "36%", render: $.fn.dataTable.render.text() },
- { width: "8%", render: $.fn.dataTable.render.text() },
+ { width: "8%", type: "ip-address", render: $.fn.dataTable.render.text() },
{ width: "14%", orderData: 4 },
{ width: "8%", orderData: 6 },
{ width: "10%", orderData: 4 }
From 3a68efc4b0d23409d3c7cda0ab248a891b1ad3f8 Mon Sep 17 00:00:00 2001
From: Adam Warner
Date: Thu, 16 Jul 2020 18:44:00 +0100
Subject: [PATCH 2/9] fix a complaint from the CI
Signed-off-by: Adam Warner
---
scripts/pi-hole/js/db_queries.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js
index 184c59eb5..7707dee3a 100644
--- a/scripts/pi-hole/js/db_queries.js
+++ b/scripts/pi-hole/js/db_queries.js
@@ -373,7 +373,7 @@ $(function () {
},
{ width: "10%" },
{ width: "40%" },
- { width: "20%" , type: "ip-address" },
+ { width: "20%", type: "ip-address" },
{ width: "10%" },
{ width: "5%" }
],
From 99adb3012b4b96ecd236ef2d497562ea3337be85 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sun, 19 Jul 2020 22:13:05 +0200
Subject: [PATCH 3/9] Fix arpflush command
Signed-off-by: DL6ER
---
scripts/pi-hole/php/savesettings.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index 23e0efdcf..af95c901b 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -737,7 +737,7 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
break;
// Flush network table
case "flusharp":
- pihole_execute("arpflush quiet", $output);
+ $output = pihole_execute("arpflush quiet");
$error = implode(" ", $output);
if(strlen($error) == 0)
{
From 8672c49b4b2f8c46ab163304d68a473cdae46f12 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Mon, 20 Jul 2020 21:43:44 +0200
Subject: [PATCH 4/9] Replace "." by "_" in hostnames to work around a PHP Phar
bug.
Signed-off-by: DL6ER
---
scripts/pi-hole/php/teleporter.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php
index cfd4bc479..8948c19fd 100644
--- a/scripts/pi-hole/php/teleporter.php
+++ b/scripts/pi-hole/php/teleporter.php
@@ -540,7 +540,7 @@ function process_file($contents)
}
else
{
- $hostname = gethostname() ? gethostname()."-" : "";
+ $hostname = gethostname() ? str_replace(".", "_", gethostname())."-" : "";
$tarname = "pi-hole-".$hostname."teleporter_".date("Y-m-d_H-i-s").".tar";
$filename = $tarname.".gz";
$archive_file_name = sys_get_temp_dir() ."/". $tarname;
From fdea341c9f059423a76d2e49c03eea49e0cb1377 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Mon, 20 Jul 2020 22:04:59 +0200
Subject: [PATCH 5/9] Fix audit log button doing nothing (resp. wrongthing)
Signed-off-by: DL6ER
---
scripts/pi-hole/js/auditlog.js | 2 +-
scripts/pi-hole/php/groups.php | 47 ++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/scripts/pi-hole/js/auditlog.js b/scripts/pi-hole/js/auditlog.js
index d794fa1d2..65b8eecca 100644
--- a/scripts/pi-hole/js/auditlog.js
+++ b/scripts/pi-hole/js/auditlog.js
@@ -99,7 +99,7 @@ function add(domain, list) {
domain: domain,
list: list,
token: token,
- action: "add_domain",
+ action: list === "audit" ? "add_audit" : "add_domain",
comment: "Added from Audit Log"
},
success: function () {
diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php
index 04a9030c3..04871d177 100644
--- a/scripts/pi-hole/php/groups.php
+++ b/scripts/pi-hole/php/groups.php
@@ -893,6 +893,53 @@ function JSON_error($message = null)
} catch (\Exception $ex) {
JSON_error($ex->getMessage());
}
+} elseif ($_POST['action'] == 'add_audit') {
+ // Add new domain
+ try {
+ $domains = explode(' ', html_entity_decode(trim($_POST['domain'])));
+ $before = intval($db->querySingle("SELECT COUNT(*) FROM domain_audit;"));
+ $total = count($domains);
+ $added = 0;
+ $stmt = $db->prepare('REPLACE INTO domain_audit (domain) VALUES (:domain)');
+ if (!$stmt) {
+ throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
+ }
+
+ foreach ($domains as $domain) {
+ $input = $domain;
+
+ if (!$stmt->bindValue(':domain', $domain, SQLITE3_TEXT)) {
+ throw new Exception('While binding domain: ' . $db->lastErrorMsg() . ' '.
+ 'Added ' . $added . " out of ". $total . " domains");
+ }
+
+ if (!$stmt->execute()) {
+ throw new Exception('While executing: ' . $db->lastErrorMsg() . ' '.
+ 'Added ' . $added . " out of ". $total . " domains");
+ }
+ $added++;
+ }
+
+ $after = intval($db->querySingle("SELECT COUNT(*) FROM domain_audit;"));
+ $difference = $after - $before;
+ if($total === 1) {
+ if($difference !== 1) {
+ $msg = "Not adding ". htmlentities(utf8_encode($domain)) . " as it is already on the list";
+ } else {
+ $msg = "Added " . htmlentities(utf8_encode($domain));
+ }
+ } else {
+ if($difference !== $total) {
+ $msg = "Added " . ($after-$before) . " out of ". $total . " domains (skipped duplicates)";
+ } else {
+ $msg = "Added " . $total . " domains";
+ }
+ }
+ $reload = true;
+ JSON_success($msg);
+ } catch (\Exception $ex) {
+ JSON_error($ex->getMessage());
+ }
} else {
log_and_die('Requested action not supported!');
}
From d6477926552cb5a1a10b83f8e816194e33b84b9a Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Mon, 20 Jul 2020 22:27:40 +0200
Subject: [PATCH 6/9] Fix query types links on the dashboard (Query Types pie
chart)
Signed-off-by: DL6ER
---
scripts/pi-hole/js/index.js | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js
index 7f587f2e1..5c056fbc6 100644
--- a/scripts/pi-hole/js/index.js
+++ b/scripts/pi-hole/js/index.js
@@ -287,6 +287,7 @@ function updateQueriesOverTime() {
});
}
+var querytypeids = [];
function updateQueryTypesPie() {
$.getJSON("api.php?getQueryTypes", function (data) {
if ("FTLnotrunning" in data) {
@@ -305,12 +306,16 @@ function updateQueryTypesPie() {
iter = data;
}
+ querytypeids = [];
Object.keys(iter).forEach(function (key) {
if (iter[key] > 0) {
v.push(iter[key]);
- c.push(THEME_COLORS[i++ % THEME_COLORS.length]);
+ c.push(THEME_COLORS[i % THEME_COLORS.length]);
k.push(key);
+ querytypeids.push(i + 1);
}
+
+ i++;
});
// Build a single dataset with the data to be pushed
@@ -342,7 +347,7 @@ function updateQueryTypesPie() {
ci.update();
} else if (e.which === 1) {
// which == 1 is left mouse button
- window.open("queries.php?querytype=" + ($(this).index() + 1), "_self");
+ window.open("queries.php?querytype=" + querytypeids[$(this).index()], "_self");
}
});
}).done(function () {
From 3fb2c2be1f0e8510286272561b34115914493b80 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sun, 2 Aug 2020 20:14:31 +0200
Subject: [PATCH 7/9] Allow multiple conditional forwarding fields
Signed-off-by: DL6ER
---
scripts/pi-hole/js/settings.js | 8 +-
scripts/pi-hole/php/savesettings.php | 91 +++++++++++------
settings.php | 142 ++++++++++++++++++---------
3 files changed, 159 insertions(+), 82 deletions(-)
diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js
index c50c7554e..28cb6ac31 100644
--- a/scripts/pi-hole/js/settings.js
+++ b/scripts/pi-hole/js/settings.js
@@ -247,10 +247,10 @@ $(function () {
// En-/disable conditional forwarding input fields based
// on the checkbox state
- $('input[name="rev_server"]').click(function () {
- $('input[name="rev_server_cidr"]').prop("disabled", !this.checked);
- $('input[name="rev_server_target"]').prop("disabled", !this.checked);
- $('input[name="rev_server_domain"]').prop("disabled", !this.checked);
+ $('input[name^="rev_server_chk"]').click(function () {
+ $('input[name^="rev_server_cidr"]').prop("disabled", !this.checked);
+ $('input[name^="rev_server_target"]').prop("disabled", !this.checked);
+ $('input[name^="rev_server_domain"]').prop("disabled", !this.checked);
});
});
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index af95c901b..f4f6a986e 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -6,6 +6,8 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
+$REV_SERVER_COUNT = 6;
+
if(!in_array(basename($_SERVER['SCRIPT_FILENAME']), ["settings.php", "teleporter.php"], true))
{
die("Direct access to this script is forbidden!");
@@ -349,38 +351,6 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
$extra .= "no-dnssec";
}
- // Check if rev-server is requested
- if(isset($_POST["rev_server"]))
- {
- // Validate CIDR IP
- $cidr = trim($_POST["rev_server_cidr"]);
- if (!validCIDRIP($cidr))
- {
- $error .= "Conditional forwarding subnet (\"".htmlspecialchars($cidr)."\") is invalid! ".
- "This field requires CIDR notation for local subnets (e.g., 192.168.0.0/16). ".
- "Please use only subnets /8, /16, /24, and /32. ";
- }
-
- // Validate target IP
- $target = trim($_POST["rev_server_target"]);
- if (!validIP($target))
- {
- $error .= "Conditional forwarding target IP (\"".htmlspecialchars($target)."\") is invalid! ";
- }
-
- // Validate conditional forwarding domain name (empty is okay)
- $domain = trim($_POST["rev_server_domain"]);
- if(strlen($domain) > 0 && !validDomain($domain))
- {
- $error .= "Conditional forwarding domain name (\"".htmlspecialchars($domain)."\") is invalid! ";
- }
-
- if(!$error)
- {
- $extra .= " rev-server ".$cidr." ".$target." ".$domain;
- }
- }
-
// Check if DNSinterface is set
if(isset($_POST["DNSinterface"]))
{
@@ -419,6 +389,63 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
break;
+ // Conditional forwarding
+ case "rev-server":
+ // Check if rev-server is requested
+ $extra = "";
+ if(isset($_POST["rev_server_chk"]))
+ {
+ // Loop over available fields
+ for($i = 0; $i < $REV_SERVER_COUNT; $i++)
+ {
+ // Get IP in CIDR notation
+ $cidr = trim($_POST["rev_server_cidr".$i]);
+
+ // Skip empty fields
+ if(strlen($cidr) == 0)
+ continue;
+
+ // Validate CIDR IP
+ if (!validCIDRIP($cidr))
+ {
+ $error .= "Conditional forwarding subnet (\"".htmlspecialchars($cidr)."\") is invalid! ".
+ "This field requires CIDR notation for local subnets (e.g., 192.168.0.0/16). ".
+ "Please use only subnets /8, /16, /24, and /32. ";
+ }
+
+ // Validate target IP
+ $target = trim($_POST["rev_server_target".$i]);
+ if (!validIP($target))
+ {
+ $error .= "Conditional forwarding target IP (\"".htmlspecialchars($target)."\") is invalid! ";
+ }
+
+ // Validate conditional forwarding domain name (empty is okay)
+ $domain = trim($_POST["rev_server_domain".$i]);
+ if(strlen($domain) > 0 && !validDomain($domain))
+ {
+ $error .= "Conditional forwarding domain name (\"".htmlspecialchars($domain)."\") is invalid! ";
+ }
+
+ if(!$error)
+ {
+ $extra .= " rev-server ".$cidr." ".$target." ".$domain;
+ }
+ }
+ }
+
+ // If there has been no error we can save the new settings
+ if(!strlen($error))
+ {
+ $return = pihole_execute("-a setrev ".$extra);
+ $success .= htmlspecialchars(end($return))." ";
+ $success .= "The conditional forwarding settings have been updated";
+ }
+ else
+ {
+ $error .= "The settings have been reset to their previous values";
+ }
+
// Set query logging
case "Logging":
diff --git a/settings.php b/settings.php
index 1d71de0ae..a13cc9294 100644
--- a/settings.php
+++ b/settings.php
@@ -9,7 +9,6 @@
require "scripts/pi-hole/php/savesettings.php";
require_once "scripts/pi-hole/php/FTL.php";
// Reread ini file as things might have been changed
-$setupVars = parse_ini_file("/etc/pihole/setupVars.conf");
$piholeFTLConf = piholeFTLConfig();
// Handling of PHP internal errors
@@ -164,14 +163,6 @@
} else {
$DNSinterface = "single";
}
-if (isset($setupVars["REV_SERVER"]) && ($setupVars["REV_SERVER"] == 1)) {
- $rev_server = true;
- $rev_server_cidr = $setupVars["REV_SERVER_CIDR"];
- $rev_server_target = $setupVars["REV_SERVER_TARGET"];
- $rev_server_domain = $setupVars["REV_SERVER_DOMAIN"];
-} else {
- $rev_server = false;
-}
?>
class="active">
" role="tab" data-toggle="tab">DNS
+ class="active">
+ " role="tab" data-toggle="tab">Conditional forwarding
+
class="active">
" role="tab" data-toggle="tab">DHCP
@@ -985,8 +979,64 @@ function convertseconds($argument)
the size of your log might increase significantly
when enabling DNSSEC. A DNSSEC resolver test can be found
here .
-
- Conditional forwarding
+
+
+
+
+
+
+ Save
+
+
+
+
+
+
+$rev_server = false;
+if (isset($setupVars["REV_SERVER"]) && ($setupVars["REV_SERVER"] == 1))
+ $rev_server = true;
+
+$rev_server_cidr = array();
+$rev_server_target = array();
+$rev_server_domain = array();
+for ($i = 0; $i < $REV_SERVER_COUNT; $i++)
+{
+ // 1st elements are "REV_SERVER_CIDR, REV_SERVER_TARGET, REV_SERVER_DOMAIN"
+ // 2nd elements are "REV_SERVER_CIDR2, REV_SERVER_TARGET2, REV_SERVER_DOMAIN2"
+ // 3rd elements are "REV_SERVER_CIDR3, REV_SERVER_TARGET3, REV_SERVER_DOMAIN3"
+ // etc. (for backwards-compatibility)
+ if($i == 0)
+ $extra = "";
+ else
+ $extra = $i + 1;
+
+ if(isset($setupVars["REV_SERVER_CIDR".$extra]))
+ array_push($rev_server_cidr, $setupVars["REV_SERVER_CIDR".$extra]);
+ else
+ array_push($rev_server_cidr, NULL);
+
+ if(isset($setupVars["REV_SERVER_TARGET".$extra]))
+ array_push($rev_server_target, $setupVars["REV_SERVER_TARGET".$extra]);
+ else
+ array_push($rev_server_target, NULL);
+
+ if(isset($setupVars["REV_SERVER_DOMAIN".$extra]))
+ array_push($rev_server_domain, $setupVars["REV_SERVER_DOMAIN".$extra]);
+ else
+ array_push($rev_server_domain, NULL);
+}
+?>
+
@@ -937,60 +940,9 @@ function convertseconds($argument)
-
-
-
-
-
-
-
-
- checked>
- Never forward non-FQDNs
-
-
-
checked>
-
Never forward reverse lookups for private IP ranges
-
Note that enabling these two options may increase your privacy
- slightly, but may also prevent you from being able to access
- local hostnames if the Pi-hole is not used as DHCP server
-
-
-
checked>
-
Use DNSSEC
-
Validate DNS replies and cache DNSSEC data. When forwarding DNS
- queries, Pi-hole requests the DNSSEC records needed to validate
- the replies. If a domain fails validation or the upstream does not
- support DNSSEC, this setting can cause issues resolving domains.
- Use Google, Cloudflare, DNS.WATCH, Quad9, or another DNS
- server which supports DNSSEC when activating DNSSEC. Note that
- the size of your log might increase significantly
- when enabling DNSSEC. A DNSSEC resolver test can be found
- here .
-
-
Validate DNS replies and cache DNSSEC data. When forwarding DNS
- queries, Pi-hole requests the DNSSEC records needed to validate
- the replies. If a domain fails validation or the upstream does not
- support DNSSEC, this setting can cause issues resolving domains.
- Use Google, Cloudflare, DNS.WATCH, Quad9, or another DNS
- server which supports DNSSEC when activating DNSSEC. Note that
- the size of your log might increase significantly
- when enabling DNSSEC. A DNSSEC resolver test can be found
- here .
-
-
-
-
-
-
-
Save
-
-
-
+
$rev_server = false;
if (isset($setupVars["REV_SERVER"]) && ($setupVars["REV_SERVER"] == 1))
@@ -1026,17 +978,54 @@ function convertseconds($argument)
array_push($rev_server_domain, NULL);
}
?>
-