Published as v0.3.9-w

This commit is contained in:
Ylian Saint-Hilaire 2019-08-14 15:08:11 -07:00
parent ff076fa927
commit ec7edc4430
5 changed files with 96 additions and 56 deletions

View File

@ -1982,7 +1982,7 @@ function OnWebSocket(msg, s, head) {
s.on('data', function (msg) { s.on('data', function (msg) {
if (this.parent.tunneling == false) { if (this.parent.tunneling == false) {
msg = msg.toString(); msg = msg.toString();
if (msg == 'c') { if ((msg == 'c') || (msg == 'cr')) {
this.parent.tunneling = true; this.pipe(this.parent.tcp); this.parent.tcp.pipe(this); debug(1, 'Tunnel active'); this.parent.tunneling = true; this.pipe(this.parent.tcp); this.parent.tcp.pipe(this); debug(1, 'Tunnel active');
} else if ((msg.length > 6) && (msg.substring(0, 6) == 'error:')) { } else if ((msg.length > 6) && (msg.substring(0, 6) == 'error:')) {
console.log(msg.substring(6)); console.log(msg.substring(6));

View File

@ -1042,7 +1042,7 @@ function createMeshCore(agent)
if (this.httprequest.state == 0) { if (this.httprequest.state == 0) {
// Check if this is a relay connection // Check if this is a relay connection
if (data == 'c') { this.httprequest.state = 1; /*sendConsoleText("Tunnel #" + this.httprequest.index + " now active", this.httprequest.sessionid);*/ } if ((data == 'c') || (data == 'cr')) { this.httprequest.state = 1; /*sendConsoleText("Tunnel #" + this.httprequest.index + " now active", this.httprequest.sessionid);*/ }
} else { } else {
// Handle tunnel data // Handle tunnel data
if (this.httprequest.protocol == 0) { // 1 = Terminal, 2 = Desktop, 5 = Files, 6 = PowerShell if (this.httprequest.protocol == 0) { // 1 = Terminal, 2 = Desktop, 5 = Files, 6 = PowerShell
@ -1059,41 +1059,61 @@ function createMeshCore(agent)
return; return;
} }
this.end = function () { this.end = function ()
if (process.platform == "win32") { {
if (process.platform == "win32")
{
// Unpipe the web socket // Unpipe the web socket
this.unpipe(this.httprequest._term); this.unpipe(this.httprequest._term);
this.httprequest._term.unpipe(this); if (this.httprequest._term) { this.httprequest._term.unpipe(this); }
// Unpipe the WebRTC channel if needed (This will also be done when the WebRTC channel ends). // Unpipe the WebRTC channel if needed (This will also be done when the WebRTC channel ends).
if (this.rtcchannel) { if (this.rtcchannel)
{
this.rtcchannel.unpipe(this.httprequest._term); this.rtcchannel.unpipe(this.httprequest._term);
this.httprequest._term.unpipe(this.rtcchannel); if (this.httprequest._term) { this.httprequest._term.unpipe(this.rtcchannel); }
} }
// Clean up // Clean up
this.httprequest._term.end(); if (this.httprequest._term) { this.httprequest._term.end(); }
this.httprequest._term = null; this.httprequest._term = null;
} else { } else
{
// TODO!! // TODO!!
} }
}; };
// Remote terminal using native pipes // Remote terminal using native pipes
if (process.platform == "win32") { if (process.platform == "win32")
if ((this.httprequest.protocol == 6) && (require('win-terminal').PowerShellCapable() == true)) { {
try
{
if ((this.httprequest.protocol == 6) && (require('win-terminal').PowerShellCapable() == true))
{
this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); this.httprequest._term = require('win-terminal').StartPowerShell(80, 25);
} else { } else
{
this.httprequest._term = require('win-terminal').Start(80, 25); this.httprequest._term = require('win-terminal').Start(80, 25);
} }
}
catch(e)
{
MeshServerLog('Failed to start remote terminal session, ' + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
this.end();
return;
}
this.httprequest._term.pipe(this, { dataTypeSkip: 1 }); this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false }); this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); }); this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); });
} else { } else
if (fs.existsSync("/bin/bash")) { {
if (fs.existsSync("/bin/bash"))
{
this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM }); this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM });
if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); } if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); }
} else { } else
{
this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM }); this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); } if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); }
} }
@ -1296,7 +1316,6 @@ function createMeshCore(agent)
} else if (this.httprequest.protocol == 1) { } else if (this.httprequest.protocol == 1) {
// Send data into terminal stdin // Send data into terminal stdin
//this.write(data); // Echo back the keys (Does not seem to be a good idea) //this.write(data); // Echo back the keys (Does not seem to be a good idea)
this.httprequest.process.write(data);
} else if (this.httprequest.protocol == 2) { } else if (this.httprequest.protocol == 2) {
// Send data into remote desktop // Send data into remote desktop
if (this.httprequest.desktop.state == 0) { if (this.httprequest.desktop.state == 0) {

View File

@ -134,15 +134,22 @@ function windows_terminal() {
this.PowerShellCapable = function() this.PowerShellCapable = function()
{ {
if (require('os').arch() == 'x64') { if (require('os').arch() == 'x64')
{
return (require('fs').existsSync(process.env['windir'] + '\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe')); return (require('fs').existsSync(process.env['windir'] + '\\SysWow64\\WindowsPowerShell\\v1.0\\powershell.exe'));
} else { }
else
{
return (require('fs').existsSync(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe')); return (require('fs').existsSync(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'));
} }
} }
this.StartEx = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT, terminalTarget) this.StartEx = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT, terminalTarget)
{ {
if (this._stream != null)
{
throw ('Concurrent terminal sessions are not supported on Windows.');
}
this.stopping = null; this.stopping = null;
if (this._kernel32.GetConsoleWindow().Val == 0) { if (this._kernel32.GetConsoleWindow().Val == 0) {
if (this._kernel32.AllocConsole().Val == 0) { if (this._kernel32.AllocConsole().Val == 0) {
@ -177,37 +184,47 @@ function windows_terminal() {
// Hook Ready // Hook Ready
this.terminal.StartCommand(this.userArgs[0]); this.terminal.StartCommand(this.userArgs[0]);
}, console.log); }, console.log);
this._stream = new duplex({ this._stream = new duplex(
'write': function (chunk, flush) { {
if (!this.terminal.connected) { 'write': function (chunk, flush)
{
if (!this.terminal.connected)
{
//console.log('_write: ' + chunk); //console.log('_write: ' + chunk);
if (!this._promise.chunk) { if (!this._promise.chunk)
{
this._promise.chunk = []; this._promise.chunk = [];
} }
if (typeof (chunk) == 'string') { if (typeof (chunk) == 'string')
{
this._promise.chunk.push(chunk); this._promise.chunk.push(chunk);
} else { } else
{
this._promise.chunk.push(Buffer.alloc(chunk.length)); this._promise.chunk.push(Buffer.alloc(chunk.length));
chunk.copy(this._promise.chunk.peek()); chunk.copy(this._promise.chunk.peek());
} }
this._promise.chunk.peek().flush = flush; this._promise.chunk.peek().flush = flush;
this._promise.then(function () { this._promise.then(function ()
{
var buf; var buf;
while (this.chunk.length > 0) { while (this.chunk.length > 0)
{
buf = this.chunk.shift(); buf = this.chunk.shift();
this.terminal._WriteBuffer(buf); this.terminal._WriteBuffer(buf);
buf.flush(); buf.flush();
} }
}); });
} }
else { else
{
//console.log('writeNOW: ' + chunk); //console.log('writeNOW: ' + chunk);
this.terminal._WriteBuffer(chunk); this.terminal._WriteBuffer(chunk);
flush(); flush();
} }
return (true); return (true);
}, },
'final': function (flush) { 'final': function (flush)
{
var p = this.terminal._stop(); var p = this.terminal._stop();
p.__flush = flush; p.__flush = flush;
p.then(function () { this.__flush(); }); p.then(function () { this.__flush(); });
@ -216,6 +233,10 @@ function windows_terminal() {
this._stream.terminal = this; this._stream.terminal = this;
this._stream._promise = new promise(function (res, rej) { this._res = res; this._rej = rej; }); this._stream._promise = new promise(function (res, rej) { this._res = res; this._rej = rej; });
this._stream._promise.terminal = this; this._stream._promise.terminal = this;
this._stream.prependOnceListener('end', function ()
{
this.terminal._stream = null;
});
return (this._stream); return (this._stream);
}; };
this.Start = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT) this.Start = function Start(CONSOLE_SCREEN_WIDTH, CONSOLE_SCREEN_HEIGHT)

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.3.9-v", "version": "0.3.9-w",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",