Fixed terminal.

Ylian Saint-Hilaire committed Nov 26, 2019 at 11:54 UTC 5a7d097a3252f60651191ae21a9e4be818af874c
9 files changed +38 -30
MeshCentralServer.njsproj
+1
@@ -71,6 +71,7 @@
71 <Compile Include="agents\modules_meshcore\win-console.js" />
72 <Compile Include="agents\modules_meshcore\win-info.js" />
73 <Compile Include="agents\modules_meshcore\win-terminal.js" />
74 + <Compile Include="agents\modules_meshcore\win-virtual-terminal.js" />
75 <Compile Include="agents\modules_meshcore_min\amt-lme.min.js" />
76 <Compile Include="agents\modules_meshcore_min\amt-mei.min.js" />
77 <Compile Include="agents\modules_meshcore_min\amt-scanner.min.js" />
agents/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files /dev/null and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshcore.js
+8 -16
@@ -1085,24 +1085,16 @@ function createMeshCore(agent) {
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 - //{
1088 + if (((this.httprequest.protocol == 6) || (this.httprequest.protocol == 8)) && (require('win-terminal').PowerShellCapable() == true)) {
1089 + //if (require('win-virtual-terminal').supported) {
1090 + //this.httprequest._term = require('win-virtual-terminal').StartPowerShell(80, 25);
1091 + //} else {
1092 this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
1093 //}
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 - //{
1094 + } else {
1095 + //if (require('win-virtual-terminal').supported) {
1096 + //this.httprequest._term = require('win-virtual-terminal').Start(80, 25);
1097 + //} else {
1098 this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 7
1099 //}
1100 }
agents/meshcore.min.js
+24 -9
@@ -1081,14 +1081,25 @@ 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
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 + //if (require('win-virtual-terminal').supported) {
1090 + //this.httprequest._term = require('win-virtual-terminal').StartPowerShell(80, 25);
1091 + //} else {
1092 + this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
1093 + //}
1094 } else {
1089 - this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
1095 + //if (require('win-virtual-terminal').supported) {
1096 + //this.httprequest._term = require('win-virtual-terminal').Start(80, 25);
1097 + //} else {
1098 + this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 7
1099 + //}
1100 }
1091 - } catch (e) {
1101 + } catch (e)
1102 + {
1103 MeshServerLog('Failed to start remote terminal session, ' + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
1104 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1105 this.end();
@@ -1097,8 +1108,11 @@ function createMeshCore(agent) {
1108 this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
1109 this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1110 this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1100 - } else {
1101 - try {
1111 + }
1112 + else
1113 + {
1114 + try
1115 + {
1116 if (fs.existsSync('/usr/bin/python') && fs.existsSync('/bin/bash')) {
1117 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
1118 if (process.platform == 'linux') { this.httprequest.process.stdin.write("export TERM='xterm'\nalias ls='ls --color=auto'\nclear\n"); }
@@ -1109,7 +1123,8 @@ function createMeshCore(agent) {
1123 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
1124 if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
1125 }
1112 - } catch (e) {
1126 + } catch (e)
1127 + {
1128 MeshServerLog("Failed to start remote terminal session, " + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
1129 this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1130 this.end();
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.4.4-x",
3 + "version": "0.4.4-y",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
public/scripts/amt-terminal-0.0.2.js
+4 -4
@@ -408,14 +408,14 @@ var CreateAmtRemoteTerminal = function (divid, options) {
408 for (var z = 0; z < obj.width; z++) { _tscreen[y][z] = ' '; _scratt[y][z] = (7 << 6); }
409 }
410 break;
411 - case 'X': // Erase X characters, default 1 (untested)
412 - var x = 1;
411 + case 'X': // Erase X characters, default 1
412 + var x = 1, xx = _termx, yy = _termy;
413 if (argslen == 1) { x = args[0] }
414 - while ((x > 0) && (_termx > 0)) { _tscreen[_termy][_termx] = ' '; _termx--; x--; }
414 + while ((x > 0) && (yy < obj.height)) { _tscreen[yy][xx] = ' '; xx++; x--; if (xx >= obj.width) { xx = 0; yy++; } }
415 break;
416 default:
417 //if (code != '@') alert(code);
418 - console.log('unknown terminal code', code, args, mode);
418 + console.log('Unknown terminal code', code, args, mode);
419 break;
420 }
421 }