This commit is contained in:
Ylian Saint-Hilaire 2019-12-06 16:49:49 -08:00
commit fb907be4cd

View File

@ -1109,28 +1109,58 @@ function createMeshCore(agent) {
{
try
{
if (((this.httprequest.protocol == 6) || (this.httprequest.protocol == 8)) && (require('win-terminal').PowerShellCapable() == true)) {
if (require('win-virtual-terminal').supported) {
this.httprequest._term = require('win-virtual-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
} else {
this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
if (!require('win-terminal').PowerShellCapable() && (this.httprequest.protocol == 6 || this.httprequest.protocol == 9)) { throw ('PowerShell is not supported on this version of windows'); }
if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6))
{
// Admin Terminal
if (require('win-virtual-terminal').supported)
{
// ConPTY PseudoTerminal
this.httprequest._term = require('win-virtual-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
}
} else {
if (require('win-virtual-terminal').supported) {
this.httprequest._term = require('win-virtual-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
} else {
this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
else
{
// Legacy Terminal
this.httprequest._term = require('win-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
}
}
} catch (e) {
else
{
// Logged in user
var username = require('user-sessions').getUsername(require('user-sessions').consoleUid());
if (require('win-virtual-terminal').supported)
{
// ConPTY PseudoTerminal
this.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-virtual-terminal', script: getJSModule('win-virtual-terminal') }], launch: { module: 'win-virtual-terminal', method: (this.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
}
else
{
// Legacy Terminal
this.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-terminal', script: getJSModule('win-terminal') }], launch: { module: 'win-terminal', method: (this.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
}
this.httprequest._dispatcher.ws = this;
this.httprequest._dispatcher.on('connection', function (c)
{
console.log('client connected');
this.ws._term = c;
c.pipe(this.ws, { dataTypeSkip: 1 });
this.ws.pipe(c, { dataTypeSkip: 1, end: false });
this.ws.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
});
}
} 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"); }); });
if (!this.httprequest._dispatcher)
{
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
{
@ -1212,7 +1242,7 @@ function createMeshCore(agent) {
}
// Remote desktop using native pipes
this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(), tunnel: this };
this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(require('MeshAgent')._tsid == null ? undefined : require('MeshAgent')._tsid), tunnel: this };
this.httprequest.desktop.kvm.parent = this.httprequest.desktop;
this.desktop = this.httprequest.desktop;
@ -1256,7 +1286,7 @@ function createMeshCore(agent) {
this.httprequest.desktop.kvm.connectionBar.removeAllListeners('close');
this.httprequest.desktop.kvm.connectionBar.close();
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '));
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '), require('MeshAgent')._tsid);
this.httprequest.desktop.kvm.connectionBar.httprequest = this.httprequest;
this.httprequest.desktop.kvm.connectionBar.on('close', function ()
{
@ -1321,7 +1351,7 @@ function createMeshCore(agent) {
}
try
{
this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.ws.httprequest.desktop.kvm.users.sort().join(', '));
this.ws.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.ws.httprequest.desktop.kvm.users.sort().join(', '), require('MeshAgent')._tsid);
MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.ws.httprequest.remoteaddr + ')', this.ws.httprequest);
}
catch(xx)
@ -1375,7 +1405,7 @@ function createMeshCore(agent) {
}
try
{
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '));
this.httprequest.desktop.kvm.connectionBar = require('notifybar-desktop')('Sharing desktop with: ' + this.httprequest.desktop.kvm.users.sort().join(', '), require('MeshAgent')._tsid);
MeshServerLog('Remote Desktop Connection Bar Activated/Updated (' + this.httprequest.remoteaddr + ')', this.httprequest);
}
catch(xx)
@ -1836,6 +1866,40 @@ function createMeshCore(agent) {
response = 'Available commands: \r\n' + fin + '.';
break;
}
case 'tsid':
if (process.platform == 'win32')
{
if (args['_'].length != 1)
{
response = 'TSID: ' + (require('MeshAgent')._tsid == null ? 'console' : require('MeshAgent')._tsid);
}
else
{
var i = parseInt(args['_'][0]);
require('MeshAgent')._tsid = (isNaN(i) ? null : i);
response = 'TSID set to: ' + (require('MeshAgent')._tsid == null ? 'console' : require('MeshAgent')._tsid);
}
}
break;
case 'activeusers':
if (process.platform == 'win32')
{
var p = require('user-sessions').enumerateUsers();
p.sessionid = sessionid;
p.then(function (u)
{
var v = [];
for(var i in u)
{
if(u[i].State == 'Active' || u[i].State == 'Connected')
{
v.push({ tsid: i, type: u[i].StationName, user: u[i].Username });
}
}
sendConsoleText(JSON.stringify(v, null, 1), this.sessionid);
});
}
break;
case 'wallpaper':
if (process.platform != 'win32' && !(process.platform == 'linux' && require('linux-gnome-helpers').available))
{