]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
add ipv6 and ipv4 cidr match vtype
authorMira Limbeck <m.limbeck@proxmox.com>
Mon, 15 Apr 2019 13:12:16 +0000 (15:12 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 16 Apr 2019 05:37:12 +0000 (05:37 +0000)
add additional vtype for combined ipv4 and ipv6 cidr validation.

Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
Toolkit.js
Utils.js

index cb37972294fe77092e1416b4858274324970b104..d5761743f00dda8ef18485e9ecc669ed3d63932e 100644 (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);
     },
index 93ccc0175f73e9c80729a5fbb53e34a82920b686..645c5250cf64803e280b466b9cd04309291f81f4 100644 (file)
--- 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 + "$");