From eb983dc2922fe56d6bdbbb91f7049d2e6a8478cd Mon Sep 17 00:00:00 2001 From: DL6ER Date: Mon, 18 May 2020 14:59:39 +0200 Subject: [PATCH] Add support for entering client host names. Signed-off-by: DL6ER --- groups-clients.php | 2 +- scripts/pi-hole/js/groups-clients.js | 10 ++++++---- scripts/pi-hole/js/groups-common.js | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/groups-clients.php b/groups-clients.php index de6361ed..0e9a319c 100644 --- a/groups-clients.php +++ b/groups-clients.php @@ -39,7 +39,7 @@
-

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 }; })();