Added Windows support for User shells
Bryan Roe committed
Dec 6, 2019 at 10:49 UTC
5ad93ad89c0ef03c21807528857d57c7fa5cf136
1 file changed
+44
-14
agents/meshcore.js
+44
-14
@@ -1109,28 +1109,58 @@ function createMeshCore(agent) {
1109
{
1110
try
1111
{
1112
- if (((this.httprequest.protocol == 6) || (this.httprequest.protocol == 8)) && (require('win-terminal').PowerShellCapable() == true)) {
1113
- if (require('win-virtual-terminal').supported) {
1114
- this.httprequest._term = require('win-virtual-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
1115
- } else {
1116
- this.httprequest._term = require('win-terminal').StartPowerShell(80, 25); // TODO: Start as logged in used when protocol is 8
1112
+ if (!require('win-terminal').PowerShellCapable() && (this.httprequest.protocol == 6 || this.httprequest.protocol == 9)) { throw ('PowerShell is not supported on this version of windows'); }
1113
+ if ((this.httprequest.protocol == 1) || (this.httprequest.protocol == 6))
1114
+ {
1115
+ // Admin Terminal
1116
+ if (require('win-virtual-terminal').supported)
1117
+ {
1118
+ // ConPTY PseudoTerminal
1119
+ this.httprequest._term = require('win-virtual-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
1120
}
1118
- } else {
1119
- if (require('win-virtual-terminal').supported) {
1120
- this.httprequest._term = require('win-virtual-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
1121
- } else {
1122
- this.httprequest._term = require('win-terminal').Start(80, 25); // TODO: Start as logged in used when protocol is 8
1121
+ else
1122
+ {
1123
+ // Legacy Terminal
1124
+ this.httprequest._term = require('win-terminal')[this.httprequest.protocol == 6 ? 'StartPowerShell' : 'Start'](80, 25);
1125
}
1126
}
1125
- } catch (e) {
1127
+ else
1128
+ {
1129
+ // Logged in user
1130
+ var username = require('user-sessions').getUsername(require('user-sessions').consoleUid());
1131
+ if (require('win-virtual-terminal').supported)
1132
+ {
1133
+ // ConPTY PseudoTerminal
1134
+ 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] } });
1135
+ }
1136
+ else
1137
+ {
1138
+ // Legacy Terminal
1139
+ 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] } });
1140
+ }
1141
+ this.httprequest._dispatcher.ws = this;
1142
+ this.httprequest._dispatcher.on('connection', function (c)
1143
+ {
1144
+ console.log('client connected');
1145
+ this.ws._term = c;
1146
+ c.pipe(this.ws, { dataTypeSkip: 1 });
1147
+ this.ws.pipe(c, { dataTypeSkip: 1, end: false });
1148
+ this.ws.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1149
+ });
1150
+ }
1151
+ } catch (e)
1152
+ {
1153
MeshServerLog('Failed to start remote terminal session, ' + e.toString() + ' (' + this.httprequest.remoteaddr + ')', this.httprequest);
1154
this.write(JSON.stringify({ ctrlChannel: '102938', type: 'console', msg: e.toString() }));
1155
this.end();
1156
return;
1157
}
1131
- this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
1132
- this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1133
- this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1158
+ if (!this.httprequest._dispatcher)
1159
+ {
1160
+ this.httprequest._term.pipe(this, { dataTypeSkip: 1 });
1161
+ this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1162
+ this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1163
+ }
1164
}
1165
else
1166
{