1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00
Files
MeshAgent/test/authtest.js
Bryan Roe 559928de5b The following updates, fix KVM for openSUSE and other distros with similar behavior
1. Removed 'setDisplay()' because it doesn't work
2. Added more descriptive error message when XOpenDisplay fails
3. Added ability to set XAUTHORITY in the child process if it wasn't set, by finding how X was started
2019-01-24 11:19:33 -08:00

26 lines
832 B
JavaScript

function getAuthToken()
{
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = '';
child.stdin.write('ps -e -o user -o command | awk {\'printf "%s,",$1;$1="";printf "%s\\n", $0\'} | grep X\nexit\n');
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
child.waitExit();
var lines = child.stdout.str.split('\n');
for (var i in lines) {
var tokens = lines[i].split(',');
if (tokens[0]) {
var items = tokens[1].split(' ');
for (var x = 0; x < items.length; ++x) {
if (items[x] == '-auth' && items.length > (x + 1)) {
return (items[x + 1]);
}
}
}
}
return (null);
}
console.log('AuthToken => ' + getAuthToken());
process.exit();