webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit 9dec4af4b975fb612a6507d37df392efe1adead6
parent a8c6663344af1363a90edb8caefeb1a2f7b05b50
Author: Sheng <webmaster0115@gmail.com>
Date:   Mon, 19 Aug 2019 18:33:35 +0800

Updated validate_form_data to produce all the validation errors

Diffstat:
Mwebssh/static/js/main.js | 61+++++++++++++++++++++++++++++++++++--------------------------
1 file changed, 35 insertions(+), 26 deletions(-)

diff --git a/webssh/static/js/main.js b/webssh/static/js/main.js @@ -309,8 +309,8 @@ jQuery(function($){ function log_status(text) { - status.text(text); console.log(text); + status.html(text.split('\n').join('<br/>')); } @@ -558,34 +558,45 @@ jQuery(function($){ port = data.get('port'), username = data.get('username'), pk = data.get('privatekey'), - result = {'vaiid': false}, - msg, size; + result = { + valid: false, + title: '' + }, + errors = [], size; if (!hostname) { - msg = 'Need value hostname'; - } else if (!port) { + errors.push('Value of hostname is required.'); + } else { + if (!hostname_tester.test(hostname)) { + errors.push('Invalid hostname: ' + hostname); + } + } + + if (!port) { port = 22; - } else if (!username) { - msg = 'Need value username'; - } else if (!hostname_tester.test(hostname)) { - msg = 'Invalid hostname: ' + hostname; - } else if (port <= 0 || port > 65535) { - msg = 'Invalid port: ' + port; } else { - if (pk) { - size = pk.size || pk.length; - if (size > key_max_size) { - msg = 'Invalid private key: ' + pk.name || pk; - } + if (!(port > 0 && port < 65535)) { + errors.push('Invalid port: ' + port); } } - if (!msg || debug) { + if (!username) { + errors.push('Value of username is required.'); + } + + if (pk) { + size = pk.size || pk.length; + if (size > key_max_size) { + errors.push('Invalid private key: ' + pk.name || ''); + } + } + + if (!errors.length || debug) { result.valid = true; - msg = username + '@' + hostname + ':' + port; + result.title = username + '@' + hostname + ':' + port; } + result.errors = errors; - result.msg = msg; return result; } @@ -642,7 +653,7 @@ jQuery(function($){ var result = validate_form_data(data); if (!result.valid) { - log_status(result.msg); + log_status(result.errors.join('\n')); return; } @@ -658,7 +669,7 @@ jQuery(function($){ ajax_post(); } - return result.msg; + return result.title; } @@ -671,7 +682,7 @@ jQuery(function($){ var result = validate_form_data(data_wrapped); if (!result.valid) { - console.log(result.msg); + log_status(result.errors.join('\n')); return; } @@ -690,7 +701,7 @@ jQuery(function($){ complete: ajax_complete_callback }); - return result.msg; + return result.title; } @@ -792,10 +803,8 @@ jQuery(function($){ if (url_form_data.password === undefined) { log_status('Password via url must be encoded in base64.'); } else { - if (url_form_data.hostname && url_form_data.username) { + if (url_form_data.hostname || url_form_data.port || url_form_data.username || url_form_data.password || url_form_data.totp) { connect(url_form_data); - } else { - console.log('Values of hostname and username are required.'); } }