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

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Jul 12 11:48:11 CEST 2016


On Thu, Jul 07, 2016 at 01:18:52PM +0200, Dominik Csapak wrote:
> 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

I'm not 100% convinced. If it's only triggered by key presses it should
still be fine, it's not *that* complex. After all the browser should
still be able to run the this thing a thousand times during just the
time you can hear the sound of the key being pressed.

Unless the previous version caused delays visible to the user? But then
I'd want to know why, as this should only take a split second...

The story would be different if the check was running permanently in the
background.

> 
> 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