Use read_file_as_text to valiate the private key

pull/26/head
Sheng 2018-08-23 22:47:37 +08:00
parent 6cfcaddadf
commit ee7fd101c6
1 changed files with 34 additions and 21 deletions

View File

@ -78,7 +78,7 @@ jQuery(function($){
try { try {
text = decoder.decode(reader.result); text = decoder.decode(reader.result);
} catch (TypeError) { } catch (TypeError) {
console.error('Decoding error happened.'); console.log('Decoding error happened.');
} finally { } finally {
if (callback) { if (callback) {
callback(text); callback(text);
@ -288,27 +288,7 @@ jQuery(function($){
port = data.get('port'), port = data.get('port'),
username = data.get('username'); username = data.get('username');
if (!hostname || !port || !username) { function ajax_post() {
status.text('Fields hostname, port and username are all required.');
return;
}
if (!hostname_tester.test(hostname)) {
status.text('Invalid hostname: ' + hostname);
return;
}
if (port <= 0 || port > 63335) {
status.text('Invalid port: ' + port);
return;
}
var pk = data.get('privatekey');
if (pk && pk.size > key_max_size) {
status.text('Invalid private key: ' + pk.name);
return;
}
store_items(names, data); store_items(names, data);
status.text(''); status.text('');
@ -325,6 +305,39 @@ jQuery(function($){
}); });
} }
if (!hostname || !port || !username) {
status.text('Fields hostname, port and username are all required.');
return;
}
if (!hostname_tester.test(hostname)) {
status.text('Invalid hostname: ' + hostname);
return;
}
if (port <= 0 || port > 63335) {
status.text('Invalid port: ' + port);
return;
}
var pk = data.get('privatekey');
if (pk) {
if (pk.size > key_max_size) {
status.text('Invalid private key: ' + pk.name);
} else {
read_file_as_text(pk, function(text) {
if (text === undefined) {
status.text('Invalid private key: ' + pk.name);
} else {
ajax_post();
}
});
}
} else {
ajax_post();
}
}
wssh.connect = connect; wssh.connect = connect;
$(form_id).submit(function(event){ $(form_id).submit(function(event){