1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-16 00:03:45 +00:00

Updated installer to save ID of user that installed agent

This commit is contained in:
Bryan Roe
2020-08-21 19:41:19 -07:00
parent ad0c6026b5
commit 7cc0f0c213
3 changed files with 24 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@@ -22,9 +22,20 @@ function installService(params)
if (process.platform == 'win32')
{
proxyFile = proxyFile.split('.exe').join('.proxy');
params.push('--installedByUser="' + require('win-registry').usernameToUserKey(require('user-sessions').getProcessOwnerName(process.pid).name) + '"');
}
else
{
var u = require('user-sessions').tty();
var uid = 0;
try
{
uid = require('user-sessions').getUid(u);
}
catch(e)
{
}
params.push('--installedByUser=' + uid);
proxyFile += '.proxy';
}

View File

@@ -969,6 +969,17 @@ function UserSessions()
if(process.platform != 'win32') // Linux, MacOS, FreeBSD
{
this.tty = function tty()
{
var child = require('child_process').execFile('/bin/sh', ['sh'], { type: require('child_process').SpawnTypes.TERM });
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("tty | awk -F/ '{ printf \"\\x1e%s\\x1e\",$2; }'\nexit\n");
child.stdin.write("tty\nexit\n");
child.waitExit();
var val = child.stdout.str.split('\x1e');
return (val.length > 1 ? val[1] : 'root');
}
this.Self = function Self()
{
var child = require('child_process').execFile('/usr/bin/id', ['id', '-u']);