mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added SSH key auth and remember to agent Win-SSH link, #3108
This commit is contained in:
parent
e25cec9c5e
commit
a928d3cada
3 changed files with 132 additions and 29 deletions
|
@ -92,7 +92,12 @@
|
|||
|
||||
// Update the terminal status and buttons
|
||||
updateState();
|
||||
resetTerminal();
|
||||
|
||||
connectButton();
|
||||
}
|
||||
|
||||
function resetTerminal() {
|
||||
// Setup the terminal with auto-fit
|
||||
if (term != null) { term.dispose(); }
|
||||
if (urlargs.fixsize != 1) { termfit = new FitAddon.FitAddon(); }
|
||||
|
@ -107,8 +112,6 @@
|
|||
resizeTimer = setTimeout(sendResize, 200);
|
||||
});
|
||||
//term.setOption('convertEol', true); // Consider \n to be \r\n, this should be taken care of by "termios"
|
||||
|
||||
connectButton();
|
||||
}
|
||||
|
||||
// Send the new terminal size to the agent
|
||||
|
@ -119,24 +122,47 @@
|
|||
|
||||
function connectButton() {
|
||||
if (state == 0) {
|
||||
var x = '';
|
||||
x += addHtmlValue("Username", '<input id=dp2user style=width:230px maxlength=64 autocomplete=off onkeyup=authKeyUp(event) />');
|
||||
x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:230px maxlength=64 autocomplete=off onkeyup=authKeyUp(event) />');
|
||||
setDialogMode(2, "Authentication", 3, connectEx, x);
|
||||
Q('dp2user').value = user;
|
||||
Q('dp2pass').value = pass;
|
||||
if (user == '') { Q('dp2user').focus(); } else { Q('dp2pass').focus(); }
|
||||
setTimeout(authKeyUp, 50);
|
||||
connectEx2({ action: 'connect', cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight, useexisting: true });
|
||||
} else {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
function authKeyUp(e) { QE('idx_dlgOkButton', (Q('dp2user').value.length > 0) && (Q('dp2pass').value.length > 0)); }
|
||||
function sshAuthUpdate(e) {
|
||||
QV('d2passauth', Q('dp2authmethod').value == 1);
|
||||
QV('d2keyauth', Q('dp2authmethod').value == 2);
|
||||
if (Q('dp2authmethod').value == 1) {
|
||||
QE('idx_dlgOkButton', (Q('dp2user').value.length > 0) && (Q('dp2pass').value.length > 0));
|
||||
} else {
|
||||
QE('idx_dlgOkButton', false);
|
||||
var ok = (Q('dp2user').value.length > 0) && (Q('dp2key').files != null) && (Q('dp2key').files.length == 1) && (Q('dp2key').files[0].size < 8000);
|
||||
if (ok == true) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) {
|
||||
var validkey = ((e.target.result.indexOf('-----BEGIN OPENSSH PRIVATE KEY-----') >= 0) && (e.target.result.indexOf('-----END OPENSSH PRIVATE KEY-----') >= 0));
|
||||
QE('idx_dlgOkButton', validkey);
|
||||
QS('d2badkey')['color'] = validkey ? '#000' : '#F00';
|
||||
}
|
||||
reader.readAsText(Q('dp2key').files[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function connectEx() {
|
||||
user = Q('dp2user').value;
|
||||
pass = Q('dp2pass').value;
|
||||
var cmd = { action: 'connect', cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight, username: Q('dp2user').value, keep: Q('dp2keep').checked };
|
||||
|
||||
if (Q('dp2authmethod').value == 1) {
|
||||
cmd.password = Q('dp2pass').value;
|
||||
connectEx2(cmd);
|
||||
} else {
|
||||
cmd.keypass = Q('dp2keypass').value;
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) { cmd.key = e.target.result; connectEx2(cmd); }
|
||||
reader.readAsText(Q('dp2key').files[0]);
|
||||
}
|
||||
}
|
||||
|
||||
function connectEx2(cmd) {
|
||||
state = 1;
|
||||
var url = window.location.protocol.replace('http', 'ws') + '//' + window.location.host + domainurl + 'sshrelay.ashx?auth=' + cookie + (urlargs.key ? ('&key=' + urlargs.key) : '');
|
||||
socket = new WebSocket(url);
|
||||
|
@ -146,7 +172,7 @@
|
|||
term.reset();
|
||||
|
||||
// Send username and terminal width and height
|
||||
socket.send(JSON.stringify({ action: 'connect', username: user, password: pass, cols: term.cols, rows: term.rows, width: Q('terminal').offsetWidth, height: Q('terminal').offsetHeight }));
|
||||
socket.send(JSON.stringify(cmd));
|
||||
pass = '';
|
||||
}
|
||||
socket.onmessage = function (data) {
|
||||
|
@ -155,8 +181,27 @@
|
|||
var json = JSON.parse(data.data);
|
||||
switch (json.action) {
|
||||
case 'connected': { state = 3; updateState(); term.focus(); break; }
|
||||
case 'sshauth': {
|
||||
var x = '';
|
||||
x += addHtmlValue("Authentication", '<select id=dp2authmethod style=width:230px onchange=sshAuthUpdate(event)><option value=1 selected>' + "Username & Password" + '</option><option value=2>' + "Username and Key" + '</option></select>')
|
||||
x += addHtmlValue("Username", '<input id=dp2user style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />');
|
||||
x += '<div id=d2passauth>';
|
||||
x += addHtmlValue("Password", '<input type=password id=dp2pass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />');
|
||||
x += '</div><div id=d2keyauth style=display:none>';
|
||||
x += addHtmlValue("Key File", '<input type=file id=dp2key style=width:230px maxlength=64 autocomplete=off onchange=sshAuthUpdate(event) />' + '<div id=d2badkey style=font-size:x-small>' + "Key file must be in OpenSSH format." + '</div>');
|
||||
x += addHtmlValue("Key Password", '<input type=password id=dp2keypass style=width:230px maxlength=64 autocomplete=off onkeyup=sshAuthUpdate(event) />');
|
||||
x += '</div>';
|
||||
x += addHtmlValue('', '<label><input id=dp2keep type=checkbox>' + "Remember credentials" + '</label>');
|
||||
setDialogMode(2, "Authentication", 3, connectEx, x);
|
||||
Q('dp2user').value = user;
|
||||
Q('dp2pass').value = pass;
|
||||
if (user == '') { Q('dp2user').focus(); } else { Q('dp2pass').focus(); }
|
||||
setTimeout(sshAuthUpdate, 50);
|
||||
break;
|
||||
}
|
||||
case 'autherror': { setDialogMode(2, "Authentication", 1, null, "Unable to authenticate."); break; }
|
||||
case 'sessionerror': { setDialogMode(2, "Session", 1, null, "Session expired."); break; }
|
||||
case 'sessiontimeout': { setDialogMode(2, "Session", 1, null, "Session timeout."); break; }
|
||||
}
|
||||
} else if (data.data[0] == '~') {
|
||||
term.writeUtf8(data.data.substring(1));
|
||||
|
@ -171,6 +216,7 @@
|
|||
if (socket != null) { socket.close(); socket = null; }
|
||||
state = 0;
|
||||
updateState();
|
||||
resetTerminal();
|
||||
}
|
||||
|
||||
function updateState() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue