[pve-devel] [PATCH manager] improve gui cidr matching

Dominik Csapak d.csapak at proxmox.com
Thu Apr 28 10:39:47 CEST 2016


with this fix, we (again) allow ipv4 cidr to be as low as 8
also check the cidr for ipv6 and show the valid ranges in the
error text

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
sorry for the additional translation string, but in
my opinion, we should tell the user which ranges are valid

if someone has a better idea how we can display that, please
tell me :)
 www/manager6/Toolkit.js | 14 ++++++++++----
 www/manager6/Utils.js   |  4 ++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/www/manager6/Toolkit.js b/www/manager6/Toolkit.js
index a8089aa..a701b8f 100644
--- a/www/manager6/Toolkit.js
+++ b/www/manager6/Toolkit.js
@@ -14,9 +14,12 @@ Ext.apply(Ext.form.field.VTypes, {
     IPAddressMask: /[\d\.]/i,
 
     IPCIDRAddress:  function(v) {
-	return IP4_cidr_match.test(v);
+	var result = IP4_cidr_match.exec(v);
+	// limits according to JSON Schema see
+	// pve-common/src/PVE/JSONSchema.pm
+	return (result !== null && result[1] >= 8 && result[1] <= 32);
     },
-    IPCIDRAddressText:  gettext('Example') + ': 192.168.1.1/24',
+    IPCIDRAddressText:  gettext('Example') + ': 192.168.1.1/24' + "<br>" + gettext('Valid CIDR Range') + ': 8-32',
     IPCIDRAddressMask: /[\d\.\/]/i,
 
     IP6Address:  function(v) {
@@ -26,9 +29,12 @@ Ext.apply(Ext.form.field.VTypes, {
     IP6AddressMask: /[A-Fa-f0-9:]/,
 
     IP6CIDRAddress:  function(v) {
-	return IP6_cidr_match.test(v);
+	var result = IP6_cidr_match.exec(v);
+	// limits according to JSON Schema see
+	// pve-common/src/PVE/JSONSchema.pm
+	return (result !== null && result[1] >= 8 && result[1] <= 120);
     },
-    IP6CIDRAddressText:  gettext('Example') + ': 2001:DB8::42/64',
+    IP6CIDRAddressText:  gettext('Example') + ': 2001:DB8::42/64' + "<br>" + gettext('Valid CIDR Range') + ': 8-120',
     IP6CIDRAddressMask:  /[A-Fa-f0-9:\/]/,
 
     IP6PrefixLength:  function(v) {
diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index c51fbcd..cf29606 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -36,7 +36,7 @@ var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
 
 
 var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/[1-3][0-9]?$");
+var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
 
 var IPV6_REGEXP = "(?:" +
     "(?:(?:"                                                  + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
@@ -51,7 +51,7 @@ var IPV6_REGEXP = "(?:" +
     ")";
 
 var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/[0-9]{1,3}?$");
+var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
 var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
 
 var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
-- 
2.1.4




More information about the pve-devel mailing list