Allow users to specify clients as MAC addresses

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2020-05-13 19:09:46 +02:00
parent 9c6a582cb2
commit 2f0b8bfdc8
2 changed files with 15 additions and 11 deletions
+9 -11
View File
@@ -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;
}
+6
View File
@@ -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
};
})();