mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-03 17:13:16 +00:00
1. Added comments to agentcore.c
2. Updated user-sessions to use getent passwd instead of /etc/passwd 3. Added user-sessions.getHomeFolder() for linux 4. Added gnome helper to fetch proxy settings from gnome
This commit is contained in:
38
modules/linux-gnome-helpers.js
Normal file
38
modules/linux-gnome-helpers.js
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
|
||||
function gnome_getProxySettings(uid)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh'], { env: { HOME: require('user-sessions').getHomeFolder(uid) }});
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
|
||||
child.stdin.write('gsettings list-recursively org.gnome.system.proxy | tr "\\n" "\\|" | tr "\\\'" "\\`" | awk \'{ count=split($0, res, "|");')
|
||||
child.stdin.write('for(a=0;a<count;++a)');
|
||||
child.stdin.write('{');
|
||||
child.stdin.write('split(res[a], modecheck, " ");');
|
||||
child.stdin.write('if(modecheck[2] == "mode")');
|
||||
child.stdin.write('{');
|
||||
child.stdin.write('split(modecheck[3], prx, "`"); mode = prx[2];');
|
||||
child.stdin.write('}');
|
||||
child.stdin.write('if(modecheck[1]=="org.gnome.system.proxy.http" && modecheck[2]=="host") { split(modecheck[3], hst, "`"); host = hst[2]; }');
|
||||
child.stdin.write('if(modecheck[1]=="org.gnome.system.proxy.http" && modecheck[2]=="port") { port = modecheck[3]; }');
|
||||
child.stdin.write('}');
|
||||
child.stdin.write('printf "{\\"mode\\": \\"%s\\", \\"host\\": \\"%s\\", \\"port\\": %s}", mode, host, port; }\'\nexit\n');
|
||||
child.waitExit();
|
||||
|
||||
try
|
||||
{
|
||||
return (JSON.parse(child.stdout.str.trim()));
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
return ({});
|
||||
}
|
||||
}
|
||||
|
||||
switch(process.platform)
|
||||
{
|
||||
case 'linux':
|
||||
module.exports = { getProxySettings: gnome_getProxySettings }
|
||||
break;
|
||||
}
|
||||
@@ -513,12 +513,21 @@ function UserSessions()
|
||||
// First step, is to see if there is a user logged in:
|
||||
this._recheckLoggedInUsers();
|
||||
}
|
||||
this.minUid = function minUid()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stderr.str = ''; child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdin.write("cat /etc/login.defs | grep UID_ | awk '{ if($1==\"UID_MIN\") { print $2; } }'\nexit\n");
|
||||
child.waitExit();
|
||||
return (parseInt(child.stdout.str.trim()) >= 0 ? parseInt(child.stdout.str.trim()) : 500);
|
||||
}
|
||||
this._users = function _users()
|
||||
{
|
||||
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('awk -F: \'($3 >= 0) {printf "%s:%s\\n", $1, $3}\' /etc/passwd\nexit\n');
|
||||
child.stdin.write("getent passwd | awk -F: '{ if($3>=0) { printf \"%s:%s\\n\", $1, $3; } }'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
var lines = child.stdout.str.split('\n');
|
||||
@@ -534,7 +543,7 @@ function UserSessions()
|
||||
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('awk -F: \'($3 >= 0) {printf "%s:%s\\n", $1, $3}\' /etc/passwd\nexit\n');
|
||||
child.stdin.write("getent passwd | awk -F: '{ if($3>=0) { printf \"%s:%s\\n\", $1, $3; } }'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
var lines = child.stdout.str.split('\n');
|
||||
@@ -568,12 +577,21 @@ function UserSessions()
|
||||
throw ('nobody logged into console');
|
||||
}
|
||||
|
||||
this.getHomeFolder = function getHomeFolder(id)
|
||||
{
|
||||
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("getent passwd " + id + " | awk -F: '{print $6}'\nexit\n");
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim());
|
||||
}
|
||||
this.getUid = function getUid(username)
|
||||
{
|
||||
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("cat /etc/passwd | awk -F: '($1==\"" + username + "\"){print $3}'\nexit\n");
|
||||
child.stdin.write("getent passwd \"" + username + "\" | awk -F: '{print $3}'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
var ret = parseInt(child.stdout.str);
|
||||
@@ -585,7 +603,7 @@ function UserSessions()
|
||||
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("cat /etc/passwd | awk -F: '($3==" + uid + "){print $1}'\nexit\n");
|
||||
child.stdin.write("getent passwd " + uid + " | awk -F: '{print $1}'\nexit\n");
|
||||
child.waitExit();
|
||||
if (child.stdout.str.length > 0) { return (child.stdout.str.trim()); }
|
||||
throw ('uid: ' + uid + ' NOT FOUND');
|
||||
|
||||
Reference in New Issue
Block a user