mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-20 10:13:17 +00:00
1. Added 'getEnvFromPid' to user-sessions, to read environment vars by PID
2 Updated getXInfo() in monitor-info, so it'll try to get XAUTHORITY from env vars is it can't determine it by looking at the XServer instance.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -330,11 +330,36 @@ function monitorinfo()
|
|||||||
if (tokens.length == 3)
|
if (tokens.length == 3)
|
||||||
{
|
{
|
||||||
ret = { tty: tokens[1], xauthority: tokens[2] };
|
ret = { tty: tokens[1], xauthority: tokens[2] };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ret!=null)
|
if (ret == null)
|
||||||
{
|
{
|
||||||
|
// This Linux Distro does not spawn an XServer instance in the user session, that specifies the XAUTHORITY.
|
||||||
|
// So we're going to brute force it, by enumerating all processes owned by this user, and inspect the environment variables
|
||||||
|
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
|
child.stdout.str = '';
|
||||||
|
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
|
child.stdin.write("ps -e -o pid -o user | grep " + uname + " | awk '{ print $1 }'\nexit\n");
|
||||||
|
child.waitExit();
|
||||||
|
|
||||||
|
var lines = child.stdout.str.split('\n');
|
||||||
|
for(var n in lines)
|
||||||
|
{
|
||||||
|
var ln = lines[n].trim();
|
||||||
|
if(ln.length>0)
|
||||||
|
{
|
||||||
|
var e = require('user-sessions').getEnvFromPid(ln);
|
||||||
|
if(e.XAUTHORITY && e.DISPLAY)
|
||||||
|
{
|
||||||
|
ret = { tty: '?', xauthority: e.XAUTHORITY, display: e.DISPLAY };
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// We need to find $DISPLAY by looking at all the processes running on the same tty as the XServer instance for this user session
|
||||||
child = require('child_process').execFile('/bin/sh', ['sh']);
|
child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||||
child.stdout.str = '';
|
child.stdout.str = '';
|
||||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||||
|
|||||||
@@ -590,6 +590,30 @@ function UserSessions()
|
|||||||
child.waitExit();
|
child.waitExit();
|
||||||
return (child.stdout.str.trim());
|
return (child.stdout.str.trim());
|
||||||
};
|
};
|
||||||
|
this.getEnvFromPid = function getEnvFromPid(pid)
|
||||||
|
{
|
||||||
|
var ret = {};
|
||||||
|
var ps, psx, v, vs = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ps = require('fs').readFileSync('/proc/' + pid + '/environ');
|
||||||
|
}
|
||||||
|
catch(pse)
|
||||||
|
{
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (psx = 0; psx < ps.length; ++psx)
|
||||||
|
{
|
||||||
|
if (ps[psx] == 0)
|
||||||
|
{
|
||||||
|
v = ps.slice(vs, psx).toString().split('=');
|
||||||
|
ret[v[0]] = v[1];
|
||||||
|
vs = psx + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
};
|
||||||
|
|
||||||
this.on('changed', this._recheckLoggedInUsers); // For linux Lock/Unlock monitoring, we need to watch for LogOn/LogOff, and keep track of the UID.
|
this.on('changed', this._recheckLoggedInUsers); // For linux Lock/Unlock monitoring, we need to watch for LogOn/LogOff, and keep track of the UID.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user