Add support for entering client host names.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-05-18 14:59:39 +02:00
parent 090e55ef99
commit eb983dc292
3 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -39,7 +39,7 @@
</div>
<div class="row">
<div class="col-md-12">
<p>You can select an existing client or add a custom one by typing into the field above and confirming your entry with <kbd>&#x23CE;</kbd>. Clients can be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like <code>192.168.2.0/24</code>) 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.</p>
<p>You can select an existing client or add a custom one by typing into the field above and confirming your entry with <kbd>&#x23CE;</kbd>.<br>Clients may be described either by their IP addresses (IPv4 and IPv6 are supported), IP subnets (CIDR notation, like <code>192.168.2.0/24</code>), their MAC addresses (like <code>12:34:56:78:9A:BC</code>) or by hostnames (like <code>localhost</code>). 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.</p>
</div>
</div>
</div>
+6 -4
View File
@@ -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;
}
+7 -1
View File
@@ -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
};
})();