updated tsid selection

Bryan Roe committed Dec 16, 2019 at 15:07 UTC 0d6a70250f82e0eaa4e0a9b01233967caf0be9c2
1 file changed +31 -24
agents/meshcore.js
+31 -24
@@ -1151,29 +1151,38 @@ function createMeshCore(agent) {
1151 else
1152 {
1153 // Logged in user
1154 - var username = require('user-sessions').getUsername(require('user-sessions').consoleUid());
1155 - if (require('win-virtual-terminal').supported)
1156 - {
1157 - // ConPTY PseudoTerminal
1158 - 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] } });
1159 - }
1160 - else
1154 + var userPromise = require('user-sessions').enumerateUsers();
1155 + userPromise.that = this;
1156 + userPromise.then(function (u)
1157 {
1162 - // Legacy Terminal
1163 - 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] } });
1164 - }
1165 - this.httprequest._dispatcher.ws = this;
1166 - this.httprequest._dispatcher.on('connection', function (c)
1167 - {
1168 - console.log('client connected');
1169 - this.ws._term = c;
1170 - c.pipe(this.ws, { dataTypeSkip: 1 });
1171 - this.ws.pipe(c, { dataTypeSkip: 1, end: false });
1172 - this.ws.prependListener('end', function ()
1158 + var that = this.that;
1159 + if (u.Active.length > 0)
1160 {
1174 - if (this.httprequest._term) { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); }
1175 - });
1176 - });
1161 + var username = u.Active[0].Username;
1162 + if (require('win-virtual-terminal').supported)
1163 + {
1164 + // ConPTY PseudoTerminal
1165 + that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-virtual-terminal', script: getJSModule('win-virtual-terminal') }], launch: { module: 'win-virtual-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
1166 + }
1167 + else
1168 + {
1169 + // Legacy Terminal
1170 + that.httprequest._dispatcher = require('win-dispatcher').dispatch({ user: username, modules: [{ name: 'win-terminal', script: getJSModule('win-terminal') }], launch: { module: 'win-terminal', method: (that.httprequest.protocol == 9 ? 'StartPowerShell' : 'Start'), args: [80, 25] } });
1171 + }
1172 + that.httprequest._dispatcher.ws = that;
1173 + that.httprequest._dispatcher.on('connection', function (c)
1174 + {
1175 + console.log('client connected');
1176 + this.ws._term = c;
1177 + c.pipe(this.ws, { dataTypeSkip: 1 });
1178 + this.ws.pipe(c, { dataTypeSkip: 1, end: false });
1179 + this.ws.prependListener('end', function ()
1180 + {
1181 + if (this.httprequest._term) { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); }
1182 + });
1183 + });
1184 + }
1185 + });
1186 }
1187 } catch (e)
1188 {
@@ -1271,9 +1280,7 @@ function createMeshCore(agent) {
1280 // Look for a TSID
1281 var tsid = null;
1282 if ((this.httprequest.xoptions != null) && (typeof this.httprequest.xoptions.tsid == 'number')) { tsid = this.httprequest.xoptions.tsid; }
1274 - //if (require('MeshAgent')._tsid != null) { tsid = require('MeshAgent')._tsid; }
1275 - //sendConsoleText('tsid: ' + tsid);
1276 - //require('MeshAgent')._tsid = tsid;
1283 + require('MeshAgent')._tsid = tsid;
1284
1285 // Remote desktop using native pipes
1286 this.httprequest.desktop = { state: 0, kvm: mesh.getRemoteDesktopStream(tsid), tunnel: this };