diff --git a/modules/user-sessions.js b/modules/user-sessions.js index 5379fd2..db3fd8a 100644 --- a/modules/user-sessions.js +++ b/modules/user-sessions.js @@ -788,7 +788,48 @@ function UserSessions() child.waitExit(); return (JSON.parse(child.stdout.str.trim().replace(',]',']'))); } - this.consoleUid = function consoleUid() + this.activeUids = function activeUids() + { + return (this.consoleUid({ active: true })); + }; + this.virtualUids = function virtualUids() + { + var active = this.activeUids(); + + 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("ps -e -o uid -o pid -o cmd | grep Xvfb | tr '\\n' '`' | awk '{"); + child.stdin.write('printf "[";'); + child.stdin.write('del="";'); + child.stdin.write('n=split($0, lines, "`");'); + child.stdin.write('for(i=1;i=' + min + ')'); child.stdin.write(' {'); - child.stdin.write(' if(tok[4]=="" || tok[4]~/^pts\\//) { continue; }'); + if (options && options.active == true) + { + child.stdin.write(' if(tok[4]=="") { continue; }'); + } + else + { + child.stdin.write(' if(tok[4]=="" || tok[4]~/^pts\\//) { continue; }'); + } child.stdin.write(' printf "%s{\\"uid\\": \\"%s\\", \\"sid\\": \\"%s\\"}", del, tok[2], tok[1];'); child.stdin.write(' del=",";'); child.stdin.write(' }'); @@ -857,18 +905,59 @@ function UserSessions() 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("loginctl show-session -p State " + sids.join(' ') + " | grep State= | tr '\\n' '`' | awk -F'`' '{"); + if (options && options.active == true) + { + child.stdin.write(' printf("[");'); + child.stdin.write(' _first="";'); + } child.stdin.write(' for(n=1;n 0) + if (options && options.active == true) { - return (parseInt(info1[i - 1].uid)); + try + { + var ret = JSON.parse(child.stdout.str); + for (var j=0;j 0) + { + return (parseInt(info1[i - 1].uid)); + } } }