[pve-devel] [PATCH manager v2] add HostList validator and check monhosts with it

Dominik Csapak d.csapak at proxmox.com
Thu Jul 7 13:18:52 CEST 2016


this adds a vtype which splits the given string into a list by
; or , or space
and checks if only valid characters are in it
the real check has to be done on the host,
since the client check is run on every keystroke

also make the rbd monhost input field use it

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
i did not want to introduce a huge regex check for every
host here, as it gets executed with every keystroke

on the backend this check has to be done only once and
with a click on "OK" you should get the error from the backend
anyway

 www/manager6/Toolkit.js         | 21 ++++++++++++++++++++-
 www/manager6/storage/RBDEdit.js |  1 +
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/www/manager6/Toolkit.js b/www/manager6/Toolkit.js
index decaab6..bad51ac 100644
--- a/www/manager6/Toolkit.js
+++ b/www/manager6/Toolkit.js
@@ -101,7 +101,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 at example.com"
+    pveMailText: gettext('Example') + ": user at example.com",
+
+    HostList: function(v) {
+	var list = v.split(/[\ \,\;]+/);
+	var i;
+	for (i = 0; i < list.length; i++) {
+	    if (list[i] == "") {
+		continue;
+	    }
+
+	    // very simple check for valid characters,
+	    // backend has to do the real check
+	    if (!(/^[0-9a-zA-Z\-\.\:\]\[]+$/).test(list[i])) {
+		return false;
+	    }
+	}
+
+	return true;
+    },
+    HostListText: gettext('Not a valid list of hosts')
 });
 
 // ExtJs 5-6 has an issue with caching
diff --git a/www/manager6/storage/RBDEdit.js b/www/manager6/storage/RBDEdit.js
index a38ea52..a046ec3 100644
--- a/www/manager6/storage/RBDEdit.js
+++ b/www/manager6/storage/RBDEdit.js
@@ -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
-- 
2.1.4





More information about the pve-devel mailing list