]> git.proxmox.com Git - pve-manager.git/commitdiff
add HostList validator and check monhosts with it
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 12 Jul 2016 12:41:28 +0000 (14:41 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 15 Jul 2016 09:53:05 +0000 (11:53 +0200)
this adds a vtype which splits the given string into a list by
; or , or space
and checks if it is a valid (hostname|ip) port notation

also make the rbd monhost input field use it

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager6/Toolkit.js
www/manager6/Utils.js
www/manager6/storage/RBDEdit.js

index decaab6a737a4a8eaff588aafd4f7157ae7de783..7bef6f21245e292be2160458977fb04c35a7b713 100644 (file)
@@ -1,4 +1,5 @@
-/*global IP4_match, IP4_cidr_match, IP6_match, IP6_cidr_match, IP64_match, DnsName_match*/
+/*global IP4_match, IP4_cidr_match, IP6_match, IP6_cidr_match, IP64_match, DnsName_match, DnsName_REGEXP, IPV4_REGEXP, IPV6_REGEXP*/
+/*global HostPort_match, HostPortBrackets_match, IP6_dotnotation_match*/
 // ExtJS related things
 
 PVE.Utils.toolkit = 'extjs';
@@ -101,7 +102,26 @@ Ext.apply(Ext.form.field.VTypes, {
     pveMail: function(v) {
         return (/^(\w+)([\-+.][\w]+)*@(\w[\-\w]*\.){1,5}([A-Za-z]){2,63}$/).test(v);
     },
-    pveMailText: gettext('Example') + ": user@example.com"
+    pveMailText: gettext('Example') + ": user@example.com",
+
+    HostList: function(v) {
+       var list = v.split(/[\ \,\;]+/);
+       var i;
+       for (i = 0; i < list.length; i++) {
+           if (list[i] == "") {
+               continue;
+           }
+
+           if (!HostPort_match.test(list[i]) &&
+               !HostPortBrackets_match.test(list[i]) &&
+               !IP6_dotnotation_match.test(list[i])) {
+               return false;
+           }
+       }
+
+       return true;
+    },
+    HostListText: gettext('Not a valid list of hosts')
 });
 
 // ExtJs 5-6 has an issue with caching
index 7ed25603ac4d79d9552a4762e7ea23208126d64e..0182413391795899d8e6929631a9d47277d2e8e4 100644 (file)
@@ -59,6 +59,10 @@ var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
 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])?))";
 var DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
 
+var HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
+var HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
+var IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
+
 Ext.define('PVE.Utils', { statics: {
 
     // this class only contains static functions
index a38ea524f660bd0c49badc5117034f79d835b5b4..a046ec3ba05288145b7d9826750019833c6fedf4 100644 (file)
@@ -39,6 +39,7 @@ Ext.define('PVE.storage.RBDInputPanel', {
            {
                xtype: me.create ? 'textfield' : 'displayfield',
                name: 'monhost',
+               vtype: 'HostList',
                value: '',
                fieldLabel: gettext('Monitor Host'),
                allowBlank: false