Added SSH,SFTP to agent devices, #3969

This commit is contained in:
Ylian Saint-Hilaire 2022-05-13 13:06:36 -07:00
parent 37b698a633
commit e2bcfc96db

View File

@ -743,7 +743,7 @@
<div id="terminalCustomUiButtons" style="float:left"></div> <div id="terminalCustomUiButtons" style="float:left"></div>
</div> </div>
<div> <div>
<input type="button" id="autoconnectbutton2" value="AutoConnect" onclick=autoConnectTerminal(event) onkeypress="return false" onkeydown="return false" style="display:none" /><span id="connectbutton2span" style="margin-right:4px"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span><span id="connectbutton2hspan" style="margin-right:4px"><input type="button" id="connectbutton2h" value="HW Connect" title="Connect using Intel&reg; AMT hardware KVM" onclick=connectTerminal(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span><span id="disconnectbutton2span" style="margin-right:4px"><input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span> <input type="button" id="autoconnectbutton2" value="AutoConnect" onclick=autoConnectTerminal(event) onkeypress="return false" onkeydown="return false" style="display:none" /><span id="connectbutton2span" style="margin-right:4px"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span><span id="connectbutton2sspan" style="margin-right:4px"><input type="button" id="connectbutton2s" cmenu=sshPortContextMenu value="SSH Connect" onclick=connectTerminal(event,3) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span><span id="connectbutton2hspan" style="margin-right:4px"><input type="button" id="connectbutton2h" value="HW Connect" title="Connect using Intel&reg; AMT hardware KVM" onclick=connectTerminal(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span><span id="disconnectbutton2span" style="margin-right:4px"><input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span>
<span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span> <span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span>
</div> </div>
</td> </td>
@ -801,7 +801,9 @@
</div> </div>
<div> <div>
<input id=p13AutoConnect value="AutoConnect" onclick=autoConnectFiles(event) type="button" style="display:none" /> <input id=p13AutoConnect value="AutoConnect" onclick=autoConnectFiles(event) type="button" style="display:none" />
<input id=p13Connect value="Connect" onclick=connectFiles(event) type="button" /> <input id=p13Connect value="Connect" onclick=connectFiles(event,1) type="button" />
<input id=p13Connects value="SFTP Connect" cmenu=sshPortContextMenu onclick=connectFiles(event,2) type="button" />
<input id=p13Disconnect value="Disconnect" onclick=connectFiles(event) type="button" />
<span id=p13Status>Disconnected</span> <span id=p13Status>Disconnected</span>
</div> </div>
</td> </td>
@ -2722,7 +2724,6 @@
if (message.localport) { url += '&localport=' + message.localport; } if (message.localport) { url += '&localport=' + message.localport; }
if (message.ip != null) { url += ('&remoteip=' + message.ip); } if (message.ip != null) { url += ('&remoteip=' + message.ip); }
url += ('&appid=' + message.protocol + '&autoexit=1'); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP, 6 = MCRDesktop, 7 = MCRFiles url += ('&appid=' + message.protocol + '&autoexit=1'); // Protocol: 0 = Custom, 1 = HTTP, 2 = HTTPS, 3 = RDP, 4 = PuTTY, 5 = WinSCP, 6 = MCRDesktop, 7 = MCRFiles
console.log(url);
downloadFile(url, ''); downloadFile(url, '');
} else if (message.tag == 'novnc') { } else if (message.tag == 'novnc') {
var vncurl = window.location.origin + domainUrl + 'novnc/vnc.html?ws=wss%3A%2F%2F' + window.location.host + encodeURIComponentEx(domainUrl) + (message.localRelay?'local':'mesh') + 'relay.ashx%3Fauth%3D' + message.cookie + '&show_dot=1' + (urlargs.key?('&key=' + urlargs.key):'') + '&l={{{lang}}}'; var vncurl = window.location.origin + domainUrl + 'novnc/vnc.html?ws=wss%3A%2F%2F' + window.location.host + encodeURIComponentEx(domainUrl) + (message.localRelay?'local':'mesh') + 'relay.ashx%3Fauth%3D' + message.cookie + '&show_dot=1' + (urlargs.key?('&key=' + urlargs.key):'') + '&l={{{lang}}}';
@ -9557,7 +9558,8 @@
// Show the right buttons // Show the right buttons
QV('disconnectbutton2span', (termState == true)); QV('disconnectbutton2span', (termState == true));
QV('connectbutton2span', (termState == false) && (terminalNode.agent != null) && (terminalNode.agent.caps & 2)); QV('connectbutton2span', (termState == false) && (terminalNode.agent != null) && (terminalNode.agent.caps & 2) && (terminalNode.mtype != 3));
QV('connectbutton2sspan', (termState == false) && (terminalNode.agent != null) && (terminalNode.agent.caps & 2) && (terminalNode.agent.id != 3) && (terminalNode.agent.id != 4));
if (terminalNode.mtype == 1) { if (terminalNode.mtype == 1) {
QV('connectbutton2hspan', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2)); QV('connectbutton2hspan', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2));
QV('terminalSizeDropDown', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2)); QV('terminalSizeDropDown', (termState == false) && (terminalNode.intelamt != null) && (terminalNode.intelamt.state == 2));
@ -9568,7 +9570,7 @@
// Enable action button if mesh type is not "local devices" // Enable action button if mesh type is not "local devices"
QV('termActionsBtn', terminalNode.mtype != 3); QV('termActionsBtn', terminalNode.mtype != 3);
if (terminalNode.mtype != 3) { if (((termState == true) && (terminal.contype != 3)) || (terminalNode.agent.id == 3) || (terminalNode.agent.id == 4)) {
QH('terminalCustomUpperRight', ''); QH('terminalCustomUpperRight', '');
} else { } else {
QH('terminalCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (terminalNode.sshport?terminalNode.sshport:22)) + '</a>'); QH('terminalCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (terminalNode.sshport?terminalNode.sshport:22)) + '</a>');
@ -9577,6 +9579,7 @@
// Enable buttons // Enable buttons
var online = ((terminalNode.conn & 1) != 0) || (terminalNode.mtype == 3); // If Agent (1) connected, enable Terminal var online = ((terminalNode.conn & 1) != 0) || (terminalNode.mtype == 3); // If Agent (1) connected, enable Terminal
QE('connectbutton2', online); QE('connectbutton2', online);
QE('connectbutton2s', online);
var hwonline = ((terminalNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal var hwonline = ((terminalNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
QE('connectbutton2h', hwonline); QE('connectbutton2h', hwonline);
@ -9612,7 +9615,10 @@
var xstate = state; var xstate = state;
if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; } if ((xstate == 3) && (xterminal.contype == 2)) { xstate++; }
var str = StatusStrs[xstate]; var str = StatusStrs[xstate];
if (terminal.webRtcActive == true) { str += ", WebRTC"; } if (xstate == 3) {
if (terminal.contype == 3) { str += ", SSH"; }
if (terminal.webRtcActive == true) { str += ", WebRTC"; }
}
QH('termstatus', str); QH('termstatus', str);
switch (state) { switch (state) {
case 0: case 0:
@ -9777,6 +9783,7 @@
} }
} }
// contype: 1 = Agent, 2 = AMT, 3 = SSH
function connectTerminal(e, contype, options) { function connectTerminal(e, contype, options) {
p12clearConsoleMsg(); p12clearConsoleMsg();
if (!terminal) { if (!terminal) {
@ -9853,8 +9860,8 @@
}); });
// Setup a terminal tunnel to the agent // Setup a terminal tunnel to the agent
terminal = CreateAgentRedirect(meshserver, CreateRemoteTunnel((currentNode.mtype == 3)? sshTunnelUpdate : tunnelUpdate, termoptions), serverPublicNamePort, authCookie, authRelayCookie, domainUrl); terminal = CreateAgentRedirect(meshserver, CreateRemoteTunnel((contype == 3)? sshTunnelUpdate : tunnelUpdate, termoptions), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
if (currentNode.mtype == 3) { terminal.urlname = 'sshterminalrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay. if (contype == 3) { terminal.urlname = 'sshterminalrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
terminal.debugmode = debugmode; terminal.debugmode = debugmode;
terminal.m.debugmode = debugmode; terminal.m.debugmode = debugmode;
terminal.options = termoptions; terminal.options = termoptions;
@ -9862,7 +9869,7 @@
if (termoptions.requireLogin) { terminal.options.requireLogin = true; } if (termoptions.requireLogin) { terminal.options.requireLogin = true; }
terminal.Start(terminalNode._id); terminal.Start(terminalNode._id);
terminal.onStateChanged = onTerminalStateChange; terminal.onStateChanged = onTerminalStateChange;
terminal.contype = 1; terminal.contype = contype;
terminal.attemptWebRTC = false; // Never do WebRTC on terminal, because of a race condition we can't do it. terminal.attemptWebRTC = false; // Never do WebRTC on terminal, because of a race condition we can't do it.
terminal.onConsoleMessageChange = function () { p12setConsoleMsg(terminal.consoleMessage ? formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs) : null, terminal.consoleMessageTimeout); } terminal.onConsoleMessageChange = function () { p12setConsoleMsg(terminal.consoleMessage ? formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs) : null, terminal.consoleMessageTimeout); }
} else { } else {
@ -9880,7 +9887,7 @@
terminal.onStateChanged = onTerminalStateChange; terminal.onStateChanged = onTerminalStateChange;
terminal.onConsoleMessageChange = function () { p12setConsoleMsg(terminal.consoleMessage ? formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs) : null, terminal.consoleMessageTimeout); } terminal.onConsoleMessageChange = function () { p12setConsoleMsg(terminal.consoleMessage ? formatAgentConsoleMessage(terminal.consoleMessage, terminal.consoleMessageId, terminal.consoleMessageArgs) : null, terminal.consoleMessageTimeout); }
terminal.Start(terminalNode._id); terminal.Start(terminalNode._id);
terminal.contype = 1; terminal.contype = contype;
terminal.m.terminalEmulation = 0; terminal.m.terminalEmulation = 0;
terminal.m.fxEmulation = 0; terminal.m.fxEmulation = 0;
Q('id_ttypebutton').value = terminalEmulations[0]; Q('id_ttypebutton').value = terminalEmulations[0];
@ -9980,14 +9987,24 @@
filesNode = currentNode; filesNode = currentNode;
var online = ((filesNode.conn & 1) != 0) || (filesNode.mtype == 3); // If Agent (1) connected, enable Terminal var online = ((filesNode.conn & 1) != 0) || (filesNode.mtype == 3); // If Agent (1) connected, enable Terminal
QE('p13Connect', online); QE('p13Connect', online);
QE('p13Connects', online);
QV('p13Connect', files == null);
QV('p13Connects', (files == null) && (filesNode.agent != null) && (filesNode.agent.id != 3) && (filesNode.agent.id != 4));
QV('p13Disconnect', files != null);
if (((samenode == false) || (online == false)) && files) { files.Stop(); files = null; } if (((samenode == false) || (online == false)) && files) { files.Stop(); files = null; }
p13setActions(); p13setActions();
} }
function onFilesStateChange(xfiles, state) { function onFilesStateChange(xfiles, state) {
p13Connect.value = (state == 0) ? "Connect" : "Disconnect"; QV('p13Connect', state == 0);
QV('p13Connects', state == 0);
QV('p13Disconnect', state != 0);
//p13Connect.value = (state == 0) ? "Connect" : "Disconnect";
var str = StatusStrs[state]; var str = StatusStrs[state];
if (files.webRtcActive == true) { str += ", WebRTC"; } if (state == 3) {
if (files.contype == 2) { str += ", SFTP"; }
if (files.webRtcActive == true) { str += ", WebRTC"; }
}
Q('p13Status').textContent = str; Q('p13Status').textContent = str;
switch (state) { switch (state) {
case 0: case 0:
@ -10033,12 +10050,14 @@
var autoConnectFilesTimer = null; var autoConnectFilesTimer = null;
function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } } function autoConnectFiles(e) { if (autoConnectFilesTimer == null) { autoConnectFilesTimer = setInterval(connectFiles, 100); } else { clearInterval(autoConnectFilesTimer); autoConnectFilesTimer = null; } }
function connectFiles(e) { // 1 = Agent, 2 = SFTP
function connectFiles(e, contype) {
p13clearConsoleMsg(); p13clearConsoleMsg();
if (!files) { if (!files) {
// Setup a mesh agent files // Setup a mesh agent files
files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, authRelayCookie, domainUrl); files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
if (filesNode.mtype == 3) { files.urlname = 'sshfilesrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay. if (contype == 2) { files.urlname = 'sshfilesrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
files.contype = contype;
files.attemptWebRTC = attemptWebRTC; files.attemptWebRTC = attemptWebRTC;
files.onStateChanged = onFilesStateChange; files.onStateChanged = onFilesStateChange;
files.onConsoleMessageChange = function () { files.onConsoleMessageChange = function () {
@ -10340,7 +10359,8 @@
QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false))); QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0))); QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
} }
if (filesNode.mtype != 3) { var filesState = ((files != null) && (files.state != 0));
if (((filesState == true) && (files.contype != 2)) || (filesNode.agent.id == 3) || (filesNode.agent.id == 4)) {
QH('filesCustomUpperRight', ''); QH('filesCustomUpperRight', '');
} else { } else {
QH('filesCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (filesNode.sshport?filesNode.sshport:22)) + '</a>'); QH('filesCustomUpperRight', '<a style=cursor:pointer onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (filesNode.sshport?filesNode.sshport:22)) + '</a>');