add ipv6 and ipv4 cidr match vtype

add additional vtype for combined ipv4 and ipv6 cidr validation.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
This commit is contained in:
Mira Limbeck 2019-04-15 15:12:16 +02:00 committed by Thomas Lamprecht
parent a9c65d7e9c
commit 577b6c7546
2 changed files with 21 additions and 2 deletions

View File

@ -47,6 +47,22 @@ Ext.apply(Ext.form.field.VTypes, {
IP64AddressText: gettext('Example') + ': 192.168.1.1 2001:DB8::42',
IP64AddressMask: /[A-Fa-f0-9\.:]/,
IP64CIDRAddress: function(v) {
var result = Proxmox.Utils.IP64_cidr_match.exec(v);
if (result === null) {
return false;
}
if (result[1] !== undefined) {
return result[1] >= 8 && result[1] <= 128;
} else if (result[2] !== undefined) {
return result[2] >= 8 && result[2] <= 32;
} else {
return false;
}
},
IP64CIDRAddressText: gettext('Example') + ': 192.168.1.1/24 2001:DB8::42/64',
IP64CIDRAddressMask: /[A-Fa-f0-9\.:\/]/,
MacAddress: function(v) {
return (/^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/).test(v);
},

View File

@ -620,10 +620,12 @@ Ext.define('Proxmox.Utils', { utilities: {
var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
var IPV4_CIDR_MASK = "([0-9]{1,2})";
var IPV6_CIDR_MASK = "([0-9]{1,3})";
me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/" + IPV4_CIDR_MASK + "$");
var IPV6_REGEXP = "(?:" +
"(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
@ -638,10 +640,11 @@ Ext.define('Proxmox.Utils', { utilities: {
")";
me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/" + IPV6_CIDR_MASK + "$");
me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
me.IP64_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + "\/" + IPV6_CIDR_MASK + ")|(?:" + IPV4_REGEXP + "\/" + IPV4_CIDR_MASK + ")$");
var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");