Added support for login shell for FreeBSD and MacOS

Bryan Roe committed Feb 5, 2020 at 13:36 UTC 248d9423fa59c043454f5c38afeef4c53c3c8441
1 file changed +9 -19
agents/meshcore.js
+9 -19
@@ -1238,6 +1238,7 @@ 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 login = process.platform == 'linux' ? '/bin/login' : '/usr/bin/login';
1242
1243 var env = { HISTCONTROL: 'ignoreboth', TERM: 'xterm' };
1244 if (this.httprequest.xoptions)
@@ -1248,31 +1249,20 @@ function createMeshCore(agent) {
1249 var options = { type: childProcess.SpawnTypes.TERM, uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: env };
1250 if (this.httprequest.xoptions && this.httprequest.xoptions.requireLogin)
1251 {
1251 - if (process.platform == 'linux')
1252 - {
1253 - if (!require('fs').existsSync('/bin/login')) { throw ('Unable to spawn login process'); }
1254 - this.httprequest.process = childProcess.execFile('/bin/login', ['login'], options); // Start login shell
1255 - }
1256 - else
1257 - {
1258 - throw ('Login Shell only supported on Linux at this time');
1259 - }
1252 + if (!require('fs').existsSync(login)) { throw ('Unable to spawn login process'); }
1253 + this.httprequest.process = childProcess.execFile(login, ['login'], options); // Start login shell
1254 }
1255 else if (bash)
1256 {
1263 - this.httprequest.process = childProcess.execFile(bash, ['bash'], options); // Start as active user
1264 - if (process.platform == 'linux') { this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\'\nclear\n'); }
1257 + this.httprequest.process = childProcess.execFile(bash, ['bash'], options); // Start bash
1258 + // Spaces at the beginning of lines are needed to hide commands from the command history
1259 + if (process.platform == 'linux') { this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
1260 }
1261 else if (sh)
1262 {
1268 - this.httprequest.process = childProcess.execFile(sh, ['sh'], options); // Start as active user
1269 - if (process.platform == 'linux')
1270 - {
1271 - this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\'\n');
1272 - this.httprequest.process.stdin.write(' stty erase ^H\n');
1273 - this.httprequest.process.stdin.write("PS1='$ '\n");
1274 - this.httprequest.process.stdin.write(" clear\n");
1275 - }
1263 + this.httprequest.process = childProcess.execFile(sh, ['sh'], options); // Start sh
1264 + // Spaces at the beginning of lines are needed to hide commands from the command history
1265 + if (process.platform == 'linux') { this.httprequest.process.stdin.write(' alias ls=\'ls --color=auto\';clear\n'); }
1266 }
1267 else
1268 {