Partial SSH file support for local device group.

Ylian Saint-Hilaire committed May 24, 2021 at 15:26 UTC ded4d61f85ef2fa6542926d3453961a0fa3227da
3 files changed +378 -21
apprelays.js
+339 -1
@@ -294,7 +294,6 @@ module.exports.CreateSshRelay = function (parent, db, ws, req, args, domain) {
294 // When data is received from the web socket
295 // SSH default port is 22
296 ws.on('message', function (msg) {
297 - console.log('message', msg);
297 try {
298 if (typeof msg != 'string') return;
299 if (msg[0] == '{') {
@@ -592,3 +591,342 @@ module.exports.CreateSshTerminalRelay = function (parent, db, ws, req, domain, u
591
592 return obj;
593 };
594 +
595 +
596 +
597 +// Construct a SSH Files Relay object, called upon connection
598 +module.exports.CreateSshFilesRelay = function (parent, db, ws, req, domain, user, cookie, args) {
599 + const Net = require('net');
600 + const WebSocket = require('ws');
601 +
602 + // SerialTunnel object is used to embed SSH within another connection.
603 + function SerialTunnel(options) {
604 + var obj = new require('stream').Duplex(options);
605 + obj.forwardwrite = null;
606 + obj.updateBuffer = function (chunk) { this.push(chunk); };
607 + obj._write = function (chunk, encoding, callback) { if (obj.forwardwrite != null) { obj.forwardwrite(chunk); } if (callback) callback(); }; // Pass data written to forward
608 + obj._read = function (size) { }; // Push nothing, anything to read should be pushed from updateBuffer()
609 + obj.destroy = function () { delete obj.forwardwrite; }
610 + return obj;
611 + }
612 +
613 + const obj = {};
614 + obj.ws = ws;
615 + obj.path = require('path');
616 + obj.relayActive = false;
617 + obj.firstMessage = true;
618 +
619 + parent.parent.debug('relay', 'SSH: Request for SSH files relay (' + req.clientIp + ')');
620 +
621 + // Disconnect
622 + obj.close = function (arg) {
623 + if (obj.ws == null) return;
624 +
625 + // Collect how many raw bytes where received and sent.
626 + // We sum both the websocket and TCP client in this case.
627 + //var inTraffc = obj.ws._socket.bytesRead, outTraffc = obj.ws._socket.bytesWritten;
628 + //if (obj.wsClient != null) { inTraffc += obj.wsClient._socket.bytesRead; outTraffc += obj.wsClient._socket.bytesWritten; }
629 + //console.log('WinSSH - in', inTraffc, 'out', outTraffc);
630 +
631 + if (obj.sshClient) {
632 + obj.sshClient.destroy();
633 + obj.sshClient.removeAllListeners('ready');
634 + try { obj.sshClient.end(); } catch (ex) { console.log(ex); }
635 + delete obj.sshClient;
636 + }
637 + if (obj.wsClient) {
638 + obj.wsClient.removeAllListeners('open');
639 + obj.wsClient.removeAllListeners('message');
640 + obj.wsClient.removeAllListeners('close');
641 + try { obj.wsClient.close(); } catch (ex) { console.log(ex); }
642 + delete obj.wsClient;
643 + }
644 +
645 + if ((arg == 1) || (arg == null)) { try { ws.close(); } catch (ex) { console.log(ex); } } // Soft close, close the websocket
646 + if (arg == 2) { try { ws._socket._parent.end(); } catch (ex) { console.log(ex); } } // Hard close, close the TCP socket
647 + obj.ws.removeAllListeners();
648 +
649 + obj.relayActive = false;
650 + delete obj.cookie;
651 + delete obj.sftp;
652 + delete obj.ws;
653 + };
654 +
655 + // Save SSH credentials into device
656 + function saveSshCredentials() {
657 + parent.parent.db.Get(obj.nodeid, function (err, nodes) {
658 + if ((err != null) || (nodes == null) || (nodes.length != 1)) return;
659 + const node = nodes[0];
660 + const changed = (node.ssh == null);
661 +
662 + // Save the credentials
663 + node.ssh = { u: obj.username, p: obj.password };
664 + parent.parent.db.Set(node);
665 +
666 + // Event node change if needed
667 + if (changed) {
668 + // Event the node change
669 + var event = { etype: 'node', action: 'changenode', nodeid: obj.nodeid, domain: domain.id, userid: user._id, username: user.name, node: parent.CloneSafeNode(node), msg: "Changed SSH credentials" };
670 + if (parent.parent.db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
671 + parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(node.meshid, [obj.nodeid]), obj, event);
672 + }
673 + });
674 + }
675 +
676 + // Start the looppback server
677 + function startRelayConnection(authCookie) {
678 + try {
679 + // Setup the correct URL with domain and use TLS only if needed.
680 + var options = { rejectUnauthorized: false };
681 + if (domain.dns != null) { options.servername = domain.dns; }
682 + var protocol = 'wss';
683 + if (args.tlsoffload) { protocol = 'ws'; }
684 + var domainadd = '';
685 + if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
686 + var url = protocol + '://127.0.0.1:' + args.port + '/' + domainadd + ((obj.mtype == 3) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=11&auth=' + authCookie // Protocol 11 is Web-SSH
687 + parent.parent.debug('relay', 'SSH: Connection websocket to ' + url);
688 + obj.wsClient = new WebSocket(url, options);
689 + obj.wsClient.on('open', function () { parent.parent.debug('relay', 'SSH: Relay websocket open'); });
690 + obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
691 + if ((obj.relayActive == false) && (data == 'c')) {
692 + obj.relayActive = true;
693 +
694 + // Create a serial tunnel && SSH module
695 + obj.ser = new SerialTunnel();
696 + const Client = require('ssh2').Client;
697 + obj.sshClient = new Client();
698 + obj.sshClient.on('ready', function () { // Authentication was successful.
699 + // If requested, save the credentials
700 + if (obj.keep === true) saveSshCredentials();
701 + obj.sshClient.sftp(function(err, sftp) {
702 + if (err) { obj.close(); return; }
703 + obj.sftp = sftp;
704 + obj.ws.send('c');
705 + });
706 + });
707 + obj.sshClient.on('error', function (err) {
708 + if (err.level == 'client-authentication') { try { obj.ws.send(JSON.stringify({ action: 'autherror' })); } catch (ex) { } }
709 + if (err.level == 'client-timeout') { try { obj.ws.send(JSON.stringify({ action: 'sessiontimeout' })); } catch (ex) { } }
710 + obj.close();
711 + });
712 +
713 + // Setup the serial tunnel, SSH ---> Relay WS
714 + obj.ser.forwardwrite = function (data) { if ((data.length > 0) && (obj.wsClient != null)) { try { obj.wsClient.send(data); } catch (ex) { } } };
715 +
716 + // Connect the SSH module to the serial tunnel
717 + var connectionOptions = { sock: obj.ser }
718 + if (typeof obj.username == 'string') { connectionOptions.username = obj.username; }
719 + if (typeof obj.password == 'string') { connectionOptions.password = obj.password; }
720 + obj.sshClient.connect(connectionOptions);
721 +
722 + // We are all set, start receiving data
723 + ws._socket.resume();
724 + } else {
725 + // Relay WS --> SSH
726 + if ((data.length > 0) && (obj.ser != null)) { try { obj.ser.updateBuffer(data); } catch (ex) { console.log(ex); } }
727 + }
728 + });
729 + obj.wsClient.on('close', function () { parent.parent.debug('relay', 'SSH: Files relay websocket closed'); obj.close(); });
730 + obj.wsClient.on('error', function (err) { parent.parent.debug('relay', 'SSH: Files relay websocket error: ' + err); obj.close(); });
731 + } catch (ex) {
732 + console.log(ex);
733 + }
734 + }
735 +
736 + // When data is received from the web socket
737 + // SSH default port is 22
738 + ws.on('message', function (msg) {
739 + if ((obj.firstMessage === true) && (msg != 5)) { obj.close(); return; } else { delete obj.firstMessage; }
740 + try {
741 + if (typeof msg != 'string') {
742 + if (msg[0] == 123) {
743 + msg = msg.toString();
744 + } else if ((obj.sftp != null) && (obj.uploadHandle != null)) {
745 + var off = (msg[0] == 0) ? 1 : 0;
746 + obj.sftp.write(obj.uploadHandle, msg, off, msg.length - off, obj.uploadPosition, function (err) {
747 + if (err != null) {
748 + obj.sftp.close(obj.uploadHandle, function () { });
749 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploaddone', reqid: obj.uploadReqid }))) } catch (ex) { }
750 + delete obj.uploadHandle;
751 + delete obj.uploadFullpath;
752 + delete obj.uploadSize;
753 + delete obj.uploadReqid;
754 + delete obj.uploadPosition;
755 + } else {
756 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploadack', reqid: obj.uploadReqid }))) } catch (ex) { }
757 + }
758 + });
759 + obj.uploadPosition += (msg.length - off);
760 + return;
761 + }
762 + }
763 + if (msg[0] == '{') {
764 + // Control data
765 + msg = JSON.parse(msg);
766 + if (typeof msg.action != 'string') return;
767 + switch (msg.action) {
768 + case 'ls': {
769 + if (obj.sftp == null) return;
770 + var requestedPath = msg.path;
771 + if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
772 + obj.sftp.readdir(requestedPath, function(err, list) {
773 + if (err) { console.log(err); obj.close(); }
774 + var r = { path: requestedPath, reqid: msg.reqid, dir: [] };
775 + for (var i in list) {
776 + var file = list[i];
777 + if (file.longname[0] == 'd') { r.dir.push({ t: 2, n: file.filename, d: new Date(file.attrs.mtime * 1000).toISOString() }); }
778 + else { r.dir.push({ t: 3, n: file.filename, d: new Date(file.attrs.mtime * 1000).toISOString(), s: file.attrs.size }); }
779 + }
780 + try { obj.ws.send(Buffer.from(JSON.stringify(r))) } catch (ex) { }
781 + });
782 + break;
783 + }
784 + case 'mkdir': {
785 + if (obj.sftp == null) return;
786 + var requestedPath = msg.path;
787 + if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
788 + obj.sftp.mkdir(requestedPath, function (err) { console.log(err); });
789 + break;
790 + }
791 + case 'rm': {
792 + if (obj.sftp == null) return;
793 + var requestedPath = msg.path;
794 + if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
795 + for (var i in msg.delfiles) {
796 + const ul = obj.path.join(requestedPath, msg.delfiles[i]).split('\\').join('/');
797 + obj.sftp.unlink(ul, function (err) { });
798 + if (msg.rec === true) { obj.sftp.rmdir(ul + '/', function (err) { }); }
799 + }
800 + break;
801 + }
802 + case 'rename': {
803 + if (obj.sftp == null) return;
804 + var requestedPath = msg.path;
805 + if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
806 + const oldpath = obj.path.join(requestedPath, msg.oldname).split('\\').join('/');
807 + const newpath = obj.path.join(requestedPath, msg.newname).split('\\').join('/');
808 + obj.sftp.rename(oldpath, newpath, function (err) { });
809 + break;
810 + }
811 + case 'upload': {
812 + if (obj.sftp == null) return;
813 + var requestedPath = msg.path;
814 + if (requestedPath.startsWith('/') == false) { requestedPath = '/' + requestedPath; }
815 + obj.uploadFullpath = obj.path.join(requestedPath, msg.name).split('\\').join('/');
816 + obj.uploadSize = msg.size;
817 + obj.uploadReqid = msg.reqid;
818 + obj.uploadPosition = 0;
819 + obj.sftp.open(obj.uploadFullpath, 'w', 0o666, function (err, handle) {
820 + if (err != null) {
821 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploaderror', reqid: obj.uploadReqid }))) } catch (ex) { }
822 + } else {
823 + obj.uploadHandle = handle;
824 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploadstart', reqid: obj.uploadReqid }))) } catch (ex) { }
825 + }
826 +
827 + });
828 + break;
829 + }
830 + case 'uploaddone': {
831 + if (obj.sftp == null) return;
832 + if (obj.uploadHandle != null) {
833 + obj.sftp.close(obj.uploadHandle, function () { });
834 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploaddone', reqid: obj.uploadReqid }))) } catch (ex) { }
835 + delete obj.uploadHandle;
836 + delete obj.uploadFullpath;
837 + delete obj.uploadSize;
838 + delete obj.uploadReqid;
839 + delete obj.uploadPosition;
840 + }
841 + break;
842 + }
843 + case 'uploadcancel': {
844 + if (obj.sftp == null) return;
845 + if (obj.uploadHandle != null) {
846 + obj.sftp.close(obj.uploadHandle, function () { });
847 + obj.sftp.unlink(obj.uploadFullpath, function (err) { });
848 + try { obj.ws.send(Buffer.from(JSON.stringify({ action: 'uploadcancel', reqid: obj.uploadReqid }))) } catch (ex) { }
849 + delete obj.uploadHandle;
850 + delete obj.uploadFullpath;
851 + delete obj.uploadSize;
852 + delete obj.uploadReqid;
853 + delete obj.uploadPosition;
854 + }
855 + break;
856 + }
857 + case 'sshauth': {
858 + if (obj.sshClient != null) return;
859 +
860 + // Verify inputs
861 + if ((typeof msg.username != 'string') || (typeof msg.password != 'string')) break;
862 + if ((typeof msg.rows != 'number') || (typeof msg.cols != 'number') || (typeof msg.height != 'number') || (typeof msg.width != 'number')) break;
863 +
864 + obj.keep = msg.keep; // If true, keep store credentials on the server if the SSH tunnel connected succesfully.
865 + obj.username = msg.username;
866 + obj.password = msg.password;
867 +
868 + // Create a mesh relay authentication cookie
869 + var cookieContent = { userid: user._id, domainid: user.domain, nodeid: obj.nodeid, tcpport: obj.tcpport };
870 + if (obj.mtype == 3) { cookieContent.lc = 1; } // This is a local device
871 + startRelayConnection(parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey));
872 + break;
873 + }
874 + }
875 + }
876 + } catch (ex) { console.log(ex); obj.close(); }
877 + });
878 +
879 + // If error, do nothing
880 + ws.on('error', function (err) { parent.parent.debug('relay', 'SSH: Browser websocket error: ' + err); obj.close(); });
881 +
882 + // If the web socket is closed
883 + ws.on('close', function (req) { parent.parent.debug('relay', 'SSH: Browser websocket closed'); obj.close(); });
884 +
885 + // Decode the authentication cookie
886 + var userCookie = parent.parent.decodeCookie(req.query.auth, parent.parent.loginCookieEncryptionKey);
887 + if ((userCookie == null) || (userCookie.a != null)) { obj.close(); return; } // Invalid cookie
888 +
889 + // Fetch the user
890 + var user = parent.users[userCookie.userid]
891 + if (user == null) { obj.close(); return; } // Invalid userid
892 +
893 + // Check that we have a nodeid
894 + if (req.query.nodeid == null) { obj.close(); return; } // Invalid nodeid
895 + parent.GetNodeWithRights(domain, user, req.query.nodeid, function (node, rights, visible) {
896 + // Check permissions
897 + if ((rights & 8) == 0) { obj.close(); return; } // No MESHRIGHT_REMOTECONTROL rights
898 + if ((rights != 0xFFFFFFFF) && (rights & 0x00000200)) { obj.close(); return; } // MESHRIGHT_NOTERMINAL is set
899 + obj.mtype = node.mtype; // Store the device group type
900 + obj.nodeid = node._id; // Store the NodeID
901 +
902 + // Check the SSH port
903 + obj.tcpport = 22;
904 + if (typeof node.sshport == 'number') { obj.tcpport = node.sshport; }
905 +
906 + // We are all set, start receiving data
907 + ws._socket.resume();
908 +
909 + // Check if we have SSH credentials for this device
910 + parent.parent.db.Get(obj.nodeid, function (err, nodes) {
911 + if ((err != null) || (nodes == null) || (nodes.length != 1)) return;
912 + const node = nodes[0];
913 +
914 + if ((node.ssh == null) || (typeof node.ssh != 'object') || (typeof node.ssh.u != 'string') || (typeof node.ssh.p != 'string')) {
915 + // Send a request for SSH authentication
916 + try { ws.send(JSON.stringify({ action: 'sshauth' })) } catch (ex) { }
917 + } else {
918 + // Use our existing credentials
919 + obj.username = node.ssh.u;
920 + obj.password = node.ssh.p;
921 +
922 + // Create a mesh relay authentication cookie
923 + var cookieContent = { userid: user._id, domainid: user.domain, nodeid: obj.nodeid, tcpport: obj.tcpport };
924 + if (obj.mtype == 3) { cookieContent.lc = 1; } // This is a local device
925 + startRelayConnection(parent.parent.encodeCookie(cookieContent, parent.parent.loginCookieEncryptionKey));
926 + }
927 + });
928 +
929 + });
930 +
931 + return obj;
932 +};
views/default.handlebars
+34 -20
@@ -604,7 +604,7 @@
604 <span id=connectbutton1span><input type=button id=connectbutton1 cmenu="deskConnectButton" value="Connect" onclick=connectDesktop(event,3) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
605 <span id=connectbutton1hspan>&nbsp;<input type=button id=connectbutton1h value="HW Connect" title="Connect using Intel&reg; AMT hardware KVM" onclick=connectDesktop(event,2) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
606 <span id=disconnectbutton1span>&nbsp;<input type=button id=disconnectbutton1 value="Disconnect" onclick=connectDesktop(event,0) onkeypress="return false" onkeydown="return false" /></span>
607 - &nbsp;<span id="deskstatus" style="line-height:22px">Disconnected</span><span id="deskmetadata"></span>
607 + <span id="deskstatus" style="line-height:22px">Disconnected</span><span id="deskmetadata"></span>
608 </div>
609 </div>
610 <div id=deskarea2 style="">
@@ -701,7 +701,7 @@
701 <span id="connectbutton2span"><input type="button" id="connectbutton2" cmenu="termConnectButton" value="Connect" onclick=connectTerminal(event,1) onkeypress="return false" onkeydown="return false" disabled="disabled" /></span>
702 <span id="connectbutton2hspan">&nbsp;<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>
703 <span id="disconnectbutton2span">&nbsp;<input type="button" id="disconnectbutton2" value="Disconnect" onclick=connectTerminal(event,0) onkeypress="return false" onkeydown="return false" /></span>
704 - &nbsp;<span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span>
704 + <span id="termstatus" style="line-height:22px">Disconnected</span><span id="termtitle"></span>
705 </div>
706 </td>
707 </tr>
@@ -754,10 +754,11 @@
754 </div>
755 <table id="p13toolbar" cellpadding="0" cellspacing="0">
756 <tr>
757 - <td class="areaHead">
757 + <td class="areaHead" style="line-height:24px">
758 <div class="toright2">
759 <input id="filesActionsBtn" type=button title="Perform power actions on the device" value=Actions onclick=deviceActionFunction() />
760 <div id="filesRecordIcon" class='deskareaicon' title="Server is recording this session" style="display:none;background-color:red;width:12px;height:12px;border-radius:6px;margin-top:5px;margin-left:5px"></div>
761 + <div id="filesCustomUpperRight" style="float:left;margin-right:6px"></div>
762 <div id="filesCustomUiButtons" style="float:left"></div>
763 </div>
764 <div>
@@ -771,19 +772,19 @@
772 <td class="areaHead2" valign=bottom>
773 <div id="p13rightOfButtons" class="toright2"></div>
774 <div>
774 - <input type=button id=p13FolderUp disabled="disabled" onclick="p13folderup()" value="Up" />&nbsp;
775 - <input type=button id=p13SelectAllButton disabled="disabled" onclick="p13selectallfile()" value="Select All" />&nbsp;
776 - <input type=button id=p13RenameFileButton disabled="disabled" value="Rename" onclick="p13renamefile()" />&nbsp;
777 - <input type=button id=p13DeleteFileButton disabled="disabled" value="Delete" onclick="p13deletefile()" />&nbsp;
778 - <input type=button id=p13ViewFileButton disabled="disabled" value="Edit" onclick="p13viewfile()" />&nbsp;
779 - <input type=button id=p13NewFolderButton disabled="disabled" value="New Folder" onclick="p13createfolder()" />&nbsp;
780 - <input type=button id=p13UploadButton disabled="disabled" value="Upload" onclick="p13uploadFile()" />&nbsp;
781 - <input type=button id=p13CutButton disabled="disabled" value="Cut" onclick="p13copyFile(1)" />&nbsp;
782 - <input type=button id=p13CopyButton disabled="disabled" value="Copy" onclick="p13copyFile(0)" />&nbsp;
783 - <input type=button id=p13PasteButton disabled="disabled" value="Paste" onclick="p13pasteFile()" />&nbsp;
784 - <input type=button id=p13ZipButton disabled="disabled" value="Zip" onclick="p13zipFiles()" />&nbsp;
785 - <input type=button id=p13RefreshButton disabled="disabled" value="Refresh" onclick="p13folderup(9999)" />&nbsp;
786 - <input type=button id=p13FindButton disabled="disabled" value="Find" onclick="p13findfile()" />&nbsp;
775 + <input type=button style="margin-right:2px" disabled="disabled" id=p13FolderUp value="Up" onclick="p13folderup()" />
776 + <input type=button style="margin-right:2px" disabled="disabled" id=p13SelectAllButton value="Select All" onclick="p13selectallfile()" />
777 + <input type=button style="margin-right:2px" disabled="disabled" id=p13RenameFileButton value="Rename" onclick="p13renamefile()" />
778 + <input type=button style="margin-right:2px" disabled="disabled" id=p13DeleteFileButton value="Delete" onclick="p13deletefile()" />
779 + <input type=button style="margin-right:2px" disabled="disabled" id=p13ViewFileButton value="Edit" onclick="p13viewfile()" />
780 + <input type=button style="margin-right:2px" disabled="disabled" id=p13NewFolderButton value="New Folder" onclick="p13createfolder()" />
781 + <input type=button style="margin-right:2px" disabled="disabled" id=p13UploadButton value="Upload" onclick="p13uploadFile()" />
782 + <input type=button style="margin-right:2px" disabled="disabled" id=p13CutButton value="Cut" onclick="p13copyFile(1)" />
783 + <input type=button style="margin-right:2px" disabled="disabled" id=p13CopyButton value="Copy" onclick="p13copyFile(0)" />
784 + <input type=button style="margin-right:2px" disabled="disabled" id=p13PasteButton value="Paste" onclick="p13pasteFile()" />
785 + <input type=button style="margin-right:2px" disabled="disabled" id=p13ZipButton value="Zip" onclick="p13zipFiles()" />
786 + <input type=button style="margin-right:2px" disabled="disabled" id=p13RefreshButton value="Refresh" onclick="p13folderup(9999)" />
787 + <input type=button style="margin-right:2px" disabled="disabled" id=p13FindButton value="Find" onclick="p13findfile()" />
788 </div>
789 </td>
790 </tr>
@@ -6569,7 +6570,7 @@
6570 Q('MainComputerImage').className = ((((!node.conn) || (node.conn == 0)) && (node.mtype != 3))?'gray':'');
6571
6572 // If we are looking at a local non-windows device, enable terminal capability.
6572 - if ((node.mtype == 3) && (node.agent != null) && (node.agent.id > 4) && (features2 & 0x00000200)) { node.agent.caps = 2; }
6573 + if ((node.mtype == 3) && (node.agent != null) && (node.agent.id > 4) && (features2 & 0x00000200)) { node.agent.caps = 6; } // 1 = Terminal, 2 = Desktop, 4 = files
6574
6575 // Setup/Refresh the desktop tab
6576 if (terminalAccess) { setupTerminal(); }
@@ -6596,7 +6597,7 @@
6597 // Setup/Refresh Intel AMT tab
6598 var amtFrameNode = Q('p14iframe').contentWindow.getCurrentMeshNode();
6599 if ((amtFrameNode != null) && (amtFrameNode._id != currentNode._id)) { Q('p14iframe').contentWindow.disconnect(); }
6599 - var online = ((node.conn & 6) != 0)?true:false; // If CIRA (2) or AMT (4) connected, enable Commander
6600 + var online = ((node.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable Commander
6601 Q('p14iframe').contentWindow.setConnectionState(online);
6602 Q('p14iframe').contentWindow.setFrameHeight('650px');
6603 Q('p14iframe').contentWindow.setAuthCallback(updateAmtCredentials);
@@ -8586,7 +8587,7 @@
8587 var termState = ((terminal != null) && (terminal.state != 0));
8588
8589 // If we are looking at a local non-windows device, enable terminal capability.
8589 - if ((terminalNode.mtype == 3) && (terminalNode.agent != null) && (terminalNode.agent.id > 4) && (features2 & 0x00000200)) { terminalNode.agent.caps = 2; }
8590 + if ((terminalNode.mtype == 3) && (terminalNode.agent != null) && (terminalNode.agent.id > 4) && (features2 & 0x00000200)) { terminalNode.agent.caps = 6; } // 1 = Terminal, 2 = Desktop, 4 = files
8591
8592 // Show the right buttons
8593 QV('disconnectbutton2span', (termState == true));
@@ -8944,9 +8945,10 @@
8945 // Setup the files tab
8946 var samenode = (filesNode == currentNode);
8947 filesNode = currentNode;
8947 - var online = ((filesNode.conn & 1) != 0)?true:false; // If Agent (1) connected, enable Terminal
8948 + var online = ((filesNode.conn & 1) != 0) || (filesNode.mtype == 3); // If Agent (1) connected, enable Terminal
8949 QE('p13Connect', online);
8950 if (((samenode == false) || (online == false)) && files) { files.Stop(); files = null; }
8951 + p13setActions();
8952 }
8953
8954 function onFilesStateChange(xfiles, state) {
@@ -8997,6 +8999,7 @@
8999 if (!files) {
9000 // Setup a mesh agent files
9001 files = CreateAgentRedirect(meshserver, CreateRemoteFiles(p13gotFiles), serverPublicNamePort, authCookie, authRelayCookie, domainUrl);
9002 + if (filesNode.mtype == 3) { files.urlname = 'sshfilesrelay.ashx'; } // If this is a SSH session, change the URL to the SSH application relay.
9003 files.attemptWebRTC = attemptWebRTC;
9004 files.onStateChanged = onFilesStateChange;
9005 files.onConsoleMessageChange = function () {
@@ -9249,6 +9252,17 @@
9252 QE('p13ZipButton', advancedFeatures && (cc > 0) && ((p13filetreelocation.length > 0) || (winAgent == false)));
9253 QE('p13PasteButton', advancedFeatures && ((p13filetreelocation.length > 0) || (winAgent == false)) && ((p13clipboard != null) && (p13clipboard.length > 0)));
9254 }
9255 + if (filesNode.mtype != 3) {
9256 + QH('filesCustomUpperRight', '');
9257 + } else {
9258 + QH('filesCustomUpperRight', '<a onclick=cmsshportaction(1,event)>' + format("SSH Port {0}", (filesNode.sshport?filesNode.sshport:22)) + '</a>');
9259 + }
9260 + QV('filesActionsBtn', filesNode.mtype != 3);
9261 + QV('p13FindButton', filesNode.mtype != 3);
9262 + QV('p13CutButton', filesNode.mtype != 3);
9263 + QV('p13CopyButton', filesNode.mtype != 3);
9264 + QV('p13ZipButton', filesNode.mtype != 3);
9265 + QV('p13PasteButton', filesNode.mtype != 3);
9266 }
9267
9268 function p13getFileSelCount(includeDirs) { var cc = 0; var checkboxes = document.getElementsByName('fd'); for (var i = 0; i < checkboxes.length; i++) { if ((checkboxes[i].checked) && ((includeDirs != false) || (checkboxes[i].attributes.file.value == '3'))) cc++; } return cc; }
webserver.js
+5
@@ -5592,6 +5592,11 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
5592 require('./apprelays.js').CreateSshTerminalRelay(obj, obj.db, ws1, req1, domain, user, cookie, obj.args);
5593 });
5594 });
5595 + obj.app.ws(url + 'sshfilesrelay.ashx', function (ws, req) {
5596 + PerformWSSessionAuth(ws, req, true, function (ws1, req1, domain, user, cookie) {
5597 + require('./apprelays.js').CreateSshFilesRelay(obj, obj.db, ws1, req1, domain, user, cookie, obj.args);
5598 + });
5599 + });
5600 }
5601
5602 // Setup firebase push only server