mirror of https://github.com/huashengdun/webssh
Use read_file_as_text to valiate the private key
parent
6cfcaddadf
commit
ee7fd101c6
|
@ -73,12 +73,12 @@ jQuery(function($){
|
||||||
decoder = new window.TextDecoder('utf-8', {'fatal': true});
|
decoder = new window.TextDecoder('utf-8', {'fatal': true});
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.onload = function () {
|
reader.onload = function() {
|
||||||
var text;
|
var text;
|
||||||
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);
|
||||||
|
@ -161,7 +161,7 @@ jQuery(function($){
|
||||||
decoder = new window.TextDecoder(new_encoding);
|
decoder = new window.TextDecoder(new_encoding);
|
||||||
encoding = new_encoding;
|
encoding = new_encoding;
|
||||||
console.log('Set encoding to ' + encoding);
|
console.log('Set encoding to ' + encoding);
|
||||||
} catch(RangeError) {
|
} catch (RangeError) {
|
||||||
console.log('Unknown encoding ' + new_encoding);
|
console.log('Unknown encoding ' + new_encoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -288,6 +288,23 @@ jQuery(function($){
|
||||||
port = data.get('port'),
|
port = data.get('port'),
|
||||||
username = data.get('username');
|
username = data.get('username');
|
||||||
|
|
||||||
|
function ajax_post() {
|
||||||
|
store_items(names, data);
|
||||||
|
|
||||||
|
status.text('');
|
||||||
|
btn.prop('disabled', true);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: url,
|
||||||
|
type: 'post',
|
||||||
|
data: data,
|
||||||
|
complete: callback,
|
||||||
|
cache: false,
|
||||||
|
contentType: false,
|
||||||
|
processData: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!hostname || !port || !username) {
|
if (!hostname || !port || !username) {
|
||||||
status.text('Fields hostname, port and username are all required.');
|
status.text('Fields hostname, port and username are all required.');
|
||||||
return;
|
return;
|
||||||
|
@ -304,25 +321,21 @@ jQuery(function($){
|
||||||
}
|
}
|
||||||
|
|
||||||
var pk = data.get('privatekey');
|
var pk = data.get('privatekey');
|
||||||
if (pk && pk.size > key_max_size) {
|
if (pk) {
|
||||||
status.text('Invalid private key: ' + pk.name);
|
if (pk.size > key_max_size) {
|
||||||
return;
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
store_items(names, data);
|
|
||||||
|
|
||||||
status.text('');
|
|
||||||
btn.prop('disabled', true);
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: 'post',
|
|
||||||
data: data,
|
|
||||||
complete: callback,
|
|
||||||
cache: false,
|
|
||||||
contentType: false,
|
|
||||||
processData: false
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wssh.connect = connect;
|
wssh.connect = connect;
|
||||||
|
|
Loading…
Reference in New Issue