Added commented out code for ConPTY support

Bryan Roe committed Nov 26, 2019 at 10:36 UTC 2243c3b34fdf51bf4a39a3f9c1fb23ad10ae5a90
1 file changed +33 -10
agents/meshcore.js
+33 -10
@@ -1081,14 +1081,33 @@ function createMeshCore(agent) {
1081 };
1082
1083 // Remote terminal using native pipes
1084 - if (process.platform == "win32") {
1085 - try {
1086 - if (((this.httprequest.protocol == 6) || (this.httprequest.protocol == 9)) && (require('win-terminal').PowerShellCapable() == true)) {
1087 - this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 9
1088 - } else {
1089 - this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
1084 + if (process.platform == "win32")
1085 + {
1086 + try
1087 + {
1088 + if (((this.httprequest.protocol == 6) || (this.httprequest.protocol == 8)) && (require('win-terminal').PowerShellCapable() == true))
1089 + {
1090 + //if (require('win-virtual-terminal').supported)
1091 + //{
1092 + // this.httprequest._term = require('win-virtual-terminal').StartPowerShell(80, 25);
1093 + //}
1094 + //else
1095 + //{
1096 + this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
1097 + //}
1098 + } else
1099 + {
1100 + //if (require('win-virtual-terminal').supported)
1101 + //{
1102 + // this.httprequest._term = require('win-virtual-terminal').Start(80, 25);
1103 + //}
1104 + //else
1105 + //{
1106 + this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 7
1107 + //}
1108 }
1091 - } catch (e) {
1109 + } catch (e)
1110 + {
1111 MeshServerLog('Failed to start remote terminal session, ' + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
1112 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1113 this.end();
@@ -1097,8 +1116,11 @@ function createMeshCore(agent) {
1116 this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
1117 this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1118 this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1100 - } else {
1101 - try {
1119 + }
1120 + else
1121 + {
1122 + try
1123 + {
1124 if (fs.existsSync('/usr/bin/python') && fs.existsSync('/bin/bash')) {
1125 this.httprequest.process = childProcess.execFile('/usr/bin/python', ['python', '-c', "import pty; pty.spawn([\"/bin/bash\"])"], { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null }); // Start as active user
1126 if (process.platform == 'linux') { this.httprequest.process.stdin.write("export TERM='xterm'\nalias ls='ls --color=auto'\nclear\n"); }
@@ -1109,7 +1131,8 @@ function createMeshCore(agent) {
1131 this.httprequest.process = childProcess.execFile('/bin/sh', ['sh'], { type: childProcess.SpawnTypes.TERM, uid: (this.httprequest.protocol == 8)?require('user-sessions').consoleUid():null }); // Start as active user
1132 if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
1133 }
1112 - } catch (e) {
1134 + } catch (e)
1135 + {
1136 MeshServerLog("Failed to start remote terminal session, " + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
1137 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1138 this.end();