From 373d59f7512badcecf3d80f787e4c8b39264e806 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 9 Apr 2020 09:03:50 +0200
Subject: [PATCH 01/49] Improve conditional forwarding settings so users can
specify the subnet according to their needs.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/settings.js | 34 +++++++++-------
scripts/pi-hole/php/savesettings.php | 53 +++++++++++++++++++-----
settings.php | 61 ++++++++++++++++++----------
3 files changed, 102 insertions(+), 46 deletions(-)
diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js
index 93974e5e..b4a1a10e 100644
--- a/scripts/pi-hole/js/settings.js
+++ b/scripts/pi-hole/js/settings.js
@@ -215,21 +215,8 @@ $(function() {
// DHCP leases tooltips
$(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip({ html: true, container: "body" });
-});
-// Change "?tab=" parameter in URL for save and reload
-$(".nav-tabs a").on("shown.bs.tab", function(e) {
- var tab = e.target.hash.substring(1);
- window.history.pushState("", "", "?tab=" + tab);
- if (tab === "piholedhcp") {
- window.location.reload();
- }
-
- window.scrollTo(0, 0);
-});
-
-// Auto dismissal for info notifications
-$(document).ready(function() {
+ // Auto dismissal for info notifications
var alInfo = $("#alInfo");
if (alInfo.length) {
alInfo.delay(3000).fadeOut(2000, function() {
@@ -243,4 +230,23 @@ $(document).ready(function() {
input.setAttribute("autocorrect", "off");
input.setAttribute("autocapitalize", "off");
input.setAttribute("spellcheck", false);
+
+ // 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);
+ });
+});
+
+// Change "?tab=" parameter in URL for save and reload
+$(".nav-tabs a").on("shown.bs.tab", function(e) {
+ var tab = e.target.hash.substring(1);
+ window.history.pushState("", "", "?tab=" + tab);
+ if (tab === "piholedhcp") {
+ window.location.reload();
+ }
+
+ window.scrollTo(0, 0);
});
diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php
index 6c8b1e89..ecad2bcf 100644
--- a/scripts/pi-hole/php/savesettings.php
+++ b/scripts/pi-hole/php/savesettings.php
@@ -19,6 +19,30 @@ function validIP($address){
return !filter_var($address, FILTER_VALIDATE_IP) === false;
}
+function validCIDRIP($address){
+ // This validation strategy has been taken from ../js/groups-common.js
+ $isIPv6 = strpos($address, ":") !== false;
+ if($isIPv6) {
+ // One IPv6 element is 16bit: 0000 - FFFF
+ $v6elem = "[0-9A-Fa-f]{1,4}";
+ // CIDR for IPv6 is any multiple of 4 from 4 up to 128 bit
+ $v6cidr = "(4";
+ for ($i=8; $i <= 128; $i+=4) {
+ $v6cidr .= "|$i";
+ }
+ $v6cidr .= ")";
+ $validator = "/^(((?:$v6elem))((?::$v6elem))*::((?:$v6elem))((?::$v6elem))*|((?:$v6elem))((?::$v6elem)){7})\/$v6cidr$/";
+ return preg_match($validator, $address);
+ } else {
+ // One IPv4 element is 8bit: 0 - 256
+ $v4elem = "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)";
+ // Note that rev-server accepts only /8, /16, /24, and /32
+ $allowedv4cidr = "(8|16|24|32)";
+ $validator = "/^$v4elem\.$v4elem\.$v4elem\.$v4elem\/$allowedv4cidr$/";
+ return preg_match($validator, $address);
+ }
+}
+
// Check for existance of variable
// and test it only if it exists
function istrue(&$argument) {
@@ -329,25 +353,32 @@ function addStaticDHCPLease($mac, $ip, $hostname) {
$extra .= "no-dnssec";
}
- // Check if Conditional Forwarding is requested
- if(isset($_POST["conditionalForwarding"]))
+ // Check if rev-server is requested
+ if(isset($_POST["rev_server"]))
{
- // Validate conditional forwarding IP
- if (!validIP($_POST["conditionalForwardingIP"]))
+ // Validate CIDR IP
+ if (!validCIDRIP($_POST["rev_server_cidr"]))
{
- $error .= "Conditional forwarding IP (".htmlspecialchars($_POST["conditionalForwardingIP"]).") is invalid! ";
+ $error .= "Conditional forwarding subnet (\"".htmlspecialchars($_POST["rev_server_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 conditional forwarding domain name
- if(!validDomain($_POST["conditionalForwardingDomain"]))
+ // Validate target IP
+ if (!validIP($_POST["rev_server_target"]))
{
- $error .= "Conditional forwarding domain name (".htmlspecialchars($_POST["conditionalForwardingDomain"]).") is invalid! ";
+ $error .= "Conditional forwarding target IP (\"".htmlspecialchars($_POST["rev_server_target"])."\") is invalid! ";
}
+
+ // Validate conditional forwarding domain name (empty is okay)
+ if(strlen($_POST["rev_server_domain"]) > 0 && !validDomain($_POST["rev_server_domain"]))
+ {
+ $error .= "Conditional forwarding domain name (\"".htmlspecialchars($_POST["rev_server_domain"])."\") is invalid! ";
+ }
+
if(!$error)
{
- $addressArray = explode(".", $_POST["conditionalForwardingIP"]);
- $reverseAddress = $addressArray[2].".".$addressArray[1].".".$addressArray[0].".in-addr.arpa";
- $extra .= " conditional_forwarding ".$_POST["conditionalForwardingIP"]." ".$_POST["conditionalForwardingDomain"]." $reverseAddress";
+ $extra .= " rev-server ".$_POST["rev_server_cidr"]." ".$_POST["rev_server_target"]." ".$_POST["rev_server_domain"];
}
}
diff --git a/settings.php b/settings.php
index 18826b59..f797dc27 100644
--- a/settings.php
+++ b/settings.php
@@ -164,12 +164,13 @@ if (isset($setupVars["DNSMASQ_LISTENING"])) {
} else {
$DNSinterface = "single";
}
-if (isset($setupVars["CONDITIONAL_FORWARDING"]) && ($setupVars["CONDITIONAL_FORWARDING"] == 1)) {
- $conditionalForwarding = true;
- $conditionalForwardingDomain = $setupVars["CONDITIONAL_FORWARDING_DOMAIN"];
- $conditionalForwardingIP = $setupVars["CONDITIONAL_FORWARDING_IP"];
+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 {
- $conditionalForwarding = false;
+ $rev_server = false;
}
?>
@@ -807,36 +808,54 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "blocklists"
the size of your log might increase significantly
when enabling DNSSEC. A DNSSEC resolver test can be found
here.
-
-
If not configured as your DHCP server, Pi-hole won't be able to
+
+
If not configured as your DHCP server, Pi-hole typically won't be able to
determine the names of devices on your local network. As a
result, tables such as Top Clients will only show IP addresses.
One solution for this is to configure Pi-hole to forward these
- requests to your DHCP server (most likely your router), but only for devices on your
- home network. To configure this we will need to know the IP
- address of your DHCP server and the name of your local network.
-
Note: The local domain name must match the domain name specified
- in your DHCP server, likely found within the DHCP settings.
+ requests to your DHCP server (most likely your router), but only for devices on your
+ home network. To configure this we will need to know the IP
+ address of your DHCP server and which addresses belong to your local network.
+ Exemplary inout is given below as placeholder in the text boxes (if empty).
+
If your local network spans 192.168.0.1 - 192.168.0.255, then you will have to input
+ 192.168.0.0/24. If your local network is 192.168.47.1 - 192.168.47.255, it will
+ be 192.168.47.0/24 and similar. If your network is larger, the CIDR has to be
+ different, for instance a range of 10.8.0.1 - 10.8.255.255 results in 10.8.0.0/16,
+ whereas an even wider network of 10.0.0.1 - 10.255.255.255 results in 10.0.0.0/8.
+ Feel free to reach out to us on our
+ Discourse forum
+ in case you need any assistance setting up local host name resolution for your particular system.
+
You can also specify a local domain name (like fritz.box) to ensure queries to
+ devices ending in your local domain name will not leave your network, however, this is optional.
+ The local domain name must match the domain name specified
+ in your DHCP server for this to work. You can likely find it within the DHCP settings.
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index ca0854e5..87450a7a 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -432,7 +432,7 @@ $(document).ready(function() {
}
console.log(event.ctrlKey);
api.column(1).search("^"+this.textContent+"$", true, true).draw();
- $("#resetButton").show();
+ showResetButton("query type", this.textContent);
}
});
api.$("td:eq(1)").hover(
@@ -458,7 +458,7 @@ $(document).ready(function() {
}
var domain = this.textContent.split("\n")[0];
api.column(2).search("^"+domain+"$", true, true).draw();
- $("#resetButton").show();
+ showResetButton("domain", domain);
}
});
api.$("td:eq(2)").hover(
@@ -484,7 +484,7 @@ $(document).ready(function() {
resetColumnsFilters();
}
api.column(3).search("^"+this.textContent+"$", true, true).draw();
- $("#resetButton").show();
+ showResetButton("client", this.textContent);
}
});
api.$("td:eq(3)").hover(
@@ -521,6 +521,7 @@ $(document).ready(function() {
$("#resetButton").click(function() {
resetColumnsFilters();
tableApi.draw();
+ $("#resetButton").text("");
$("#resetButton").hide();
});
@@ -543,5 +544,16 @@ function resetColumnsFilters(add_filters) {
tableApi.columns()[0].forEach(index => {
tableApi.column(index).search("", true, true);
});
- tableApi.draw();
+ $("#resetButton").text("");
+ tableApi.draw();
+}
+
+function showResetButton(type, param) {
+ let button = $("#resetButton");
+ if(button.text().length === 0) {
+ button.text("Clear filtering on "+type+" \""+param+"\"");
+ } else {
+ button.text(button.text() + "and "+type+" \""+param+"\"");
+ }
+ button.show();
}
From 8c82872f4a5fd2f32b2eafb35785412ae4a4cc94 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Tue, 21 Apr 2020 11:24:56 +0200
Subject: [PATCH 06/49] Add missing space in front of and on the dynamically
generated button text.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 87450a7a..b62e2811 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -430,7 +430,6 @@ $(document).ready(function() {
if(!event.ctrlKey) {
resetColumnsFilters();
}
- console.log(event.ctrlKey);
api.column(1).search("^"+this.textContent+"$", true, true).draw();
showResetButton("query type", this.textContent);
}
@@ -540,8 +539,8 @@ $(document).ready(function() {
});
});
-function resetColumnsFilters(add_filters) {
- tableApi.columns()[0].forEach(index => {
+function resetColumnsFilters() {
+ tableApi.columns()[0].forEach(function(index) {
tableApi.column(index).search("", true, true);
});
$("#resetButton").text("");
@@ -553,7 +552,7 @@ function showResetButton(type, param) {
if(button.text().length === 0) {
button.text("Clear filtering on "+type+" \""+param+"\"");
} else {
- button.text(button.text() + "and "+type+" \""+param+"\"");
+ button.text(button.text() + " and "+type+" \""+param+"\"");
}
button.show();
}
From 0aecefcbc8697e4da30c328bbb45029f7417ea03 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Tue, 21 Apr 2020 11:41:16 +0200
Subject: [PATCH 07/49] Add comments and simplify code
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index b62e2811..ef0d9209 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -519,9 +519,9 @@ $(document).ready(function() {
$("#resetButton").click(function() {
resetColumnsFilters();
+ hideResetButton();
+ // Trigger table update
tableApi.draw();
- $("#resetButton").text("");
- $("#resetButton").hide();
});
var chkbox_data = localStorage.getItem("query_log_filter_chkbox");
@@ -543,7 +543,9 @@ function resetColumnsFilters() {
tableApi.columns()[0].forEach(function(index) {
tableApi.column(index).search("", true, true);
});
- $("#resetButton").text("");
+ // Clear filter reset button
+ hideResetButton();
+ // Trigger table update
tableApi.draw();
}
@@ -556,3 +558,9 @@ function showResetButton(type, param) {
}
button.show();
}
+
+function hideResetButton() {
+ let button = $("#resetButton");
+ button.text("");
+ button.hide();
+}
From 2439c3c76a02235ca3fd88c56d784a8acf0eff38 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Tue, 21 Apr 2020 11:45:18 +0200
Subject: [PATCH 08/49] Add comment that holding down [Ctrl] can do something
magical
Signed-off-by: DL6ER
---
queries.php | 2 +-
scripts/pi-hole/js/queries.js | 39 +++++++++++++++++++++++------------
2 files changed, 27 insertions(+), 14 deletions(-)
diff --git a/queries.php b/queries.php
index 2a601e02..73185051 100644
--- a/queries.php
+++ b/queries.php
@@ -155,7 +155,7 @@ if(strlen($showing) > 0)
-
+
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index ef0d9209..c4b728ca 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -427,10 +427,14 @@ $(document).ready(function() {
// Query type IPv4 / IPv6
api.$("td:eq(1)").click(function(event) {
if (autofilter()) {
- if(!event.ctrlKey) {
+ if (!event.ctrlKey) {
resetColumnsFilters();
}
- api.column(1).search("^"+this.textContent+"$", true, true).draw();
+
+ api
+ .column(1)
+ .search("^" + this.textContent + "$", true, true)
+ .draw();
showResetButton("query type", this.textContent);
}
});
@@ -452,11 +456,15 @@ $(document).ready(function() {
// Domain
api.$("td:eq(2)").click(function(event) {
if (autofilter()) {
- if(!event.ctrlKey) {
+ if (!event.ctrlKey) {
resetColumnsFilters();
}
+
var domain = this.textContent.split("\n")[0];
- api.column(2).search("^"+domain+"$", true, true).draw();
+ api
+ .column(2)
+ .search("^" + domain + "$", true, true)
+ .draw();
showResetButton("domain", domain);
}
});
@@ -479,10 +487,14 @@ $(document).ready(function() {
// Client
api.$("td:eq(3)").click(function(event) {
if (autofilter()) {
- if(!event.ctrlKey) {
+ if (!event.ctrlKey) {
resetColumnsFilters();
}
- api.column(3).search("^"+this.textContent+"$", true, true).draw();
+
+ api
+ .column(3)
+ .search("^" + this.textContent + "$", true, true)
+ .draw();
showResetButton("client", this.textContent);
}
});
@@ -541,8 +553,8 @@ $(document).ready(function() {
function resetColumnsFilters() {
tableApi.columns()[0].forEach(function(index) {
- tableApi.column(index).search("", true, true);
- });
+ tableApi.column(index).search("", true, true);
+ });
// Clear filter reset button
hideResetButton();
// Trigger table update
@@ -550,17 +562,18 @@ function resetColumnsFilters() {
}
function showResetButton(type, param) {
- let button = $("#resetButton");
- if(button.text().length === 0) {
- button.text("Clear filtering on "+type+" \""+param+"\"");
+ var button = $("#resetButton");
+ if (button.text().length === 0) {
+ button.text("Clear filtering on " + type + ' "' + param + '"');
} else {
- button.text(button.text() + " and "+type+" \""+param+"\"");
+ button.text(button.text() + " and " + type + ' "' + param + '"');
}
+
button.show();
}
function hideResetButton() {
- let button = $("#resetButton");
+ var button = $("#resetButton");
button.text("");
button.hide();
}
From b74816d8f6b2b18c48669d4e21d13681ce8839b4 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 23 Apr 2020 08:41:37 +0200
Subject: [PATCH 09/49] Improve wording
Signed-off-by: DL6ER
---
queries.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/queries.php b/queries.php
index 73185051..6b25d703 100644
--- a/queries.php
+++ b/queries.php
@@ -155,7 +155,7 @@ if(strlen($showing) > 0)
-
+
From 728d9077803676bde31ddb4019d6dbc86b1b0843 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 23 Apr 2020 09:17:10 +0200
Subject: [PATCH 10/49] Add meta key modifier and highlight filtering columns
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 69 +++++++++++++++--------------------
1 file changed, 30 insertions(+), 39 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index c4b728ca..2b91d810 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -8,6 +8,7 @@
/* global moment:false */
var tableApi;
+var colHighlightColor = "#ffefad";
function add(domain, list) {
var token = $("#token").text();
@@ -426,17 +427,7 @@ $(document).ready(function() {
var api = this.api();
// Query type IPv4 / IPv6
api.$("td:eq(1)").click(function(event) {
- if (autofilter()) {
- if (!event.ctrlKey) {
- resetColumnsFilters();
- }
-
- api
- .column(1)
- .search("^" + this.textContent + "$", true, true)
- .draw();
- showResetButton("query type", this.textContent);
- }
+ addColumnFilter(event, 1, "query type", this.textContent);
});
api.$("td:eq(1)").hover(
function() {
@@ -455,18 +446,7 @@ $(document).ready(function() {
api.$("td:eq(1)").css("cursor", "pointer");
// Domain
api.$("td:eq(2)").click(function(event) {
- if (autofilter()) {
- if (!event.ctrlKey) {
- resetColumnsFilters();
- }
-
- var domain = this.textContent.split("\n")[0];
- api
- .column(2)
- .search("^" + domain + "$", true, true)
- .draw();
- showResetButton("domain", domain);
- }
+ addColumnFilter(event, 2, "domain", this.textContent.split("\n")[0]);
});
api.$("td:eq(2)").hover(
function() {
@@ -486,17 +466,7 @@ $(document).ready(function() {
api.$("td:eq(2)").css("cursor", "pointer");
// Client
api.$("td:eq(3)").click(function(event) {
- if (autofilter()) {
- if (!event.ctrlKey) {
- resetColumnsFilters();
- }
-
- api
- .column(3)
- .search("^" + this.textContent + "$", true, true)
- .draw();
- showResetButton("client", this.textContent);
- }
+ addColumnFilter(event, 3, "client", this.textContent);
});
api.$("td:eq(3)").hover(
function() {
@@ -516,9 +486,7 @@ $(document).ready(function() {
}
});
- // Initialize regex filter mode and clear search field (if set previously)
resetColumnsFilters();
- tableApi.search("", true, true).draw();
$("#all-queries tbody").on("click", "button", function() {
var data = tableApi.row($(this).parents("tr")).data();
@@ -531,9 +499,6 @@ $(document).ready(function() {
$("#resetButton").click(function() {
resetColumnsFilters();
- hideResetButton();
- // Trigger table update
- tableApi.draw();
});
var chkbox_data = localStorage.getItem("query_log_filter_chkbox");
@@ -551,10 +516,36 @@ $(document).ready(function() {
});
});
+function addColumnFilter(event, colID, colType, filterstring) {
+ if (!autofilter()) {
+ return;
+ }
+ // Do nothing in case of a requested multi-selection
+ if (!event.ctrlKey && !event.metaKey) {
+ resetColumnsFilters();
+ }
+
+ // Apply filtering
+ tableApi
+ .column(colID)
+ .search("^" + filterstring + "$", true, true)
+ .draw();
+
+ // Apply background color
+ tableApi
+ .$("td:eq(" + colID + ")")
+ .css("background-color", colHighlightColor);
+ showResetButton(colType, filterstring);
+}
+
function resetColumnsFilters() {
tableApi.columns()[0].forEach(function(index) {
tableApi.column(index).search("", true, true);
+ tableApi
+ .$("td:eq(" + index + ")")
+ .css("background-color", "#fff");
});
+
// Clear filter reset button
hideResetButton();
// Trigger table update
From c24900ddffa9e7b627ac9191d3b98e9f410944f5 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 23 Apr 2020 09:30:18 +0200
Subject: [PATCH 11/49] Reduce code duplication
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 47 ++++++++++++++++-------------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 2b91d810..97717785 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -425,58 +425,42 @@ $(document).ready(function() {
],
initComplete: function() {
var api = this.api();
+
// Query type IPv4 / IPv6
api.$("td:eq(1)").click(function(event) {
addColumnFilter(event, 1, "query type", this.textContent);
});
api.$("td:eq(1)").hover(
function() {
- if (autofilter()) {
- this.title = "Click to show only " + this.textContent + " queries";
- this.style.color = "#72afd2";
- } else {
- this.title = "";
- this.style.color = "";
- }
+ addFilteringHint(this, "with query type " + this.textContent);
},
function() {
this.style.color = "";
}
);
api.$("td:eq(1)").css("cursor", "pointer");
+
// Domain
api.$("td:eq(2)").click(function(event) {
addColumnFilter(event, 2, "domain", this.textContent.split("\n")[0]);
});
api.$("td:eq(2)").hover(
function() {
- if (autofilter()) {
- var domain = this.textContent.split("\n")[0];
- this.title = "Click to show only queries with domain " + domain;
- this.style.color = "#72afd2";
- } else {
- this.title = "";
- this.style.color = "";
- }
+ addFilteringHint(this, "with domain " + this.textContent);
},
function() {
this.style.color = "";
}
);
api.$("td:eq(2)").css("cursor", "pointer");
+
// Client
api.$("td:eq(3)").click(function(event) {
addColumnFilter(event, 3, "client", this.textContent);
});
api.$("td:eq(3)").hover(
function() {
- if (autofilter()) {
- this.title = "Click to show only queries made by " + this.textContent;
- this.style.color = "#72afd2";
- } else {
- this.title = "";
- this.style.color = "";
- }
+ addFilteringHint(this, "made by client " + this.textContent);
},
function() {
this.style.color = "";
@@ -516,10 +500,23 @@ $(document).ready(function() {
});
});
+function addFilteringHint(obj, text)
+{
+ if (autofilter()) {
+ obj.title = "Click to show only queries " + text;
+ obj.style.color = "#72afd2";
+ } else {
+ obj.title = "";
+ obj.style.color = "";
+ }
+}
+
function addColumnFilter(event, colID, colType, filterstring) {
+ // Do not filter anything when the checkbox is unticked
if (!autofilter()) {
return;
}
+
// Do nothing in case of a requested multi-selection
if (!event.ctrlKey && !event.metaKey) {
resetColumnsFilters();
@@ -532,8 +529,7 @@ function addColumnFilter(event, colID, colType, filterstring) {
.draw();
// Apply background color
- tableApi
- .$("td:eq(" + colID + ")")
+ tableApi.$("td:eq(" + colID + ")")
.css("background-color", colHighlightColor);
showResetButton(colType, filterstring);
}
@@ -541,8 +537,7 @@ function addColumnFilter(event, colID, colType, filterstring) {
function resetColumnsFilters() {
tableApi.columns()[0].forEach(function(index) {
tableApi.column(index).search("", true, true);
- tableApi
- .$("td:eq(" + index + ")")
+ tableApi.$("td:eq(" + index + ")")
.css("background-color", "#fff");
});
From 51064df4fd228392a494990260e8d66194e4b183 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 23 Apr 2020 09:34:06 +0200
Subject: [PATCH 12/49] Remove pointer cursor when auto-filtering is disabled.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 97717785..644656d5 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -436,9 +436,9 @@ $(document).ready(function() {
},
function() {
this.style.color = "";
+ this.style.cursor = "";
}
);
- api.$("td:eq(1)").css("cursor", "pointer");
// Domain
api.$("td:eq(2)").click(function(event) {
@@ -450,9 +450,9 @@ $(document).ready(function() {
},
function() {
this.style.color = "";
+ this.style.cursor = "";
}
);
- api.$("td:eq(2)").css("cursor", "pointer");
// Client
api.$("td:eq(3)").click(function(event) {
@@ -464,9 +464,9 @@ $(document).ready(function() {
},
function() {
this.style.color = "";
+ this.style.cursor = "";
}
);
- api.$("td:eq(3)").css("cursor", "pointer");
}
});
@@ -505,9 +505,11 @@ function addFilteringHint(obj, text)
if (autofilter()) {
obj.title = "Click to show only queries " + text;
obj.style.color = "#72afd2";
+ obj.style.cursor = "pointer";
} else {
obj.title = "";
obj.style.color = "";
+ obj.style.cursor = "";
}
}
From f8ca9d4173c6b35fc4fa0b2d19710d0973ded1d4 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 23 Apr 2020 16:21:04 +0200
Subject: [PATCH 13/49] Replace / by "or".
Signed-off-by: DL6ER
---
queries.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/queries.php b/queries.php
index 6b25d703..d7ea8cca 100644
--- a/queries.php
+++ b/queries.php
@@ -155,7 +155,7 @@ if(strlen($showing) > 0)
-
+
From 6f2a878371d3154bad417d8dc808feb89df1f962 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Fri, 24 Apr 2020 11:50:55 +0200
Subject: [PATCH 14/49] Store filtering columns in array instead of in a
string. This makes adding a column multiple times impossible.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 53 ++++++++++++++++++++++++-----------
1 file changed, 36 insertions(+), 17 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 644656d5..d4328708 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -9,6 +9,7 @@
var tableApi;
var colHighlightColor = "#ffefad";
+var tableFilters = [];
function add(domain, list) {
var token = $("#token").text();
@@ -397,6 +398,17 @@ $(document).ready(function() {
],
stateSave: true,
stateSaveCallback: function(settings, data) {
+ // Clear possible filtering settings
+ data.columns.forEach(function(value, index) {
+ data.columns[index].search.search = "";
+ });
+
+ // Always start on the first page to show most recent queries
+ data.start = 0;
+
+ // Always start with empty search field
+ data.search.search = "";
+
// Store current state in client's local storage area
localStorage.setItem("query_log_table", JSON.stringify(data));
},
@@ -409,10 +421,6 @@ $(document).ready(function() {
}
data = JSON.parse(data);
- // Always start on the first page to show most recent queries
- data.start = 0;
- // Always start with empty search field
- data.search.search = "";
// Apply loaded state to table
return data;
},
@@ -428,7 +436,7 @@ $(document).ready(function() {
// Query type IPv4 / IPv6
api.$("td:eq(1)").click(function(event) {
- addColumnFilter(event, 1, "query type", this.textContent);
+ addColumnFilter(event, 1, this.textContent);
});
api.$("td:eq(1)").hover(
function() {
@@ -442,7 +450,7 @@ $(document).ready(function() {
// Domain
api.$("td:eq(2)").click(function(event) {
- addColumnFilter(event, 2, "domain", this.textContent.split("\n")[0]);
+ addColumnFilter(event, 2, this.textContent.split("\n")[0]);
});
api.$("td:eq(2)").hover(
function() {
@@ -456,7 +464,7 @@ $(document).ready(function() {
// Client
api.$("td:eq(3)").click(function(event) {
- addColumnFilter(event, 3, "client", this.textContent);
+ addColumnFilter(event, 3, this.textContent);
});
api.$("td:eq(3)").hover(
function() {
@@ -513,7 +521,7 @@ function addFilteringHint(obj, text)
}
}
-function addColumnFilter(event, colID, colType, filterstring) {
+function addColumnFilter(event, colID, filterstring) {
// Do not filter anything when the checkbox is unticked
if (!autofilter()) {
return;
@@ -524,6 +532,8 @@ function addColumnFilter(event, colID, colType, filterstring) {
resetColumnsFilters();
}
+ tableFilters[colID] = filterstring;
+
// Apply filtering
tableApi
.column(colID)
@@ -533,11 +543,12 @@ function addColumnFilter(event, colID, colType, filterstring) {
// Apply background color
tableApi.$("td:eq(" + colID + ")")
.css("background-color", colHighlightColor);
- showResetButton(colType, filterstring);
+ showResetButton();
}
function resetColumnsFilters() {
- tableApi.columns()[0].forEach(function(index) {
+ tableFilters.forEach(function(value, index) {
+ tableFilters[index] = "";
tableApi.column(index).search("", true, true);
tableApi.$("td:eq(" + index + ")")
.css("background-color", "#fff");
@@ -549,14 +560,22 @@ function resetColumnsFilters() {
tableApi.draw();
}
-function showResetButton(type, param) {
- var button = $("#resetButton");
- if (button.text().length === 0) {
- button.text("Clear filtering on " + type + ' "' + param + '"');
- } else {
- button.text(button.text() + " and " + type + ' "' + param + '"');
- }
+var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
+function showResetButton() {
+ var button = $("#resetButton");
+ var text = "";
+ tableFilters.forEach(function(value, index) {
+ if (value.length > 0) {
+ if (text.length === 0) {
+ text = 'Clear filtering on ' + colTypes[index] + ' "' + value + '"';
+ } else {
+ text += ' and ' + colTypes[index] + ' "' + value + '"';
+ }
+ }
+ });
+
+ button.text(text);
button.show();
}
From fcd4751cb7ee29fdc2892f22b03a083e4b0247b3 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Fri, 24 Apr 2020 12:01:56 +0200
Subject: [PATCH 15/49] Implement selective undoing using the Shift key.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 67 ++++++++++++++++++++++-------------
1 file changed, 43 insertions(+), 24 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index d4328708..9bf65f94 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -508,8 +508,7 @@ $(document).ready(function() {
});
});
-function addFilteringHint(obj, text)
-{
+function addFilteringHint(obj, text) {
if (autofilter()) {
obj.title = "Click to show only queries " + text;
obj.style.color = "#72afd2";
@@ -527,35 +526,57 @@ function addColumnFilter(event, colID, filterstring) {
return;
}
- // Do nothing in case of a requested multi-selection
- if (!event.ctrlKey && !event.metaKey) {
+ // Reset other columns when NOT requesting multi-selection functions
+ if (!event.ctrlKey && !event.metaKey && !event.shiftKey) {
resetColumnsFilters();
}
+ if (event.shiftKey) {
+ filterstring = "";
+ }
+
tableFilters[colID] = filterstring;
- // Apply filtering
- tableApi
- .column(colID)
- .search("^" + filterstring + "$", true, true)
- .draw();
-
- // Apply background color
- tableApi.$("td:eq(" + colID + ")")
- .css("background-color", colHighlightColor);
- showResetButton();
+ applyColumnFiltering();
}
function resetColumnsFilters() {
tableFilters.forEach(function(value, index) {
tableFilters[index] = "";
- tableApi.column(index).search("", true, true);
- tableApi.$("td:eq(" + index + ")")
- .css("background-color", "#fff");
});
// Clear filter reset button
- hideResetButton();
+ applyColumnFiltering();
+}
+
+function applyColumnFiltering() {
+ var showReset = false;
+ tableFilters.forEach(function(value, index) {
+ // Prepare regex filter string
+ var regex = "";
+ if (value.length > 0) {
+ regex = "^" + value + "$";
+
+ // Add background color
+ tableApi.$("td:eq(" + index + ")").css("background-color", colHighlightColor);
+
+ // Remember to show reset button
+ showReset = true;
+ } else {
+ // Clear background color
+ tableApi.$("td:eq(" + index + ")").css("background-color", "#fff");
+ }
+
+ // Apply filtering on this column (regex may be empty -> no filtering)
+ tableApi.column(index).search(regex, true, true);
+ });
+
+ if (showReset) {
+ showResetButton();
+ } else {
+ hideResetButton();
+ }
+
// Trigger table update
tableApi.draw();
}
@@ -566,12 +587,10 @@ function showResetButton() {
var button = $("#resetButton");
var text = "";
tableFilters.forEach(function(value, index) {
- if (value.length > 0) {
- if (text.length === 0) {
- text = 'Clear filtering on ' + colTypes[index] + ' "' + value + '"';
- } else {
- text += ' and ' + colTypes[index] + ' "' + value + '"';
- }
+ if (value.length > 0 && text.length === 0) {
+ text = "Clear filtering on " + colTypes[index] + ' "' + value + '"';
+ } else if (value.length > 0) {
+ text += " and " + colTypes[index] + ' "' + value + '"';
}
});
From 82f4549219cd0686e8bf660dd62d9fedd3426a88 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sat, 25 Apr 2020 06:22:17 +0200
Subject: [PATCH 16/49] Add filtering on status column.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 59 +++++++++++++++++++++++++++++++++--
1 file changed, 57 insertions(+), 2 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 9bf65f94..e96da742 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -270,6 +270,8 @@ $(document).ready(function() {
buttontext = "";
}
+ fieldtext += '';
+
$(row).addClass(colorClass);
$("td:eq(4)", row).html(fieldtext);
$("td:eq(6)", row).html(buttontext);
@@ -302,7 +304,8 @@ $(document).ready(function() {
}
// Check for existence of sixth column and display only if not Pi-holed
- var replytext;
+ var replytext,
+ replyid = -1;
if (data.length > 6 && !blocked) {
switch (data[6]) {
case "0":
@@ -341,10 +344,14 @@ $(document).ready(function() {
default:
replytext = "? (" + parseInt(data[6]) + ")";
}
+
+ replyid = parseInt(data[6]);
} else {
replytext = "-";
}
+ replytext += '';
+
$("td:eq(5)", row).addClass("text-black");
$("td:eq(5)", row).html(replytext);
@@ -475,6 +482,39 @@ $(document).ready(function() {
this.style.cursor = "";
}
);
+
+ // Status
+ api.$("td:eq(4)").click(function(event) {
+ var id = this.children.id.value;
+ var text = this.textContent;
+ addColumnFilter(event, 4, id + "#" + text);
+ });
+ api.$("td:eq(4)").hover(
+ function() {
+ addFilteringHint(this, "with status " + this.textContent);
+ },
+ function() {
+ this.style.color = "";
+ this.style.cursor = "";
+ }
+ );
+ /*
+ // Reply type
+ api.$("td:eq(5)").click(function(event) {
+ var id = this.children.id.value;
+ var text = this.textContent.split(" ")[0];
+ // Column 5 is DNSSEC status data
+ addColumnFilter(event, 6, id + "#" + text);
+ });
+ api.$("td:eq(5)").hover(
+ function() {
+ addFilteringHint(this, "with reply type " + this.textContent);
+ },
+ function() {
+ this.style.color = "";
+ this.style.cursor = "";
+ }
+ );*/
}
});
@@ -554,7 +594,15 @@ function applyColumnFiltering() {
tableFilters.forEach(function(value, index) {
// Prepare regex filter string
var regex = "";
+
+ // Split filter string if we received a combined ID#Name column
+ var valArr = value.split("#");
+ if (valArr.length > 0) {
+ value = valArr[0];
+ }
+
if (value.length > 0) {
+ // Exact matching
regex = "^" + value + "$";
// Add background color
@@ -581,12 +629,19 @@ function applyColumnFiltering() {
tableApi.draw();
}
-var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
+var colTypes = ["time", "query type", "domain", "client", "status", "DNSSEC reply", "reply type"];
function showResetButton() {
var button = $("#resetButton");
var text = "";
tableFilters.forEach(function(value, index) {
+ // Split filter string if we received a combined ID#Name column
+ var valArr = value.split("#");
+ if (valArr.length > 1) {
+ value = valArr[1];
+ }
+
+ // Create or add to button text
if (value.length > 0 && text.length === 0) {
text = "Clear filtering on " + colTypes[index] + ' "' + value + '"';
} else if (value.length > 0) {
From 1466ecd486c18afe32a4a4329906151676f4c89f Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sat, 25 Apr 2020 15:04:09 +0200
Subject: [PATCH 17/49] Add reply type filtering.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index e96da742..d646f5d8 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -146,7 +146,7 @@ $(document).ready(function() {
rowCallback: function(row, data) {
// DNSSEC status
var dnssec_status;
- switch (data[5]) {
+ switch (data[6]) {
case "1":
dnssec_status = ' SECURE';
break;
@@ -306,8 +306,8 @@ $(document).ready(function() {
// Check for existence of sixth column and display only if not Pi-holed
var replytext,
replyid = -1;
- if (data.length > 6 && !blocked) {
- switch (data[6]) {
+ if (!blocked) {
+ switch (data[5]) {
case "0":
replytext = "N/A";
break;
@@ -345,7 +345,7 @@ $(document).ready(function() {
replytext = "? (" + parseInt(data[6]) + ")";
}
- replyid = parseInt(data[6]);
+ replyid = parseInt(data[5]);
} else {
replytext = "-";
}
@@ -372,6 +372,10 @@ $(document).ready(function() {
var dataIndex = 0;
return data.data.map(function(x) {
x[0] = x[0] * 1e6 + dataIndex++;
+ var dnssec = x[5];
+ var reply = x[6];
+ x[5] = reply;
+ x[6] = dnssec;
return x;
});
}
@@ -498,13 +502,12 @@ $(document).ready(function() {
this.style.cursor = "";
}
);
- /*
+
// Reply type
api.$("td:eq(5)").click(function(event) {
var id = this.children.id.value;
var text = this.textContent.split(" ")[0];
- // Column 5 is DNSSEC status data
- addColumnFilter(event, 6, id + "#" + text);
+ addColumnFilter(event, 5, id + "#" + text);
});
api.$("td:eq(5)").hover(
function() {
@@ -514,7 +517,7 @@ $(document).ready(function() {
this.style.color = "";
this.style.cursor = "";
}
- );*/
+ );
}
});
From 4d9409e7082bb50f69254ea98b9101bc5c828974 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sat, 25 Apr 2020 15:05:47 +0200
Subject: [PATCH 18/49] Apply filtering events only on Ctrl/Command/Shift +
Click.
Signed-off-by: DL6ER
---
queries.php | 2 +-
scripts/pi-hole/js/queries.js | 166 ++++++++--------------------------
2 files changed, 41 insertions(+), 127 deletions(-)
diff --git a/queries.php b/queries.php
index d7ea8cca..c123fb5b 100644
--- a/queries.php
+++ b/queries.php
@@ -155,7 +155,7 @@ if(strlen($showing) > 0)
-
+
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index d646f5d8..93e7344b 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -109,10 +109,6 @@ function handleAjaxError(xhr, textStatus) {
tableApi.draw();
}
-function autofilter() {
- return $("#autofilter").prop("checked");
-}
-
$(document).ready(function() {
// Do we want to filter queries?
var GETDict = {};
@@ -305,49 +301,43 @@ $(document).ready(function() {
// Check for existence of sixth column and display only if not Pi-holed
var replytext,
- replyid = -1;
- if (!blocked) {
- switch (data[5]) {
- case "0":
- replytext = "N/A";
- break;
- case "1":
- replytext = "NODATA";
- break;
- case "2":
- replytext = "NXDOMAIN";
- break;
- case "3":
- replytext = "CNAME";
- break;
- case "4":
- replytext = "IP";
- break;
- case "5":
- replytext = "DOMAIN";
- break;
- case "6":
- replytext = "RRNAME";
- break;
- case "7":
- replytext = "SERVFAIL";
- break;
- case "8":
- replytext = "REFUSED";
- break;
- case "9":
- replytext = "NOTIMP";
- break;
- case "10":
- replytext = "upstream error";
- break;
- default:
- replytext = "? (" + parseInt(data[6]) + ")";
- }
-
- replyid = parseInt(data[5]);
- } else {
- replytext = "-";
+ replyid = parseInt(data[5]);;
+ switch (replyid) {
+ case 0:
+ replytext = "N/A";
+ break;
+ case 1:
+ replytext = "NODATA";
+ break;
+ case 2:
+ replytext = "NXDOMAIN";
+ break;
+ case 3:
+ replytext = "CNAME";
+ break;
+ case 4:
+ replytext = "IP";
+ break;
+ case 5:
+ replytext = "DOMAIN";
+ break;
+ case 6:
+ replytext = "RRNAME";
+ break;
+ case 7:
+ replytext = "SERVFAIL";
+ break;
+ case 8:
+ replytext = "REFUSED";
+ break;
+ case 9:
+ replytext = "NOTIMP";
+ break;
+ case 10:
+ replytext = "upstream error";
+ break;
+ default:
+ replytext = "? (" +data[5] + ")";
}
replytext += '';
@@ -449,43 +439,16 @@ $(document).ready(function() {
api.$("td:eq(1)").click(function(event) {
addColumnFilter(event, 1, this.textContent);
});
- api.$("td:eq(1)").hover(
- function() {
- addFilteringHint(this, "with query type " + this.textContent);
- },
- function() {
- this.style.color = "";
- this.style.cursor = "";
- }
- );
// Domain
api.$("td:eq(2)").click(function(event) {
addColumnFilter(event, 2, this.textContent.split("\n")[0]);
});
- api.$("td:eq(2)").hover(
- function() {
- addFilteringHint(this, "with domain " + this.textContent);
- },
- function() {
- this.style.color = "";
- this.style.cursor = "";
- }
- );
// Client
api.$("td:eq(3)").click(function(event) {
addColumnFilter(event, 3, this.textContent);
});
- api.$("td:eq(3)").hover(
- function() {
- addFilteringHint(this, "made by client " + this.textContent);
- },
- function() {
- this.style.color = "";
- this.style.cursor = "";
- }
- );
// Status
api.$("td:eq(4)").click(function(event) {
@@ -493,15 +456,6 @@ $(document).ready(function() {
var text = this.textContent;
addColumnFilter(event, 4, id + "#" + text);
});
- api.$("td:eq(4)").hover(
- function() {
- addFilteringHint(this, "with status " + this.textContent);
- },
- function() {
- this.style.color = "";
- this.style.cursor = "";
- }
- );
// Reply type
api.$("td:eq(5)").click(function(event) {
@@ -509,15 +463,6 @@ $(document).ready(function() {
var text = this.textContent.split(" ")[0];
addColumnFilter(event, 5, id + "#" + text);
});
- api.$("td:eq(5)").hover(
- function() {
- addFilteringHint(this, "with reply type " + this.textContent);
- },
- function() {
- this.style.color = "";
- this.style.cursor = "";
- }
- );
}
});
@@ -535,43 +480,12 @@ $(document).ready(function() {
$("#resetButton").click(function() {
resetColumnsFilters();
});
-
- var chkbox_data = localStorage.getItem("query_log_filter_chkbox");
- if (chkbox_data !== null) {
- // Restore checkbox state
- $("#autofilter").prop("checked", chkbox_data === "true");
- } else {
- // Initialize checkbox
- $("#autofilter").prop("checked", true);
- localStorage.setItem("query_log_filter_chkbox", true);
- }
-
- $("#autofilter").click(function() {
- localStorage.setItem("query_log_filter_chkbox", $("#autofilter").prop("checked"));
- });
});
-function addFilteringHint(obj, text) {
- if (autofilter()) {
- obj.title = "Click to show only queries " + text;
- obj.style.color = "#72afd2";
- obj.style.cursor = "pointer";
- } else {
- obj.title = "";
- obj.style.color = "";
- obj.style.cursor = "";
- }
-}
-
function addColumnFilter(event, colID, filterstring) {
- // Do not filter anything when the checkbox is unticked
- if (!autofilter()) {
- return;
- }
-
- // Reset other columns when NOT requesting multi-selection functions
+ // Don't do anything when NOT explicitly requesting multi-selection functions
if (!event.ctrlKey && !event.metaKey && !event.shiftKey) {
- resetColumnsFilters();
+ return;
}
if (event.shiftKey) {
@@ -632,7 +546,7 @@ function applyColumnFiltering() {
tableApi.draw();
}
-var colTypes = ["time", "query type", "domain", "client", "status", "DNSSEC reply", "reply type"];
+var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
function showResetButton() {
var button = $("#resetButton");
From cb3be64a23a993f5286a505e045f7161bcb044a7 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sun, 26 Apr 2020 09:50:56 +0200
Subject: [PATCH 19/49] Simply reply type code.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 75 ++++++++++-------------------------
1 file changed, 22 insertions(+), 53 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 93e7344b..bfdea4e8 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -11,6 +11,21 @@ var tableApi;
var colHighlightColor = "#ffefad";
var tableFilters = [];
+var replyTypes = [
+ "N/A",
+ "NODATA",
+ "NXDOMAIN",
+ "CNAME",
+ "IP",
+ "DOMAIN",
+ "RRNAME",
+ "SERVFAIL",
+ "REFUSED",
+ "NOTIMP",
+ "upstream error"
+];
+var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
+
function add(domain, list) {
var token = $("#token").text();
var alertModal = $("#alertModal");
@@ -164,8 +179,7 @@ $(document).ready(function() {
}
// Query status
- var blocked,
- fieldtext,
+ var fieldtext,
buttontext,
colorClass,
isCNAME = false,
@@ -173,28 +187,24 @@ $(document).ready(function() {
switch (data[4]) {
case "1":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (gravity)";
buttontext =
'';
break;
case "2":
- blocked = false;
colorClass = "text-green";
fieldtext = "OK (forwarded)" + dnssec_status;
buttontext =
'';
break;
case "3":
- blocked = false;
colorClass = "text-green";
fieldtext = "OK (cached)" + dnssec_status;
buttontext =
'';
break;
case "4":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (regex blacklist)";
@@ -206,32 +216,27 @@ $(document).ready(function() {
'';
break;
case "5":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (exact blacklist)";
buttontext =
'';
break;
case "6":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (external, IP)";
buttontext = "";
break;
case "7":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (external, NULL)";
buttontext = "";
break;
case "8":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (external, NXRA)";
buttontext = "";
break;
case "9":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (gravity, CNAME)";
buttontext =
@@ -239,7 +244,6 @@ $(document).ready(function() {
isCNAME = true;
break;
case "10":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (regex blacklist, CNAME)";
@@ -252,7 +256,6 @@ $(document).ready(function() {
isCNAME = true;
break;
case "11":
- blocked = true;
colorClass = "text-red";
fieldtext = "Blocked (exact blacklist, CNAME)";
buttontext =
@@ -260,7 +263,6 @@ $(document).ready(function() {
isCNAME = true;
break;
default:
- blocked = false;
colorClass = "text-black";
fieldtext = "Unknown (" + parseInt(data[4]) + ")";
buttontext = "";
@@ -301,43 +303,12 @@ $(document).ready(function() {
// Check for existence of sixth column and display only if not Pi-holed
var replytext,
- replyid = parseInt(data[5]);;
- switch (replyid) {
- case 0:
- replytext = "N/A";
- break;
- case 1:
- replytext = "NODATA";
- break;
- case 2:
- replytext = "NXDOMAIN";
- break;
- case 3:
- replytext = "CNAME";
- break;
- case 4:
- replytext = "IP";
- break;
- case 5:
- replytext = "DOMAIN";
- break;
- case 6:
- replytext = "RRNAME";
- break;
- case 7:
- replytext = "SERVFAIL";
- break;
- case 8:
- replytext = "REFUSED";
- break;
- case 9:
- replytext = "NOTIMP";
- break;
- case 10:
- replytext = "upstream error";
- break;
- default:
- replytext = "? (" +data[5] + ")";
+ replyid = parseInt(data[5]);
+
+ if (replyid >= 0 && replyid < replyTypes.length) {
+ replytext = replyTypes[replyid];
+ } else {
+ replytext = "? (" + replyid + ")";
}
replytext += '';
@@ -546,8 +517,6 @@ function applyColumnFiltering() {
tableApi.draw();
}
-var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
-
function showResetButton() {
var button = $("#resetButton");
var text = "";
From 6c2685229564b01fb598ff6da35f49889e171d6e Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Sun, 26 Apr 2020 21:37:51 +0000
Subject: [PATCH 20/49] Use classes for highlighting to ensure the alternate
row colors are not lost when removing a column from the selection.
Signed-off-by: DL6ER
---
queries.php | 7 +++++--
scripts/pi-hole/js/queries.js | 5 ++---
style/pi-hole.css | 6 +++++-
3 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/queries.php b/queries.php
index c123fb5b..e73daf4e 100644
--- a/queries.php
+++ b/queries.php
@@ -155,8 +155,11 @@ if(strlen($showing) > 0)
-
-
+
+
+
Use Ctrl or ⌘ + to add columns to the current filter
+
Use Shift + to remove columns to the current filter
+
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index bfdea4e8..e48eeee3 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -8,7 +8,6 @@
/* global moment:false */
var tableApi;
-var colHighlightColor = "#ffefad";
var tableFilters = [];
var replyTypes = [
@@ -494,13 +493,13 @@ function applyColumnFiltering() {
regex = "^" + value + "$";
// Add background color
- tableApi.$("td:eq(" + index + ")").css("background-color", colHighlightColor);
+ tableApi.$("td:eq(" + index + ")").addClass("filter-highlight");
// Remember to show reset button
showReset = true;
} else {
// Clear background color
- tableApi.$("td:eq(" + index + ")").css("background-color", "#fff");
+ tableApi.$("td:eq(" + index + ")").removeClass("filter-highlight");
}
// Apply filtering on this column (regex may be empty -> no filtering)
diff --git a/style/pi-hole.css b/style/pi-hole.css
index 08ee7abb..67de6bcd 100644
--- a/style/pi-hole.css
+++ b/style/pi-hole.css
@@ -265,4 +265,8 @@ code.breakall
.bootstrap-select.bs-container.align-right {
left: unset !important;
right: 10px;
-}
\ No newline at end of file
+}
+
+.filter-highlight {
+ background-color: #ffcc0050;
+}
From c463e15ba6d72b24e2b6da3b65674580564d63c9 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Tue, 28 Apr 2020 17:55:41 +0000
Subject: [PATCH 21/49] Fix wording
Signed-off-by: DL6ER
---
queries.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/queries.php b/queries.php
index e73daf4e..6623c1fc 100644
--- a/queries.php
+++ b/queries.php
@@ -158,7 +158,7 @@ if(strlen($showing) > 0)
Use Ctrl or ⌘ + to add columns to the current filter
-
Use Shift + to remove columns to the current filter
+
Use Shift + to remove columns from the current filter
From 5971707263c91c229b4caf32c89f3c0e2982b193 Mon Sep 17 00:00:00 2001
From: Willem Stuursma-Ruwen
Date: Sun, 10 May 2020 21:15:48 +0200
Subject: [PATCH 22/49] Fixes #1227 Fix possible warning when unlinking files
Signed-off-by: Willem Stuursma-Ruwen
---
api.php | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/api.php b/api.php
index e06a43a7..15023dbf 100644
--- a/api.php
+++ b/api.php
@@ -52,7 +52,8 @@ elseif (isset($_GET['enable']) && $auth)
}
pihole_execute('enable');
$data = array_merge($data, array("status" => "enabled"));
- unlink("../custom_disable_timer");
+ // Silence errors if there is a race condition with the timer
+ @unlink("../custom_disable_timer");
}
elseif (isset($_GET['disable']) && $auth)
{
@@ -77,7 +78,8 @@ elseif (isset($_GET['disable']) && $auth)
else
{
pihole_execute('disable');
- unlink("../custom_disable_timer");
+ // Silence errors if there is a race condition with the timer
+ @unlink("../custom_disable_timer");
}
$data = array_merge($data, array("status" => "disabled"));
}
From 55ab4f179f4ffde7f0325cc4373f5b9a8a53c312 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Wed, 3 Jun 2020 15:36:06 +0200
Subject: [PATCH 23/49] Minor style changes for the dark theme.
Signed-off-by: DL6ER
---
queries.php | 2 +-
scripts/pi-hole/js/queries.js | 5 ++---
style/pi-hole.css | 9 ---------
3 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/queries.php b/queries.php
index 37820e43..8915514e 100644
--- a/queries.php
+++ b/queries.php
@@ -142,7 +142,7 @@ if(strlen($showing) > 0)
Use Ctrl or ⌘ + to add columns to the current filter
Use Shift + to remove columns from the current filter
-
+
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 9e1b118b..76126c6f 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -318,7 +318,6 @@ $(function () {
replytext += '';
- $("td:eq(5)", row).addClass("text-black");
$("td:eq(5)", row).html(replytext);
if (data.length > 7) {
@@ -488,13 +487,13 @@ function applyColumnFiltering() {
regex = "^" + value + "$";
// Add background color
- tableApi.$("td:eq(" + index + ")").addClass("filter-highlight");
+ tableApi.$("td:eq(" + index + ")").addClass("highlight");
// Remember to show reset button
showReset = true;
} else {
// Clear background color
- tableApi.$("td:eq(" + index + ")").removeClass("filter-highlight");
+ tableApi.$("td:eq(" + index + ")").removeClass("highlight");
}
// Apply filtering on this column (regex may be empty -> no filtering)
diff --git a/style/pi-hole.css b/style/pi-hole.css
index 2588c5b5..36a9d4e5 100644
--- a/style/pi-hole.css
+++ b/style/pi-hole.css
@@ -295,15 +295,6 @@
font-family: inherit;
}
-.bootstrap-select.bs-container.align-right {
- left: unset !important;
- right: 10px;
-}
-
-.filter-highlight {
- background-color: #ffcc0050;
-}
-
.form-inline .form-control {
display: inline-block;
width: 100%;
From 700b575c093d39a9f4577edac6a19e1a25a26eac Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 09:26:53 +0200
Subject: [PATCH 24/49] Add note that IPv6 is supported as well.
Signed-off-by: DL6ER
---
settings.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/settings.php b/settings.php
index 0551edc3..30214b4a 100644
--- a/settings.php
+++ b/settings.php
@@ -999,6 +999,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "
be 192.168.47.0/24 and similar. If your network is larger, the CIDR has to be
different, for instance a range of 10.8.0.1 - 10.8.255.255 results in 10.8.0.0/16,
whereas an even wider network of 10.0.0.1 - 10.255.255.255 results in 10.0.0.0/8.
+ Setting up IPv6 ranges is exactly similar to setting up IPv4 here and fully supported.
Feel free to reach out to us on our
Discourse forum
in case you need any assistance setting up local host name resolution for your particular system.
From 68e03df011b6b5924dc45f1d7ded78e1b824c699 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 09:44:22 +0200
Subject: [PATCH 25/49] Simplify button by removing the description of what we
are filtering.
Signed-off-by: DL6ER
---
queries.php | 2 +-
scripts/pi-hole/js/queries.js | 36 +++--------------------------------
2 files changed, 4 insertions(+), 34 deletions(-)
diff --git a/queries.php b/queries.php
index 8915514e..be203c49 100644
--- a/queries.php
+++ b/queries.php
@@ -142,7 +142,7 @@ if(strlen($showing) > 0)
Use Ctrl or ⌘ + to add columns to the current filter
Use Shift + to remove columns from the current filter
-
+
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 76126c6f..a45e2fec 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -23,7 +23,6 @@ var replyTypes = [
"NOTIMP",
"upstream error"
];
-var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
function add(domain, list) {
var token = $("#token").text();
@@ -176,7 +175,7 @@ $(function () {
// Query status
var fieldtext,
buttontext,
- colorClass,
+ colorClass = false,
isCNAME = false,
regexLink = false;
@@ -258,7 +257,6 @@ $(function () {
isCNAME = true;
break;
default:
- colorClass = false;
fieldtext = "Unknown (" + parseInt(data[4]) + ")";
buttontext = "";
}
@@ -501,39 +499,11 @@ function applyColumnFiltering() {
});
if (showReset) {
- showResetButton();
+ $("#resetButton").removeClass("hidden");
} else {
- hideResetButton();
+ $("#resetButton").addClass("hidden");
}
// Trigger table update
tableApi.draw();
}
-
-function showResetButton() {
- var button = $("#resetButton");
- var text = "";
- tableFilters.forEach(function (value, index) {
- // Split filter string if we received a combined ID#Name column
- var valArr = value.split("#");
- if (valArr.length > 1) {
- value = valArr[1];
- }
-
- // Create or add to button text
- if (value.length > 0 && text.length === 0) {
- text = "Clear filtering on " + colTypes[index] + ' "' + value + '"';
- } else if (value.length > 0) {
- text += " and " + colTypes[index] + ' "' + value + '"';
- }
- });
-
- button.text(text);
- button.removeClass("hidden");
-}
-
-function hideResetButton() {
- var button = $("#resetButton");
- button.text("");
- button.addClass("hidden");
-}
From e357a925b5aacf771e88d11b71b9951b3c65e229 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 10:08:13 +0200
Subject: [PATCH 26/49] Add tooltip and click cursor to enhance accessibility
of the click filtering feature.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 102 +++++++++++++++++++++++++++-------
1 file changed, 83 insertions(+), 19 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index a45e2fec..4e0a292b 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -23,6 +23,7 @@ var replyTypes = [
"NOTIMP",
"upstream error"
];
+var colTypes = ["time", "query type", "domain", "client", "status", "reply type"];
function add(domain, list) {
var token = $("#token").text();
@@ -388,33 +389,83 @@ $(function () {
var api = this.api();
// Query type IPv4 / IPv6
- api.$("td:eq(1)").click(function (event) {
- addColumnFilter(event, 1, this.textContent);
- });
+ api
+ .$("td:eq(1)")
+ .click(function (event) {
+ addColumnFilter(event, 1, this.textContent);
+ })
+ .hover(
+ function () {
+ $(this).css("cursor", "pointer").attr("title", tooltipText(1, this.textContent));
+ },
+ function () {
+ $(this).css("cursor", "auto");
+ }
+ );
// Domain
- api.$("td:eq(2)").click(function (event) {
- addColumnFilter(event, 2, this.textContent.split("\n")[0]);
- });
+ api
+ .$("td:eq(2)")
+ .click(function (event) {
+ addColumnFilter(event, 2, this.textContent.split("\n")[0]);
+ })
+ .hover(
+ function () {
+ $(this).css("cursor", "pointer").attr("title", tooltipText(2, this.textContent));
+ },
+ function () {
+ $(this).css("cursor", "auto");
+ }
+ );
// Client
- api.$("td:eq(3)").click(function (event) {
- addColumnFilter(event, 3, this.textContent);
- });
+ api
+ .$("td:eq(3)")
+ .click(function (event) {
+ addColumnFilter(event, 3, this.textContent);
+ })
+ .hover(
+ function () {
+ $(this).css("cursor", "pointer").attr("title", tooltipText(3, this.textContent));
+ },
+ function () {
+ $(this).css("cursor", "auto");
+ }
+ );
// Status
- api.$("td:eq(4)").click(function (event) {
- var id = this.children.id.value;
- var text = this.textContent;
- addColumnFilter(event, 4, id + "#" + text);
- });
+ api
+ .$("td:eq(4)")
+ .click(function (event) {
+ var id = this.children.id.value;
+ var text = this.textContent;
+ addColumnFilter(event, 4, id + "#" + text);
+ })
+ .hover(
+ function () {
+ $(this).css("cursor", "pointer").attr("title", tooltipText(4, this.textContent));
+ },
+ function () {
+ $(this).css("cursor", "auto");
+ }
+ );
// Reply type
- api.$("td:eq(5)").click(function (event) {
- var id = this.children.id.value;
- var text = this.textContent.split(" ")[0];
- addColumnFilter(event, 5, id + "#" + text);
- });
+ api
+ .$("td:eq(5)")
+ .click(function (event) {
+ var id = this.children.id.value;
+ var text = this.textContent.split(" ")[0];
+ addColumnFilter(event, 5, id + "#" + text);
+ })
+ .hover(
+ function () {
+ $(this).css("cursor", "pointer").attr("title", tooltipText(5, this.textContent));
+ },
+ function () {
+ $(this).css("cursor", "auto");
+ }
+ );
}
});
@@ -444,6 +495,19 @@ $(function () {
}
});
+function tooltipText(index, text) {
+ if (index === 5) {
+ // Strip reply time from tooltip text
+ text = text.split(" ")[0];
+ }
+
+ if (index in tableFilters && tableFilters[index].length > 0) {
+ return "Clear filter on " + colTypes[index] + ' "' + text + '" using Shift + Click.';
+ }
+
+ return "Add filter on " + colTypes[index] + ' "' + text + '" using Ctrl + Click.';
+}
+
function addColumnFilter(event, colID, filterstring) {
// Don't do anything when NOT explicitly requesting multi-selection functions
if (!event.ctrlKey && !event.metaKey && !event.shiftKey) {
From c90fbc28cc02f15be0f7c933900f58910cae53fb Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 10:11:18 +0200
Subject: [PATCH 27/49] Reduce agressiveness of highlight color.
Signed-off-by: DL6ER
---
queries.php | 2 +-
style/themes/default-dark.css | 2 +-
style/themes/default-light.css | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/queries.php b/queries.php
index be203c49..cd5978bd 100644
--- a/queries.php
+++ b/queries.php
@@ -138,7 +138,7 @@ if(strlen($showing) > 0)
-
+
Filtering options:
Use Ctrl or ⌘ + to add columns to the current filter
Use Shift + to remove columns from the current filter
diff --git a/style/themes/default-dark.css b/style/themes/default-dark.css
index 1d63c1f4..62321bd5 100644
--- a/style/themes/default-dark.css
+++ b/style/themes/default-dark.css
@@ -385,7 +385,7 @@ pre {
color: #007997 !important;
}
td.highlight {
- background-color: yellow;
+ background-color: #ffcc0050;
}
.btn-default {
box-shadow: none;
diff --git a/style/themes/default-light.css b/style/themes/default-light.css
index 859af1c3..1ed7cf73 100644
--- a/style/themes/default-light.css
+++ b/style/themes/default-light.css
@@ -192,7 +192,7 @@
}
td.highlight {
- background-color: #ff0 !important;
+ background-color: #ffcc0050;
}
.network-never {
From 3d423ede5f3691ded9d9432965bfaafd0c9c78b2 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 10:26:54 +0200
Subject: [PATCH 28/49] Use classes instead of manipulating CSS directly for
getting the pointer.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 4e0a292b..775efb53 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -396,10 +396,10 @@ $(function () {
})
.hover(
function () {
- $(this).css("cursor", "pointer").attr("title", tooltipText(1, this.textContent));
+ $(this).addClass("pointer").attr("title", tooltipText(1, this.textContent));
},
function () {
- $(this).css("cursor", "auto");
+ $(this).removeClass("pointer");
}
);
@@ -411,10 +411,10 @@ $(function () {
})
.hover(
function () {
- $(this).css("cursor", "pointer").attr("title", tooltipText(2, this.textContent));
+ $(this).addClass("pointer").attr("title", tooltipText(2, this.textContent));
},
function () {
- $(this).css("cursor", "auto");
+ $(this).removeClass("pointer");
}
);
@@ -426,10 +426,10 @@ $(function () {
})
.hover(
function () {
- $(this).css("cursor", "pointer").attr("title", tooltipText(3, this.textContent));
+ $(this).addClass("pointer").attr("title", tooltipText(3, this.textContent));
},
function () {
- $(this).css("cursor", "auto");
+ $(this).removeClass("pointer");
}
);
@@ -443,10 +443,10 @@ $(function () {
})
.hover(
function () {
- $(this).css("cursor", "pointer").attr("title", tooltipText(4, this.textContent));
+ $(this).addClass("pointer").attr("title", tooltipText(4, this.textContent));
},
function () {
- $(this).css("cursor", "auto");
+ $(this).removeClass("pointer");
}
);
@@ -460,10 +460,10 @@ $(function () {
})
.hover(
function () {
- $(this).css("cursor", "pointer").attr("title", tooltipText(5, this.textContent));
+ $(this).addClass("pointer").attr("title", tooltipText(5, this.textContent));
},
function () {
- $(this).css("cursor", "auto");
+ $(this).removeClass("pointer");
}
);
}
From fafdf375334c21b56897900b0007847ca63de712 Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 10:38:51 +0200
Subject: [PATCH 29/49] Remove parseInt() from values guaranteed to be int from
the API.
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index 775efb53..df47aaed 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -258,11 +258,11 @@ $(function () {
isCNAME = true;
break;
default:
- fieldtext = "Unknown (" + parseInt(data[4]) + ")";
+ fieldtext = "Unknown (" + data[4] + ")";
buttontext = "";
}
- fieldtext += '';
+ fieldtext += '';
if (colorClass !== false) {
$(row).addClass(colorClass);
@@ -307,7 +307,7 @@ $(function () {
// Check for existence of sixth column and display only if not Pi-holed
var replytext,
- replyid = parseInt(data[5]);
+ replyid = data[5];
if (replyid >= 0 && replyid < replyTypes.length) {
replytext = replyTypes[replyid];
From f4fe04dd16659fd4e33877de21b5984cab5999be Mon Sep 17 00:00:00 2001
From: DL6ER
Date: Thu, 4 Jun 2020 10:52:35 +0200
Subject: [PATCH 30/49] Add placeholder to the search field to highlight what
can be searched for
Signed-off-by: DL6ER
---
scripts/pi-hole/js/queries.js | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js
index df47aaed..817267bf 100644
--- a/scripts/pi-hole/js/queries.js
+++ b/scripts/pi-hole/js/queries.js
@@ -466,6 +466,16 @@ $(function () {
$(this).removeClass("pointer");
}
);
+
+ // Disable autocorrect in the search box
+ var input = $("input[type=search]");
+ if (input !== null) {
+ input.attr("autocomplete", "off");
+ input.attr("autocorrect", "off");
+ input.attr("autocapitalize", "off");
+ input.attr("spellcheck", false);
+ input.attr("placeholder", "Type / Domain / Client");
+ }
}
});
@@ -484,15 +494,6 @@ $(function () {
tableApi.search("");
resetColumnsFilters();
});
-
- // Disable autocorrect in the search box
- var input = document.querySelector("input[type=search]");
- if (input !== null) {
- input.setAttribute("autocomplete", "off");
- input.setAttribute("autocorrect", "off");
- input.setAttribute("autocapitalize", "off");
- input.setAttribute("spellcheck", false);
- }
});
function tooltipText(index, text) {
From 1bef0bb17bfcdfa36385c203897c7e4b8a333ea7 Mon Sep 17 00:00:00 2001
From: XhmikosR
Date: Sun, 7 Jun 2020 14:20:45 +0300
Subject: [PATCH 31/49] Tweak CSP (#1445)
Switch to `default-src` `'none'` and specify the directives we were missing that were being inherited.
Signed-off-by: XhmikosR
---
scripts/pi-hole/php/header.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/pi-hole/php/header.php b/scripts/pi-hole/php/header.php
index 6e5af46b..e0b1d587 100644
--- a/scripts/pi-hole/php/header.php
+++ b/scripts/pi-hole/php/header.php
@@ -162,7 +162,7 @@
-
+
From 7bfc7cbcd54b984184e8db3c6d5701c1854c3722 Mon Sep 17 00:00:00 2001
From: XhmikosR
Date: Sun, 7 Jun 2020 17:00:13 +0300
Subject: [PATCH 32/49] network.js: use `utils.datetime()`
Signed-off-by: XhmikosR
---
scripts/pi-hole/js/network.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js
index 7471554c..788a1fb1 100644
--- a/scripts/pi-hole/js/network.js
+++ b/scripts/pi-hole/js/network.js
@@ -5,7 +5,7 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
-/* global moment:false, utils:false */
+/* global utils:false */
var tableApi;
@@ -161,7 +161,7 @@ $(function () {
width: "8%",
render: function (data, type) {
if (type === "display") {
- return moment.unix(data).format("Y-MM-DD [ ]HH:mm:ss z");
+ return utils.datetime(data);
}
return data;
@@ -172,7 +172,7 @@ $(function () {
width: "8%",
render: function (data, type) {
if (type === "display") {
- return moment.unix(data).format("Y-MM-DD [ ]HH:mm:ss z");
+ return utils.datetime(data);
}
return data;
From 0303fb6f5f9b33625287524aca3306c4f420fea1 Mon Sep 17 00:00:00 2001
From: XhmikosR
Date: Mon, 8 Jun 2020 07:49:51 +0300
Subject: [PATCH 33/49] footer.js: remove dead code.
Signed-off-by: XhmikosR
---
scripts/pi-hole/js/footer.js | 5 -----
1 file changed, 5 deletions(-)
diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js
index 5a84dcaf..f8541810 100644
--- a/scripts/pi-hole/js/footer.js
+++ b/scripts/pi-hole/js/footer.js
@@ -4,7 +4,6 @@
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
-/* global initpage:false */
//The following functions allow us to display time until pi-hole is enabled after disabling.
//Works between all pages
@@ -221,10 +220,6 @@ $(function () {
initCheckboxRadioStyle();
initCPUtemp();
- if (typeof initpage === "function") {
- setTimeout(initpage, 100);
- }
-
// Run check immediately after page loading ...
checkMessages();
// ... and once again with five seconds delay
From 557bd85814d019e292430de0c92f288815d5a7ea Mon Sep 17 00:00:00 2001
From: Adam Warner
Date: Tue, 9 Jun 2020 07:28:45 +0100
Subject: [PATCH 34/49] change button type on dhcp static lease removal back to
submit (#1456)
Signed-off-by: Adam Warner
---
settings.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/settings.php b/settings.php
index fbb10757..51292f4c 100644
--- a/settings.php
+++ b/settings.php
@@ -744,7 +744,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "
">
0) { ?>
-
From 95379bbe7c010aca72698e9bd872a18e4b8791b5 Mon Sep 17 00:00:00 2001
From: Willem Stuursma-Ruwen
Date: Wed, 10 Jun 2020 21:29:45 +0200
Subject: [PATCH 35/49] #1227 Test if file exists instead of silencing errors
---
api.php | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/api.php b/api.php
index 15023dbf..7c3f6130 100644
--- a/api.php
+++ b/api.php
@@ -52,8 +52,10 @@ elseif (isset($_GET['enable']) && $auth)
}
pihole_execute('enable');
$data = array_merge($data, array("status" => "enabled"));
- // Silence errors if there is a race condition with the timer
- @unlink("../custom_disable_timer");
+ if (file_exists("../custom_disable_timer"))
+ {
+ unlink("../custom_disable_timer");
+ }
}
elseif (isset($_GET['disable']) && $auth)
{
@@ -78,8 +80,10 @@ elseif (isset($_GET['disable']) && $auth)
else
{
pihole_execute('disable');
- // Silence errors if there is a race condition with the timer
- @unlink("../custom_disable_timer");
+ if (file_exists("../custom_disable_timer"))
+ {
+ unlink("../custom_disable_timer");
+ }
}
$data = array_merge($data, array("status" => "disabled"));
}
From c949516ee15fa6a9b0c8511cc4c4d6b0893f3e69 Mon Sep 17 00:00:00 2001
From: Adam Warner
Date: Sat, 13 Jun 2020 18:50:36 +0100
Subject: [PATCH 36/49] make use of utils.escapeHtml on the JS side of things,
and html_entity_decode/htmlentities in PHP
Signed-off-by: Adam Warner
---
dns_records.php | 1 +
scripts/pi-hole/js/customdns.js | 6 +++--
scripts/pi-hole/js/groups-adlists.js | 10 +++----
scripts/pi-hole/js/groups-clients.js | 12 ++++-----
scripts/pi-hole/js/groups-domains.js | 10 +++----
scripts/pi-hole/js/groups.js | 10 +++----
scripts/pi-hole/php/database.php | 4 +--
scripts/pi-hole/php/func.php | 39 +++++++++++++++-------------
scripts/pi-hole/php/groups.php | 25 ++++++++++--------
scripts/pi-hole/php/teleporter.php | 4 +--
settings.php | 4 +--
11 files changed, 67 insertions(+), 58 deletions(-)
diff --git a/dns_records.php b/dns_records.php
index 4d429af4..dc9e5d5f 100644
--- a/dns_records.php
+++ b/dns_records.php
@@ -89,6 +89,7 @@
+
diff --git a/scripts/pi-hole/js/customdns.js b/scripts/pi-hole/js/customdns.js
index 116ea602..d2f4ad56 100644
--- a/scripts/pi-hole/js/customdns.js
+++ b/scripts/pi-hole/js/customdns.js
@@ -5,6 +5,8 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
+/* global utils:false */
+
var table;
var token = $("#token").text();
@@ -76,8 +78,8 @@ $(function () {
});
function addCustomDNS() {
- var ip = $("#ip").val();
- var domain = $("#domain").val();
+ var ip = utils.escapeHtml($("#ip").val());
+ var domain = utils.escapeHtml($("#domain").val());
showAlert("info");
$.ajax({
diff --git a/scripts/pi-hole/js/groups-adlists.js b/scripts/pi-hole/js/groups-adlists.js
index 4bcdde81..4f58b1c4 100644
--- a/scripts/pi-hole/js/groups-adlists.js
+++ b/scripts/pi-hole/js/groups-adlists.js
@@ -212,8 +212,8 @@ function initTable() {
}
function addAdlist() {
- var address = $("#new_address").val();
- var comment = $("#new_comment").val();
+ var address = utils.escapeHtml($("#new_address").val());
+ var comment = utils.escapeHtml($("#new_comment").val());
utils.disableAll();
utils.showAlert("info", "", "Adding adlist...", address);
@@ -258,9 +258,9 @@ function editAdlist() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
var status = tr.find("#status_" + id).is(":checked") ? 1 : 0;
- var comment = tr.find("#comment_" + id).val();
+ var comment = utils.escapeHtml(tr.find("#comment_" + id).val());
var groups = tr.find("#multiselect_" + id).val();
- var address = tr.find("#address_" + id).text();
+ var address = utils.escapeHtml(tr.find("#address_" + id).text());
var done = "edited";
var notDone = "editing";
@@ -338,7 +338,7 @@ function editAdlist() {
function deleteAdlist() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
- var address = tr.find("#address_" + id).text();
+ var address = utils.escapeHtml(tr.find("#address_" + id).text());
utils.disableAll();
utils.showAlert("info", "", "Deleting adlist...", address);
diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js
index 609606ce..70ff81ff 100644
--- a/scripts/pi-hole/js/groups-clients.js
+++ b/scripts/pi-hole/js/groups-clients.js
@@ -246,9 +246,9 @@ function initTable() {
function addClient() {
var ip = $("#select").val();
- var comment = $("#new_comment").val();
+ var comment = utils.escapeHtml($("#new_comment").val());
if (ip === "custom") {
- ip = $("#ip-custom").val().trim();
+ ip = utils.escapeHtml($("#ip-custom").val().trim());
}
utils.disableAll();
@@ -303,9 +303,9 @@ function editClient() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
var groups = tr.find("#multiselect_" + id).val();
- var ip = tr.find("#ip_" + id).text();
- var name = tr.find("#name_" + id).text();
- var comment = tr.find("#comment_" + id).val();
+ var ip = utils.escapeHtml(tr.find("#ip_" + id).text());
+ var name = utils.escapeHtml(tr.find("#name_" + id).text());
+ var comment = utils.escapeHtml(tr.find("#comment_" + id).val());
var done = "edited";
var notDone = "editing";
@@ -370,7 +370,7 @@ function deleteClient() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
var ip = tr.find("#ip_" + id).text();
- var name = tr.find("#name_" + id).text();
+ var name = utils.escapeHtml(tr.find("#name_" + id).text());
if (name.length > 0) {
ip += " (" + name + ")";
diff --git a/scripts/pi-hole/js/groups-domains.js b/scripts/pi-hole/js/groups-domains.js
index 74768f8d..5128ef14 100644
--- a/scripts/pi-hole/js/groups-domains.js
+++ b/scripts/pi-hole/js/groups-domains.js
@@ -318,8 +318,8 @@ function addDomain() {
commentEl = $("#new_regex_comment");
}
- var domain = domainEl.val();
- var comment = commentEl.val();
+ var domain = utils.escapeHtml(domainEl.val());
+ var comment = utils.escapeHtml(commentEl.val());
utils.disableAll();
utils.showAlert("info", "", "Adding " + domainRegex + "...", domain);
@@ -385,10 +385,10 @@ function editDomain() {
var elem = $(this).attr("id");
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
- var domain = tr.find("#domain_" + id).text();
+ var domain = utils.escapeHtml(tr.find("#domain_" + id).text());
var type = tr.find("#type_" + id).val();
var status = tr.find("#status_" + id).is(":checked") ? 1 : 0;
- var comment = tr.find("#comment_" + id).val();
+ var comment = utils.escapeHtml(tr.find("#comment_" + id).val());
// Show group assignment field only if in full domain management mode
// if not included, just use the row data.
@@ -485,7 +485,7 @@ function editDomain() {
function deleteDomain() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
- var domain = tr.find("#domain_" + id).text();
+ var domain = utils.escapeHtml(tr.find("#domain_" + id).text());
var type = tr.find("#type_" + id).val();
var domainRegex;
diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js
index f7d16d53..9835c4c7 100644
--- a/scripts/pi-hole/js/groups.js
+++ b/scripts/pi-hole/js/groups.js
@@ -127,8 +127,8 @@ $(function () {
});
function addGroup() {
- var name = $("#new_name").val();
- var desc = $("#new_desc").val();
+ var name = utils.escapeHtml($("#new_name").val());
+ var desc = utils.escapeHtml($("#new_desc").val());
utils.disableAll();
utils.showAlert("info", "", "Adding group...", name);
@@ -166,9 +166,9 @@ function editGroup() {
var elem = $(this).attr("id");
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
- var name = tr.find("#name_" + id).val();
+ var name = utils.escapeHtml(tr.find("#name_" + id).val());
var status = tr.find("#status_" + id).is(":checked") ? 1 : 0;
- var desc = tr.find("#desc_" + id).val();
+ var desc = utils.escapeHtml(tr.find("#desc_" + id).val());
var done = "edited";
var notDone = "editing";
@@ -239,7 +239,7 @@ function editGroup() {
function deleteGroup() {
var tr = $(this).closest("tr");
var id = tr.attr("data-id");
- var name = tr.find("#name_" + id).val();
+ var name = utils.escapeHtml(tr.find("#name_" + id).val());
utils.disableAll();
utils.showAlert("info", "", "Deleting group...", name);
diff --git a/scripts/pi-hole/php/database.php b/scripts/pi-hole/php/database.php
index 0a6af814..46b7dece 100644
--- a/scripts/pi-hole/php/database.php
+++ b/scripts/pi-hole/php/database.php
@@ -161,9 +161,9 @@ function add_to_table($db, $table, $domains, $comment=null, $wildcardstyle=false
if($wildcardstyle)
$domain = "(\\.|^)".str_replace(".","\\.",$domain)."$";
- $stmt->bindValue(":$field", $domain, SQLITE3_TEXT);
+ $stmt->bindValue(":$field", htmlentities($domain), SQLITE3_TEXT);
if($bindcomment) {
- $stmt->bindValue(":comment", $comment, SQLITE3_TEXT);
+ $stmt->bindValue(":comment", htmlentities($comment), SQLITE3_TEXT);
}
if($stmt->execute() && $stmt->reset())
diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php
index 37eb8e9d..efb7c3b8 100644
--- a/scripts/pi-hole/php/func.php
+++ b/scripts/pi-hole/php/func.php
@@ -214,31 +214,34 @@ function deleteCustomDNSEntry()
function deleteAllCustomDNSEntries()
{
- $handle = fopen($customDNSFile, "r");
- if ($handle)
+ if (isset($customDNSFile))
{
- try
+ $handle = fopen($customDNSFile, "r");
+ if ($handle)
{
- while (($line = fgets($handle)) !== false) {
- $line = str_replace("\r","", $line);
- $line = str_replace("\n","", $line);
- $explodedLine = explode (" ", $line);
+ try
+ {
+ while (($line = fgets($handle)) !== false) {
+ $line = str_replace("\r","", $line);
+ $line = str_replace("\n","", $line);
+ $explodedLine = explode (" ", $line);
- if (count($explodedLine) != 2)
- continue;
+ if (count($explodedLine) != 2)
+ continue;
- $ip = $explodedLine[0];
- $domain = $explodedLine[1];
+ $ip = $explodedLine[0];
+ $domain = $explodedLine[1];
- pihole_execute("-a removecustomdns ".$ip." ".$domain);
+ pihole_execute("-a removecustomdns ".$ip." ".$domain);
+ }
+ }
+ catch (\Exception $ex)
+ {
+ return errorJsonResponse($ex->getMessage());
}
- }
- catch (\Exception $ex)
- {
- return errorJsonResponse($ex->getMessage());
- }
- fclose($handle);
+ fclose($handle);
+ }
}
return successJsonResponse();
diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php
index 1eb4e72b..04a9030c 100644
--- a/scripts/pi-hole/php/groups.php
+++ b/scripts/pi-hole/php/groups.php
@@ -58,7 +58,8 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'add_group') {
// Add new group
try {
- $names = str_getcsv(trim($_POST['name']), ' ');
+ $input = html_entity_decode(trim($_POST['name']));
+ $names = str_getcsv($input, ' ');
$total = count($names);
$added = 0;
$stmt = $db->prepare('INSERT INTO "group" (name,description) VALUES (:name,:desc)');
@@ -96,6 +97,9 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'edit_group') {
// Edit group identified by ID
try {
+ $name = html_entity_decode($_POST['name']);
+ $desc = html_entity_decode($_POST['desc']);
+
$stmt = $db->prepare('UPDATE "group" SET enabled=:enabled, name=:name, description=:desc WHERE id = :id');
if (!$stmt) {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
@@ -106,11 +110,10 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding enabled: ' . $db->lastErrorMsg());
}
- if (!$stmt->bindValue(':name', $_POST['name'], SQLITE3_TEXT)) {
+ if (!$stmt->bindValue(':name', $name, SQLITE3_TEXT)) {
throw new Exception('While binding name: ' . $db->lastErrorMsg());
}
- $desc = $_POST['desc'];
if (strlen($desc) === 0) {
// Store NULL in database for empty descriptions
$desc = null;
@@ -263,7 +266,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding ip: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
@@ -293,7 +296,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
@@ -453,7 +456,7 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'add_domain') {
// Add new domain
try {
- $domains = explode(' ', trim($_POST['domain']));
+ $domains = explode(' ', html_entity_decode(trim($_POST['domain'])));
$before = intval($db->querySingle("SELECT COUNT(*) FROM domainlist;"));
$total = count($domains);
$added = 0;
@@ -474,7 +477,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding type: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
@@ -573,7 +576,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding enabled: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
@@ -742,7 +745,7 @@ if ($_POST['action'] == 'get_groups') {
} elseif ($_POST['action'] == 'add_adlist') {
// Add new adlist
try {
- $addresses = explode(' ', trim($_POST['address']));
+ $addresses = explode(' ', html_entity_decode(trim($_POST['address'])));
$total = count($addresses);
$added = 0;
@@ -751,7 +754,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While preparing statement: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
@@ -800,7 +803,7 @@ if ($_POST['action'] == 'get_groups') {
throw new Exception('While binding enabled: ' . $db->lastErrorMsg());
}
- $comment = $_POST['comment'];
+ $comment = html_entity_decode($_POST['comment']);
if (strlen($comment) === 0) {
// Store NULL in database for empty comments
$comment = null;
diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php
index 52951067..cfd4bc47 100644
--- a/scripts/pi-hole/php/teleporter.php
+++ b/scripts/pi-hole/php/teleporter.php
@@ -173,7 +173,7 @@ function archive_restore_table($file, $table, $flush=false)
foreach($contents as $row)
{
// Limit max length for a domain entry to 253 chars
- if(strlen($row[$field]) > 253)
+ if(isset($field) && strlen($row[$field]) > 253)
continue;
// Bind properties from JSON data
@@ -196,7 +196,7 @@ function archive_restore_table($file, $table, $flush=false)
default:
$sqltype = "UNK";
}
- $stmt->bindValue(":".$key, $value, $sqltype);
+ $stmt->bindValue(":".$key, htmlentities($value), $sqltype);
}
if($stmt->execute() && $stmt->reset() && $stmt->clear())
diff --git a/settings.php b/settings.php
index 51292f4c..06512b48 100644
--- a/settings.php
+++ b/settings.php
@@ -714,7 +714,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", "
title="Lease type: IPv Remaining lease time: DHCP UID: ">