From 368df92e0d7efd7661535f8b9f854f2cb8d2a159 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 28 Apr 2016 10:39:47 +0200 Subject: [PATCH] improve gui cidr matching 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 --- 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 a8089aa8..a701b8f0 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' + "
" + 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' + "
" + 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 c51fbcd7..cf296068 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 + ")$");