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) {
if (this.parent.tunneling == false) {
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');
} else if ((msg.length > 6) && (msg.substring(0, 6) == 'error:')) {
console.log(msg.substring(6));

View File

@ -1042,7 +1042,7 @@ function createMeshCore(agent)
if (this.httprequest.state == 0) {
// 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 {
// Handle tunnel data
if (this.httprequest.protocol == 0) { // 1 = Terminal, 2 = Desktop, 5 = Files, 6 = PowerShell
@ -1059,41 +1059,61 @@ function createMeshCore(agent)
return;
}
this.end = function () {
if (process.platform == "win32") {
this.end = function ()
{
if (process.platform == "win32")
{
// Unpipe the web socket
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).
if (this.rtcchannel) {
if (this.rtcchannel)
{
this.rtcchannel.unpipe(this.httprequest._term);
this.httprequest._term.unpipe(this.rtcchannel);
if (this.httprequest._term) { this.httprequest._term.unpipe(this.rtcchannel); }
}
// Clean up
this.httprequest._term.end();
if (this.httprequest._term) { this.httprequest._term.end(); }
this.httprequest._term = null;
} else {
} else
{
// TODO!!
}
};
// Remote terminal using native pipes
if (process.platform == "win32") {
if ((this.httprequest.protocol == 6) && (require('win-terminal').PowerShellCapable() == true)) {
if (process.platform == "win32")
{
try
{
if ((this.httprequest.protocol == 6) && (require('win-terminal').PowerShellCapable() == true))
{
this.httprequest._term = require('win-terminal').StartPowerShell(80, 25);
} else {
} else
{
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.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); });
} else {
if (fs.existsSync("/bin/bash")) {
} else
{
if (fs.existsSync("/bin/bash"))
{
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"); }
} else {
} else
{
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"); }
}
@ -1296,7 +1316,6 @@ function createMeshCore(agent)
} else if (this.httprequest.protocol == 1) {
// Send data into terminal stdin
//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) {
// Send data into remote desktop
if (this.httprequest.desktop.state == 0) {

View File

@ -134,15 +134,22 @@ function windows_terminal() {
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'));
} else {
}
else
{
return (require('fs').existsSync(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe'));
}
}
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;
if (this._kernel32.GetConsoleWindow().Val == 0) {
if (this._kernel32.AllocConsole().Val == 0) {
@ -177,37 +184,47 @@ function windows_terminal() {
// Hook Ready
this.terminal.StartCommand(this.userArgs[0]);
}, console.log);
this._stream = new duplex({
'write': function (chunk, flush) {
if (!this.terminal.connected) {
this._stream = new duplex(
{
'write': function (chunk, flush)
{
if (!this.terminal.connected)
{
//console.log('_write: ' + chunk);
if (!this._promise.chunk) {
if (!this._promise.chunk)
{
this._promise.chunk = [];
}
if (typeof (chunk) == 'string') {
if (typeof (chunk) == 'string')
{
this._promise.chunk.push(chunk);
} else {
} else
{
this._promise.chunk.push(Buffer.alloc(chunk.length));
chunk.copy(this._promise.chunk.peek());
}
this._promise.chunk.peek().flush = flush;
this._promise.then(function () {
this._promise.then(function ()
{
var buf;
while (this.chunk.length > 0) {
while (this.chunk.length > 0)
{
buf = this.chunk.shift();
this.terminal._WriteBuffer(buf);
buf.flush();
}
});
}
else {
else
{
//console.log('writeNOW: ' + chunk);
this.terminal._WriteBuffer(chunk);
flush();
}
return (true);
},
'final': function (flush) {
'final': function (flush)
{
var p = this.terminal._stop();
p.__flush = flush;
p.then(function () { this.__flush(); });
@ -216,6 +233,10 @@ function windows_terminal() {
this._stream.terminal = this;
this._stream._promise = new promise(function (res, rej) { this._res = res; this._rej = rej; });
this._stream._promise.terminal = this;
this._stream.prependOnceListener('end', function ()
{
this.terminal._stream = null;
});
return (this._stream);
};
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",
"version": "0.3.9-v",
"version": "0.3.9-w",
"keywords": [
"Remote Management",
"Intel AMT",