1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-18 01:03:14 +00:00

Added user-sessions.Current() on FreeBSD

This commit is contained in:
Bryan Roe
2020-03-05 16:18:42 -08:00
parent 5455cc5756
commit c5a559f011
2 changed files with 28 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -592,6 +592,27 @@ function UserSessions()
// First step, is to see if there is a user logged in:
this._recheckLoggedInUsers();
}
else
{
this.Current = function Current(cb)
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
child.stdin.write("who | tr '\\n' '`' | awk -F'`' '" + '{ printf "{"; for(a=1;a<NF;++a) { n=split($a, tok, " "); printf "%s\\"%s\\": \\"%s\\"", (a>1?",":""), tok[2], tok[1]; } printf "}"; }\'\nexit\n');
child.waitExit();
var ret = JSON.parse(child.stdout.str.trim());
for (var key in ret)
{
ret[key] = { Username: ret[key], SessionId: key, State: 'Active', uid: this.getUid(ret[key]) };
}
if (cb)
{
cb.call(this, ret);
}
}
}
this.minUid = function minUid()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);