From 577b6c7546c5861ea7c0bd46b07825cd1b55c3cb Mon Sep 17 00:00:00 2001 From: Mira Limbeck Date: Mon, 15 Apr 2019 15:12:16 +0200 Subject: [PATCH] add ipv6 and ipv4 cidr match vtype add additional vtype for combined ipv4 and ipv6 cidr validation. Signed-off-by: Mira Limbeck --- Toolkit.js | 16 ++++++++++++++++ Utils.js | 7 +++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Toolkit.js b/Toolkit.js index cb37972..d576174 100644 --- a/Toolkit.js +++ b/Toolkit.js @@ -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); }, diff --git a/Utils.js b/Utils.js index 93ccc01..645c525 100644 --- a/Utils.js +++ b/Utils.js @@ -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 + "$");