From 2f0b8bfdc8bad198d8259c51a79f94845ea4034d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 13 May 2020 19:09:46 +0200 Subject: [PATCH 01/28] Allow users to specify clients as MAC addresses Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-clients.js | 20 +++++++++----------- scripts/pi-hole/js/groups-common.js | 6 ++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index 49da0613..c883e5f5 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -257,22 +257,20 @@ function addClient() { if (ip.length === 0) { utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Please specify a client IP address"); + utils.showAlert("warning", "", "Warning", "Please specify a client IP or MAC address"); return; } - // Validate IP address (may contain CIDR details) - var ipv6format = ip.includes(":"); + // Convert input to upper case (important for MAC addresses) + ip = ip.toUpperCase(); - if (!ipv6format && !utils.validateIPv4CIDR(ip)) { + // Validate input, can be: + // - IPv4 address (with and without CIDR) + // - IPv6 address (with and without CIDR) + // - MAC address (in the form AA:BB:CC:DD:EE:FF) + if (!utils.validateIPv4CIDR(ip) && !utils.validateIPv6CIDR(ip) && !utils.validateMAC(ip)) { utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Invalid IPv4 address!"); - return; - } - - if (ipv6format && !utils.validateIPv6CIDR(ip)) { - utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Invalid IPv6 address!"); + utils.showAlert("warning", "", "Warning", "Input is neither an IP nor a MAC address!"); return; } diff --git a/scripts/pi-hole/js/groups-common.js b/scripts/pi-hole/js/groups-common.js index b0156b0e..8283b0ad 100644 --- a/scripts/pi-hole/js/groups-common.js +++ b/scripts/pi-hole/js/groups-common.js @@ -129,6 +129,11 @@ function validateIPv6CIDR(ip) { return ipv6validator.test(ip); } +function validateMAC(mac) { + var macvalidator = new RegExp(/^([\dA-F]{2}:){5}([\dA-F]{2})$/); + return macvalidator.test(mac); +} + function bsSelect_defaults() { // set bootstrap-select defaults var pickerDEFAULTS = $.fn.selectpicker.Constructor.DEFAULTS; @@ -157,6 +162,7 @@ window.utils = (function () { enableAll: enableAll, validateIPv4CIDR: validateIPv4CIDR, validateIPv6CIDR: validateIPv6CIDR, + validateMAC: validateMAC, bsSelect_defaults: bsSelect_defaults }; })(); From bdca8104e5484dc111d4d5383e09be7062c7871d Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 13 May 2020 21:18:54 +0200 Subject: [PATCH 02/28] Add better select menu allowing users to filter inside the dropdown as well as add new entries in place. Signed-off-by: DL6ER --- groups-clients.php | 8 +++-- scripts/pi-hole/js/groups-clients.js | 47 ++++++++++++++++++---------- scripts/pi-hole/php/groups.php | 8 ++--- scripts/pi-hole/php/header.php | 2 ++ scripts/vendor/select2.min.js | 2 ++ style/vendor/select2.min.css | 1 + 6 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 scripts/vendor/select2.min.js create mode 100644 style/vendor/select2.min.css diff --git a/groups-clients.php b/groups-clients.php index 6888ccc9..de6361ed 100644 --- a/groups-clients.php +++ b/groups-clients.php @@ -30,14 +30,18 @@
- +
+
+
+

You can select an existing client or add a custom one by typing into the field above and confirming your entry with ⏎. Clients can be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like 192.168.2.0/24) or by their MAC addresses. Note that client recognition by MAC addresses only work for devices at most one networking hop away from your Pi-hole.

+
+
-

You can select an existing client or add a custom one by typing into the field above and confirming your entry with ⏎. Clients can be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like 192.168.2.0/24) or by their MAC addresses. Note that client recognition by MAC addresses only work for devices at most one networking hop away from your Pi-hole.

+

You can select an existing client or add a custom one by typing into the field above and confirming your entry with ⏎.
Clients may be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like 192.168.2.0/24), their MAC addresses (like 12:34:56:78:9A:BC) or by hostnames (like localhost). Note that client recognition by IP addresses (incl. subnet ranges) are prefered over MAC address or host name recognition as the two latter will only be available after some time. Furthermore, MAC address recognition only works for devices at most one networking hop away from your Pi-hole.

diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index bcd6666e..ed5463f4 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -279,16 +279,18 @@ function addClient() { return; } - // Convert input to upper case (important for MAC addresses) - ip = ip.toUpperCase(); // Validate input, can be: // - IPv4 address (with and without CIDR) // - IPv6 address (with and without CIDR) // - MAC address (in the form AA:BB:CC:DD:EE:FF) - if (!utils.validateIPv4CIDR(ip) && !utils.validateIPv6CIDR(ip) && !utils.validateMAC(ip)) { + // - host name (arbitrary form, we're only checking against some reserved charaters) + if (utils.validateIPv4CIDR(ip) || utils.validateIPv6CIDR(ip) || utils.validateMAC(ip)) { + // Convert input to upper case (important for MAC addresses) + ip = ip.toUpperCase(); + } else if (!utils.validateHostname(ip)) { utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Input is neither an IP nor a MAC address!"); + utils.showAlert("warning", "", "Warning", "Input is neither a valid IP or MAC address nor a valid host name!"); return; } diff --git a/scripts/pi-hole/js/groups-common.js b/scripts/pi-hole/js/groups-common.js index 8283b0ad..6fb24eea 100644 --- a/scripts/pi-hole/js/groups-common.js +++ b/scripts/pi-hole/js/groups-common.js @@ -130,10 +130,15 @@ function validateIPv6CIDR(ip) { } function validateMAC(mac) { - var macvalidator = new RegExp(/^([\dA-F]{2}:){5}([\dA-F]{2})$/); + var macvalidator = new RegExp(/^([\da-fA-F]{2}:){5}([\da-fA-F]{2})$/); return macvalidator.test(mac); } +function validateHostname(name) { + var namevalidator = new RegExp(/[^<>;\"]/); + return namevalidator.test(name); +} + function bsSelect_defaults() { // set bootstrap-select defaults var pickerDEFAULTS = $.fn.selectpicker.Constructor.DEFAULTS; @@ -163,6 +168,7 @@ window.utils = (function () { validateIPv4CIDR: validateIPv4CIDR, validateIPv6CIDR: validateIPv6CIDR, validateMAC: validateMAC, + validateHostname: validateHostname, bsSelect_defaults: bsSelect_defaults }; })(); From 46c09841bc6c2d8b58561ae6614240df4156c6b2 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 18 May 2020 15:12:51 +0200 Subject: [PATCH 16/28] Fix background of dropdown menu. Signed-off-by: DL6ER --- style/pi-hole.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/style/pi-hole.css b/style/pi-hole.css index 1218d914..0277924b 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -276,10 +276,6 @@ code.breakall { padding: 0 12px; } -.select2-container--open .select2-dropdown--below { - max-height: 400px; -} - .select2-container--default .select2-results > .select2-results__options { max-height: 400px; } From 7be091d76ec0e8fe3d1da29513f9b8bd0fa1468a Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 18 May 2020 21:14:42 +0200 Subject: [PATCH 17/28] Shorten name validation regex Signed-off-by: DL6ER --- scripts/pi-hole/js/groups-common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/groups-common.js b/scripts/pi-hole/js/groups-common.js index 6fb24eea..3e177a22 100644 --- a/scripts/pi-hole/js/groups-common.js +++ b/scripts/pi-hole/js/groups-common.js @@ -135,7 +135,7 @@ function validateMAC(mac) { } function validateHostname(name) { - var namevalidator = new RegExp(/[^<>;\"]/); + var namevalidator = new RegExp(/[^<>;"]/); return namevalidator.test(name); } From 128a88e1302d3c2932f7c1ed36c606cc1b9f8368 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 18 May 2020 21:22:26 +0200 Subject: [PATCH 18/28] Fix IP sorting when there are empty fields present. Signed-off-by: DL6ER --- scripts/pi-hole/js/ip-address-sorting.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/js/ip-address-sorting.js b/scripts/pi-hole/js/ip-address-sorting.js index d636ecf9..bfb7fab2 100644 --- a/scripts/pi-hole/js/ip-address-sorting.js +++ b/scripts/pi-hole/js/ip-address-sorting.js @@ -5,12 +5,18 @@ * This file is copyright under the latest version of the EUPL. * Please see LICENSE file for your rights under this license. */ -// This code has been taken from +// The original ip-sorting code has been taken from // https://datatables.net/plug-ins/sorting/ip-address +// and was modified by the Pi-hole team to support +// CIDR notation and be more robust against invalid +// input data (like empty IP addresses) + jQuery.extend(jQuery.fn.dataTableExt.oSort, { "ip-address-pre": function (a) { - if (!a) { - return 0; + // Skip empty fields (IP address might have expired or + // reassigned to a differenct device) + if (!a || a.length === 0) { + return Infinity; } var i, item; From ac89d268a75873b1d35d2ecfa883ccc861c84380 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 19 May 2020 11:23:42 +0200 Subject: [PATCH 19/28] Only try to implode pihole arpflush quiet output if it is an array. Signed-off-by: DL6ER --- scripts/pi-hole/php/savesettings.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/savesettings.php b/scripts/pi-hole/php/savesettings.php index d537ae8b..9f3735d9 100644 --- a/scripts/pi-hole/php/savesettings.php +++ b/scripts/pi-hole/php/savesettings.php @@ -725,7 +725,10 @@ function addStaticDHCPLease($mac, $ip, $hostname) { // Flush network table case "flusharp": pihole_execute("arpflush quiet", $output); - $error = implode("
", $output); + if(is_array($output)) + { + $error = implode("
", $output); + } if(strlen($error) == 0) { $success .= "The network table has been flushed"; From 67da8474406b10ed3b9efb6406ad5c77bdb0b149 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 19 May 2020 11:27:10 +0200 Subject: [PATCH 20/28] Rename IP column on groups->clients page. Signed-off-by: DL6ER --- groups-clients.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/groups-clients.php b/groups-clients.php index 0e9a319c..e4796df5 100644 --- a/groups-clients.php +++ b/groups-clients.php @@ -63,7 +63,7 @@ ID - IP address + Client Comment Group assignment Action From f780ff3fbc48c0dd1bf251e0e3d10f77b3a2f0ef Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 26 May 2020 18:20:07 +0200 Subject: [PATCH 21/28] Add :interface description Signed-off-by: DL6ER --- groups-clients.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/groups-clients.php b/groups-clients.php index e4796df5..542993e7 100644 --- a/groups-clients.php +++ b/groups-clients.php @@ -39,7 +39,14 @@
-

You can select an existing client or add a custom one by typing into the field above and confirming your entry with ⏎.
Clients may be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like 192.168.2.0/24), their MAC addresses (like 12:34:56:78:9A:BC) or by hostnames (like localhost). Note that client recognition by IP addresses (incl. subnet ranges) are prefered over MAC address or host name recognition as the two latter will only be available after some time. Furthermore, MAC address recognition only works for devices at most one networking hop away from your Pi-hole.

+

You can select an existing client or add a custom one by typing into the field above and confirming your entry with ⏎.

+

Clients may be described either by their IP addresses (IPv4 and IPv6 are supported), + IP subnets (CIDR notation, like 192.168.2.0/24), + their MAC addresses (like 12:34:56:78:9A:BC), + by their hostnames (like localhost), or by the interface they are connected to (prefaced with a colon, like :eth0).

+

Note that client recognition by IP addresses (incl. subnet ranges) are prefered over MAC address, host name or interface recognition as + the two latter will only be available after some time. + Furthermore, MAC address recognition only works for devices at most one networking hop away from your Pi-hole.

From eb3c672545fbfd5ccb8cfc374b3b7ef271dd03ce Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 27 May 2020 19:48:51 +0200 Subject: [PATCH 22/28] Show explicitly which hostname belongs to which IP address when hovering over the hostnames. Note that the IP addresses and host names were already in the same order, before. Signed-off-by: DL6ER --- api_db.php | 2 ++ scripts/pi-hole/js/groups-clients.js | 8 ++++++-- scripts/pi-hole/js/network.js | 17 +++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/api_db.php b/api_db.php index d6da3bbb..34d0b8af 100644 --- a/api_db.php +++ b/api_db.php @@ -73,6 +73,8 @@ if(isset($_GET["network"]) && $auth) array_push($res["ip"],$network_address["ip"]); if($network_address["name"] !== null) array_push($res["name"],utf8_encode($network_address["name"])); + else + array_push($res["name"],""); } $network_addresses->finalize(); diff --git a/scripts/pi-hole/js/groups-clients.js b/scripts/pi-hole/js/groups-clients.js index ed5463f4..d1ac337f 100644 --- a/scripts/pi-hole/js/groups-clients.js +++ b/scripts/pi-hole/js/groups-clients.js @@ -279,7 +279,6 @@ function addClient() { return; } - // Validate input, can be: // - IPv4 address (with and without CIDR) // - IPv6 address (with and without CIDR) @@ -290,7 +289,12 @@ function addClient() { ip = ip.toUpperCase(); } else if (!utils.validateHostname(ip)) { utils.enableAll(); - utils.showAlert("warning", "", "Warning", "Input is neither a valid IP or MAC address nor a valid host name!"); + utils.showAlert( + "warning", + "", + "Warning", + "Input is neither a valid IP or MAC address nor a valid host name!" + ); return; } diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js index 82f48f21..6a8aa787 100644 --- a/scripts/pi-hole/js/network.js +++ b/scripts/pi-hole/js/network.js @@ -112,10 +112,12 @@ $(document).ready(function () { $("td:eq(3)", row).html("unknown"); } else { var names = []; + var name = ""; maxiter = Math.min(data.name.length, MAXIPDISPLAY); index = 0; for (index = 0; index < maxiter; index++) { - var name = data.name[index]; + name = data.name[index]; + if (name.length === 0) continue; names.push('' + name + ""); } @@ -125,9 +127,20 @@ $(document).ready(function () { names.push("..."); } + maxiter = Math.min(data.ip.length, data.name.length); + var allnames = []; + for (index = 0; index < maxiter; index++) { + name = data.name[index]; + if (name.length > 0) { + allnames.push(name + " (" + data.ip[index] + ")"); + } else { + allnames.push("No host name for " + data.ip[index] + " known"); + } + } + $("td:eq(3)", row).html(names.join("
")); $("td:eq(3)", row).hover(function () { - this.title = data.name.join("\n"); + this.title = allnames.join("\n"); }); } From 93d8084ea4de288668173773f4ae7330b4dcb02f Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 17 Aug 2020 11:00:04 -0400 Subject: [PATCH 23/28] Make login form button more mobile friendly Signed-off-by: Evan --- scripts/pi-hole/php/loginpage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/loginpage.php b/scripts/pi-hole/php/loginpage.php index 2024c173..d24e9c60 100644 --- a/scripts/pi-hole/php/loginpage.php +++ b/scripts/pi-hole/php/loginpage.php @@ -38,7 +38,7 @@
-
+
From 67c1f2b7494031c80e929aed4bab803c4fdb71cb Mon Sep 17 00:00:00 2001 From: Matt Booth Date: Wed, 19 Aug 2020 08:37:07 +0100 Subject: [PATCH 24/28] Fix typo in DNS Settings --- settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.php b/settings.php index 1d71de0a..10f139b5 100644 --- a/settings.php +++ b/settings.php @@ -994,7 +994,7 @@ if (isset($_GET['tab']) && in_array($_GET['tab'], array("sysadmin", "adlists", " 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).

+ Exemplary input 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 From 7f1be9d330105e105703111e31eafc5d26cabbec Mon Sep 17 00:00:00 2001 From: yubiuser Date: Wed, 19 Aug 2020 13:24:46 +0200 Subject: [PATCH 25/28] Remove degree symbole from Kelvin Signed-off-by: yubiuser --- scripts/pi-hole/js/footer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index f8541810..c9cd2921 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -170,7 +170,7 @@ function initCPUtemp() { switch (unit) { case "K": temperature += 273.15; - displaytemp.html(temperature.toFixed(1) + " °K"); + displaytemp.html(temperature.toFixed(1) + " K"); break; case "F": From f951dd2eb9b947e432032f979cef83d22f0012ce Mon Sep 17 00:00:00 2001 From: DL6ER Date: Tue, 25 Aug 2020 19:27:16 +0200 Subject: [PATCH 26/28] Apply prettier rules Signed-off-by: DL6ER --- style/pi-hole.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/style/pi-hole.css b/style/pi-hole.css index 4499c3bc..bf952a51 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -302,5 +302,5 @@ } .select2-container--default .select2-results > .select2-results__options { - max-height: 400px; + max-height: 400px; } From 8ecb72c0ccd60866b1fe8673c9e1a8bf3039685b Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Fri, 11 Sep 2020 17:46:04 +0100 Subject: [PATCH 27/28] Tweak to the login button and Forgot Password section to make it more obvious which is the correct button. Signed-off-by: Adam Warner --- scripts/pi-hole/php/loginpage.php | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/scripts/pi-hole/php/loginpage.php b/scripts/pi-hole/php/loginpage.php index d24e9c60..9db8e57b 100644 --- a/scripts/pi-hole/php/loginpage.php +++ b/scripts/pi-hole/php/loginpage.php @@ -30,34 +30,36 @@

+
+
+ +
+
+
-
-
- - -
-
- +
+ + +

+ if (!$wrongpassword) { ?> collapsed-box">
-

Forgot password

+

Forgot password?

-
@@ -73,4 +75,4 @@
-
+
\ No newline at end of file From 790793a16f0fcce776473bbe1fd54006dbaa3817 Mon Sep 17 00:00:00 2001 From: Adam Warner Date: Sat, 12 Sep 2020 11:32:41 +0100 Subject: [PATCH 28/28] Address some of @dl6er's comments Signed-off-by: Adam Warner --- scripts/pi-hole/php/loginpage.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/php/loginpage.php b/scripts/pi-hole/php/loginpage.php index 9db8e57b..fdbd658c 100644 --- a/scripts/pi-hole/php/loginpage.php +++ b/scripts/pi-hole/php/loginpage.php @@ -44,20 +44,18 @@
-
- - -
+
+ + +

-
+

Forgot password?

-
@@ -75,4 +73,4 @@
-
\ No newline at end of file +