This commit is contained in:
Ylian Saint-Hilaire 2019-08-14 11:55:14 -07:00
commit b5c5d49f2a

View File

@ -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"); }
}