mirror of https://github.com/huashengdun/webssh
Use read_file_as_text to valiate the private key
parent
6cfcaddadf
commit
ee7fd101c6
|
@ -78,7 +78,7 @@ jQuery(function($){
|
|||
try {
|
||||
text = decoder.decode(reader.result);
|
||||
} catch (TypeError) {
|
||||
console.error('Decoding error happened.');
|
||||
console.log('Decoding error happened.');
|
||||
} finally {
|
||||
if (callback) {
|
||||
callback(text);
|
||||
|
@ -288,27 +288,7 @@ jQuery(function($){
|
|||
port = data.get('port'),
|
||||
username = data.get('username');
|
||||
|
||||
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 && pk.size > key_max_size) {
|
||||
status.text('Invalid private key: ' + pk.name);
|
||||
return;
|
||||
}
|
||||
|
||||
function ajax_post() {
|
||||
store_items(names, data);
|
||||
|
||||
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;
|
||||
|
||||
$(form_id).submit(function(event){
|
||||
|
|
Loading…
Reference in New Issue