Following changes requires updated agent, which fixes interactive mode

1. Removed 'Script' and 'Python' from terminal 2. Added 'requireLogin' option, to spawn login shell

Bryan Roe committed Feb 5, 2020 at 10:20 UTC 11796beaafb56e837f088b41fd2ad91ceb9d35db
1 file changed +13 -37
agents/meshcore.js
+13 -37
@@ -1238,23 +1238,6 @@ function createMeshCore(agent) {
1238 {
1239 var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false;
1240 var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false;
1241 - var script = false;
1242 - if (this.httprequest.xoptions && this.httprequest.xoptions.script)
1243 - {
1244 - try
1245 - {
1246 - if (require('linux-gnome-helpers').scriptVersion)
1247 - {
1248 - if (require('linux-gnome-helpers').scriptVersion.major > 2 ||
1249 - (require('linux-gnome-helpers').scriptVersion.major == 2 && require('linux-gnome-helpers').scriptVersion.minor >= 25))
1250 - {
1251 - script = '/usr/bin/script';
1252 - }
1253 - }
1254 - } catch (ex) { }
1255 - }
1256 - var python = (this.httprequest.xoptions && this.httprequest.xoptions.python && fs.existsSync('/usr/bin/python')) ? '/usr/bin/python' : false;
1257 - var shell = bash || sh;
1241
1242 var env = { HISTCONTROL: 'ignoreboth', TERM: 'xterm' };
1243 if (this.httprequest.xoptions)
@@ -1262,31 +1245,27 @@ function createMeshCore(agent) {
1245 if (this.httprequest.xoptions.rows) { env.LINES = ('' + this.httprequest.xoptions.rows); }
1246 if (this.httprequest.xoptions.cols) { env.COLUMNS = ('' + this.httprequest.xoptions.cols); }
1247 }
1265 - var options = { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: env };
1266 - var setupcommands = ' alias ls=\'ls --color=auto\'\n';
1267 - if (shell == sh) setupcommands += ' stty erase ^H\n';
1268 -
1269 - if (script && shell && process.platform == 'linux')
1270 - {
1271 - this.httprequest.process = childProcess.execFile(script, ['script', '--return', '--quiet', '-c', '"' + shell + '"', '/dev/null'], options); // Start as active user
1272 - this.httprequest.process.stdin.write(setupcommands);
1273 - }
1274 - else if (python && shell)
1248 + var options = { type: childProcess.SpawnTypes.TERM, uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: env };
1249 + if (this.httprequest.xoptions && this.httprequest.xoptions.requireLogin)
1250 {
1276 - this.httprequest.process = childProcess.execFile(python, ['python', '-c', 'import pty; pty.spawn(["' + shell + '"])'], options); // Start as active user
1277 - if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
1251 + if (!require('fs').existsSync('/bin/login')) { throw ('Unable to spawn login process'); }
1252 + this.httprequest.process = childProcess.execFile('/bin/login', ['login'], options); // Start login shell
1253 }
1254 else if (bash)
1255 {
1281 - options.type = childProcess.SpawnTypes.TERM;
1282 - this.httprequest.process = childProcess.execFile(bash, ['bash', '-i'], options); // Start as active user
1283 - if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
1256 + this.httprequest.process = childProcess.execFile(bash, ['bash'], options); // Start as active user
1257 + if (process.platform == 'linux') { this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\'\nclear\n'); }
1258 }
1259 else if (sh)
1260 {
1287 - options.type = childProcess.SpawnTypes.TERM;
1261 this.httprequest.process = childProcess.execFile(sh, ['sh'], options); // Start as active user
1289 - if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands + "PS1='$ '\n"); }
1262 + if (process.platform == 'linux')
1263 + {
1264 + this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\'\n');
1265 + this.httprequest.process.stdin.write(' stty erase ^H\n');
1266 + this.httprequest.process.stdin.write("PS1='$ '\n");
1267 + this.httprequest.process.stdin.write(" clear\n");
1268 + }
1269 }
1270 else
1271 {
@@ -1301,11 +1280,8 @@ function createMeshCore(agent) {
1280 return;
1281 }
1282
1304 - if (this.httprequest.process.tcsetsize && this.httprequest.xoptions) { this.httprequest.process.tcsetsize(this.httprequest.xoptions.rows, this.httprequest.xoptions.cols); }
1305 -
1283 this.httprequest.process.tunnel = this;
1284 this.httprequest.process.on('exit', function (ecode, sig) { this.tunnel.end(); });
1308 - this.httprequest.process.stdin.write(" clear\n");
1285 this.httprequest.process.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
1286 this.httprequest.process.stdout.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
1287 this.pipe(this.httprequest.process.stdin, { dataTypeSkip: 1, end: false }); // 0 = Binary, 1 = Text.