mirror of
https://github.com/pi-hole/web.git
synced 2024-12-06 19:36:21 +01:00
Allow users to specify clients as MAC addresses
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user