[pve-devel] [PATCH widget-toolkit 1/1] add ipv6 and ipv4 cidr match vtype

Mira Limbeck m.limbeck at proxmox.com
Mon Apr 15 15:12:16 CEST 2019


add additional vtype for combined ipv4 and ipv6 cidr validation.

Signed-off-by: Mira Limbeck <m.limbeck at proxmox.com>
---
 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 + "$");
-- 
2.11.0





More information about the pve-devel mailing list