mirror of
https://github.com/Ylianst/MeshAgent
synced 2026-01-11 21:13:17 +00:00
GC reference update
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -16,7 +16,11 @@ limitations under the License.
|
||||
|
||||
try { Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : undefined); } }); } catch (e) { }
|
||||
|
||||
|
||||
function stdparser(c)
|
||||
{
|
||||
if (this.str == null) { this.str = ''; }
|
||||
this.str += c.toString();
|
||||
}
|
||||
|
||||
function dbus(address, uid, env)
|
||||
{
|
||||
@@ -154,8 +158,8 @@ module.exports = dbus;
|
||||
module.exports.hasService = function hasService(name)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', stdparser);
|
||||
child.stdout.str = ''; child.stdout.on('data', stdparser);
|
||||
child.stdin.write('cat /usr/share/dbus-1/services/*.service | grep "' + name + '" | awk -F= \'{ if( $2=="' + name + '" ) { print $2; } }\'\nexit\n');
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim() != '');
|
||||
|
||||
@@ -49,6 +49,11 @@ function sendConsoleText(msg)
|
||||
require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: msg });
|
||||
}
|
||||
|
||||
function stdparser(c)
|
||||
{
|
||||
if (this.str == null) { this.str = ''; }
|
||||
this.str += c.toString();
|
||||
}
|
||||
|
||||
function messageBox()
|
||||
{
|
||||
@@ -214,11 +219,12 @@ function linux_messageBox()
|
||||
}
|
||||
if (xinfo == null) { return (false); }
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh'], { uid: uid, env: { XAUTHORITY: xinfo.xauthority ? xinfo.xauthority : "", DISPLAY: xinfo.display } });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.str = ''; child.stdout.on('data', stdparser );
|
||||
child.stdin.write(location + ' --help-all | grep timeout\nexit\n');
|
||||
child.stderr.on('data', function (e) { });
|
||||
child.waitExit();
|
||||
Object.defineProperty(this, "_timeout", { value: child.stdout.str.trim() == '' ? false : true });
|
||||
child = null;
|
||||
return (this._timeout);
|
||||
}
|
||||
else
|
||||
@@ -334,7 +340,7 @@ function linux_messageBox()
|
||||
value: (function ()
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = ''; child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.on('data', stdparser);
|
||||
child.stdin.write("whereis notify-send | awk '{ print $2 }'\nexit\n");
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim() == '' ? null : { path: child.stdout.str.trim() });
|
||||
|
||||
@@ -34,6 +34,12 @@ var PropertyChangeMask = (1 << 22);
|
||||
var PropertyNotify = 28;
|
||||
var AnyPropertyType = 0;
|
||||
|
||||
function stdparser(c)
|
||||
{
|
||||
if (this.str == null) { this.str = ''; }
|
||||
this.str += c.toString();
|
||||
}
|
||||
|
||||
function getLibInfo(libname)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
@@ -499,7 +505,7 @@ function monitorinfo()
|
||||
if (process.platform != 'linux') { return(info); }
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.on('data', stdparser);
|
||||
child.stdin.write("ps -e -o uid -o cmd | grep X | grep " + uid + " | tr '\\n' '`' | awk '{ xl=split($2,x,\"/\"); print x[xl]; }'\nexit\n");
|
||||
child.waitExit();
|
||||
if(child.stdout.str.trim() != '')
|
||||
@@ -571,11 +577,13 @@ function monitorinfo()
|
||||
// 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.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.on('data', stdparser);
|
||||
child.stdin.write("ps -e -o tty -o pid -o user:9999 | grep " + ret.tty + " | grep " + uname + " | awk '{ print $2 }' \nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
var lines = child.stdout.str.split('\n');
|
||||
child = null;
|
||||
|
||||
var ps, psx, v, vs = 0;
|
||||
for(var x in lines)
|
||||
{
|
||||
|
||||
@@ -16,13 +16,18 @@ limitations under the License.
|
||||
|
||||
var promise = require('promise');
|
||||
|
||||
function stdparser(c)
|
||||
{
|
||||
if (this.str == null) { this.str = ''; }
|
||||
this.str += c.toString();
|
||||
}
|
||||
|
||||
if (process.platform == 'linux' || process.platform == 'darwin' || process.platform == 'freebsd')
|
||||
{
|
||||
function findPath(app)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.on('data', stdparser);
|
||||
if (process.platform == 'linux' || process.platform == 'freebsd')
|
||||
{
|
||||
child.stdin.write("whereis " + app + " | awk '{ print $2 }'\nexit\n");
|
||||
@@ -38,90 +43,81 @@ if (process.platform == 'linux' || process.platform == 'darwin' || process.platf
|
||||
}
|
||||
}
|
||||
|
||||
function stdouthelper(c)
|
||||
{
|
||||
if (c.toString().includes('<DISMISSED>')) { this.stdin.write('exit\n'); }
|
||||
}
|
||||
function exithelper()
|
||||
{
|
||||
if (this.timeout != null) { clearTimeout(this.timeout); }
|
||||
this.toast.resolve('DISMISSED');
|
||||
|
||||
this.toast.child = null;
|
||||
this.toast = null;
|
||||
}
|
||||
function Toaster()
|
||||
{
|
||||
this._ObjectID = 'toaster';
|
||||
this.Toast = function Toast(title, caption, tsid)
|
||||
{
|
||||
//var retVal = new promise(function (res, rej) { this._res = res; this._rej = rej; });
|
||||
var retVal = new promise(promise.defaultInit);
|
||||
var weakRet = WeakReference(new promise(promise.defaultInit));
|
||||
if (title == 'MeshCentral') { try { title = require('MeshAgent').displayName; } catch (x) { } }
|
||||
|
||||
retVal.title = title;
|
||||
retVal.caption = caption;
|
||||
weakRet.object.title = title;
|
||||
weakRet.object.caption = caption;
|
||||
|
||||
switch (process.platform)
|
||||
{
|
||||
case 'win32':
|
||||
{
|
||||
var cid;
|
||||
retVal.options = { env: { _title: title, _caption: caption } };
|
||||
weakRet.object.options = { env: { _title: title, _caption: caption } };
|
||||
for (var c1e in process.env)
|
||||
{
|
||||
retVal.options.env[c1e] = process.env[c1e];
|
||||
weakRet.object.options.env[c1e] = process.env[c1e];
|
||||
}
|
||||
try
|
||||
{
|
||||
retVal.options.uid = tsid == null ? require('user-sessions').consoleUid() : tsid;
|
||||
if (retVal.options.uid == (cid = require('user-sessions').getProcessOwnerName(process.pid).tsid))
|
||||
weakRet.object.options.uid = tsid == null ? require('user-sessions').consoleUid() : tsid;
|
||||
if (weakRet.object.options.uid == (cid = require('user-sessions').getProcessOwnerName(process.pid).tsid))
|
||||
{
|
||||
delete retVal.options.uid;
|
||||
delete weakRet.object.options.uid;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(tsid != null && cid != 0)
|
||||
{
|
||||
retVal.reject('Insufficient permission to display toast as uid: ' + tsid);
|
||||
return (retVal);
|
||||
weakRet.object.reject('Insufficient permission to display toast as uid: ' + tsid);
|
||||
return (weakRet.object);
|
||||
}
|
||||
retVal.options.type = require('child_process').SpawnTypes.USER;
|
||||
weakRet.object.options.type = require('child_process').SpawnTypes.USER;
|
||||
}
|
||||
}
|
||||
catch (ee)
|
||||
{
|
||||
retVal.reject('Cannot display user notification when a user is not logged in');
|
||||
return (retVal);
|
||||
weakRet.object.reject('Cannot display user notification when a user is not logged in');
|
||||
return (weakRet.object);
|
||||
}
|
||||
|
||||
retVal.child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], retVal.options);
|
||||
retVal.child.descriptorMetadata = 'toaster';
|
||||
retVal.child.toast = retVal;
|
||||
retVal.child.stdout.stdin = retVal.child.stdin;
|
||||
retVal.child.stderr.stdin = retVal.child.stdin;
|
||||
//retVal.child.stdout.on('data', function (c) { if (c.toString().includes('<DISMISSED>')) { this.stdin.write('exit\n'); } });
|
||||
//retVal.child.stderr.once('data', function (c) { this.stdin.write('$objBalloon.dispose();exit\n'); });
|
||||
retVal.child.stdout.on('data', stdouthelper);
|
||||
retVal.child.stdin.write('[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")\r\n');
|
||||
retVal.child.stdin.write('$objBalloon = New-Object System.Windows.Forms.NotifyIcon\r\n');
|
||||
retVal.child.stdin.write('$objBalloon.Icon = [System.Drawing.SystemIcons]::Information\r\n');
|
||||
retVal.child.stdin.write('$objBalloon.Visible = $True\r\n');
|
||||
retVal.child.stdin.write('Register-ObjectEvent -InputObject $objBalloon -EventName BalloonTipClosed -Action { $objBalloon.dispose();Write-Host "<`DISMISSED`>" }')
|
||||
retVal.child.stdin.write('$objBalloon.ShowBalloonTip(10000, $env:_title, $env:_caption, 0)\r\n');
|
||||
//retVal.child.timeout = setTimeout(function (c)
|
||||
//{
|
||||
// c.timeout = null;
|
||||
// c.stdin.write('$objBalloon.dispose();exit\n');
|
||||
//}, 10000, retVal.child);
|
||||
//retVal.child.on('exit', function ()
|
||||
//{
|
||||
// if (this.timeout != null) { clearTimeout(this.timeout); }
|
||||
// this.toast._res('DISMISSED');
|
||||
//});
|
||||
retVal.child.on('exit', exithelper);
|
||||
|
||||
return (retVal);
|
||||
weakRet.object.child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], weakRet.object.options);
|
||||
weakRet.object.child.weak = weakRet;
|
||||
weakRet.object.child.descriptorMetadata = 'toaster';
|
||||
weakRet.object.child.stdout.on('data', function (c) { if (c.toString().includes('<DISMISSED>')) { this.parent.stdin.write('exit\n'); } });
|
||||
weakRet.object.child.stderr.once('data', function (c) { this.parent.stdin.write('$objBalloon.dispose();exit\n'); });
|
||||
weakRet.object.child.stdin.write('[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")\r\n');
|
||||
weakRet.object.child.stdin.write('$objBalloon = New-Object System.Windows.Forms.NotifyIcon\r\n');
|
||||
weakRet.object.child.stdin.write('$objBalloon.Icon = [System.Drawing.SystemIcons]::Information\r\n');
|
||||
weakRet.object.child.stdin.write('$objBalloon.Visible = $True\r\n');
|
||||
weakRet.object.child.stdin.write('Register-ObjectEvent -InputObject $objBalloon -EventName BalloonTipClosed -Action { $objBalloon.dispose();Write-Host "<`DISMISSED`>" }')
|
||||
weakRet.object.child.stdin.write('$objBalloon.ShowBalloonTip(10000, $env:_title, $env:_caption, 0)\r\n');
|
||||
weakRet.object.child.timeout = setTimeout(function (c)
|
||||
{
|
||||
c.timeout = null;
|
||||
c.stdin.write('$objBalloon.dispose();exit\n');
|
||||
}, 10000, weakRet.object.child);
|
||||
weakRet.object.child.on('exit', function ()
|
||||
{
|
||||
if (this.weak.isAlive())
|
||||
{
|
||||
var p = this.weak.object;
|
||||
if (p.child.timeout != null) { clearTimeout(p.child.timeout); }
|
||||
p.resolve('DISMISSED');
|
||||
p.child = null;
|
||||
this.weak = null;
|
||||
}
|
||||
});
|
||||
|
||||
return (weakRet.object);
|
||||
}
|
||||
break;
|
||||
case 'freebsd':
|
||||
@@ -129,14 +125,14 @@ function Toaster()
|
||||
{
|
||||
try
|
||||
{
|
||||
retVal.consoleUid = require('user-sessions').consoleUid();
|
||||
retVal.xinfo = require('monitor-info').getXInfo(retVal.consoleUid);
|
||||
retVal.username = require('user-sessions').getUsername(retVal.consoleUid);
|
||||
weakRet.object.consoleUid = require('user-sessions').consoleUid();
|
||||
weakRet.object.xinfo = require('monitor-info').getXInfo(weakRet.object.consoleUid);
|
||||
weakRet.object.username = require('user-sessions').getUsername(weakRet.object.consoleUid);
|
||||
}
|
||||
catch (xxe)
|
||||
{
|
||||
retVal.reject(xxe);
|
||||
return (retVal);
|
||||
weakRet.object.reject(xxe);
|
||||
return (weakRet.object);
|
||||
}
|
||||
|
||||
if (require('message-box').zenity)
|
||||
@@ -147,19 +143,18 @@ function Toaster()
|
||||
if (require('message-box').zenity.timeout)
|
||||
{
|
||||
// Timeout Supported
|
||||
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + retVal.title, '--text=' + retVal.caption, '--timeout=5'], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + weakRet.object.title, '--text=' + weakRet.object.caption, '--timeout=5'], { uid: weakRet.object.consoleUid, env: { XAUTHORITY: weakRet.object.xinfo.xauthority, DISPLAY: weakRet.object.xinfo.display } });
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Timeout Support, so we must fake it
|
||||
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + retVal.title, '--text=' + retVal.caption], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
|
||||
retVal.child.timeout = setTimeout(function (c) { c.timeout = null; c.kill(); }, 5000, retVal.child);
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + weakRet.object.title, '--text=' + weakRet.object.caption], { uid: weakRet.object.consoleUid, env: { XAUTHORITY: weakRet.object.xinfo.xauthority, DISPLAY: weakRet.object.xinfo.display } });
|
||||
weakRet.object.child.timeout = setTimeout(function (c) { c.timeout = null; c.kill(); }, 5000, weakRet.object.child);
|
||||
}
|
||||
retVal.child.descriptorMetadata = 'toaster (zenity/messagebox)'
|
||||
weakRet.object.child.descriptorMetadata = 'toaster (zenity/messagebox)'
|
||||
}
|
||||
else if (require('message-box').zenity.broken || require('message-box').zenity.version[0] < 3 || (require('message-box').zenity.version[0] == 3 && require('message-box').zenity.version[1] < 10))
|
||||
{
|
||||
|
||||
// ZENITY Notification is broken
|
||||
if (require('message-box').notifysend)
|
||||
{
|
||||
@@ -167,16 +162,16 @@ function Toaster()
|
||||
if (require('user-sessions').whoami() == 'root')
|
||||
{
|
||||
// We're root, so we must run in correct context
|
||||
var xdg = require('user-sessions').findEnv(retVal.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
retVal.child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
retVal.child.stdin.write('su - ' + retVal.username + ' -c "export DISPLAY=' + retVal.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\nexit\n');
|
||||
var xdg = require('user-sessions').findEnv(weakRet.object.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
weakRet.object.child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
weakRet.object.child.stdin.write('su - ' + weakRet.object.username + ' -c "export DISPLAY=' + weakRet.object.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + weakRet.object.title + '\' \'' + weakRet.object.caption + '\'"\nexit\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're a regular user, so we don't need to do anything special
|
||||
retVal.child = require('child_process').execFile(require('message-box').notifysend.path, ['notify-send', retVal.title, retVal.caption]);
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').notifysend.path, ['notify-send', weakRet.object.title, weakRet.object.caption]);
|
||||
}
|
||||
retVal.child.descriptorMetadata = 'toaster (notify-send)'
|
||||
weakRet.object.child.descriptorMetadata = 'toaster (notify-send)'
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -184,34 +179,34 @@ function Toaster()
|
||||
if (require('message-box').zenity.timeout)
|
||||
{
|
||||
// Timeout Supported
|
||||
retVal._mb = require('message-box').create(retVal.title, retVal.caption, 5, 1);
|
||||
retVal._mb.toast = retVal;
|
||||
retVal._mb.then(function () { this.toast.resolve('DISMISSED'); }, function (e) { this.toast.resolve('DISMISSED'); });
|
||||
return (retVal);
|
||||
weakRet.object._mb = require('message-box').create(weakRet.object.title, weakRet.object.caption, 5, 1);
|
||||
weakRet.object._mb.weak = weakRet;
|
||||
weakRet.object._mb.then(function () { this.weak.object.resolve('DISMISSED'); }, function (e) { this.weak.object.resolve('DISMISSED'); });
|
||||
return (weakRet.object);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No Timeout Support, so we must fake it
|
||||
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + retVal.title, '--text=' + retVal.caption], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
|
||||
retVal.child.timeout = setTimeout(function (c) { c.timeout = null; c.kill(); }, 5000, retVal.child);
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--info', '--title=' + weakRet.object.title, '--text=' + weakRet.object.caption], { uid: weakRet.object.consoleUid, env: { XAUTHORITY: weakRet.object.xinfo.xauthority, DISPLAY: weakRet.object.xinfo.display } });
|
||||
weakRet.object.child.timeout = setTimeout(function (c) { c.timeout = null; c.kill(); }, 5000, weakRet.object.child);
|
||||
}
|
||||
retVal.child.descriptorMetadata = 'toaster (zenity/messagebox)'
|
||||
weakRet.object.child.descriptorMetadata = 'toaster (zenity/messagebox)'
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use ZENITY Notification
|
||||
retVal.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--notification', '--title=' + title, '--text=' + caption, '--timeout=5'], { uid: retVal.consoleUid, env: { XAUTHORITY: retVal.xinfo.xauthority, DISPLAY: retVal.xinfo.display } });
|
||||
retVal.child.descriptorMetadata = 'toaster (zenity/notification)'
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').zenity.path, ['zenity', '--notification', '--title=' + title, '--text=' + caption, '--timeout=5'], { uid: weakRet.object.consoleUid, env: { XAUTHORITY: weakRet.object.xinfo.xauthority, DISPLAY: weakRet.object.xinfo.display } });
|
||||
weakRet.object.child.descriptorMetadata = 'toaster (zenity/notification)'
|
||||
}
|
||||
retVal.child.parent = retVal;
|
||||
retVal.child.stderr.str = '';
|
||||
retVal.child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
retVal.child.stdout.on('data', function (chunk) { });
|
||||
retVal.child.on('exit', function (code)
|
||||
weakRet.object.child.weak = weakRet;
|
||||
weakRet.object.child.stderr.str = '';
|
||||
weakRet.object.child.stderr.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
weakRet.object.child.stdout.on('data', function (chunk) { });
|
||||
weakRet.object.child.on('exit', function (code)
|
||||
{
|
||||
if (this.timeout) { clearTimeout(this.timeout); }
|
||||
this.parent.resolve('DISMISSED');
|
||||
this.weak.object.resolve('DISMISSED');
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -220,19 +215,19 @@ function Toaster()
|
||||
if (util)
|
||||
{
|
||||
// use KDIALOG
|
||||
var xdg = require('user-sessions').findEnv(retVal.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
if (!retVal.xinfo || !retVal.xinfo.display || !retVal.xinfo.xauthority)
|
||||
var xdg = require('user-sessions').findEnv(weakRet.object.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
if (!weakRet.object.xinfo || !weakRet.object.xinfo.display || !weakRet.object.xinfo.xauthority)
|
||||
{
|
||||
retVal.reject('Internal Error');
|
||||
return (retVal);
|
||||
weakRet.object.reject('Internal Error');
|
||||
return (weakRet.object);
|
||||
}
|
||||
|
||||
retVal._notify = require('child_process').execFile(util, ['kdialog', '--title', retVal.title, '--passivepopup', retVal.caption, '5'], { uid: retVal.consoleUid, env: { DISPLAY: retVal.xinfo.display, XAUTHORITY: retVal.xinfo.xauthority, XDG_RUNTIME_DIR: xdg } });
|
||||
retVal._notify.descriptorMetadata = 'toaster (kdialog)'
|
||||
retVal._notify.parent = retVal;
|
||||
retVal._notify.stdout.on('data', function (chunk) { });
|
||||
retVal._notify.stderr.on('data', function (chunk) { });
|
||||
retVal._notify.on('exit', function (code) { this.parent.resolve('DISMISSED'); });
|
||||
weakRet.object._notify = require('child_process').execFile(util, ['kdialog', '--title', weakRet.object.title, '--passivepopup', weakRet.object.caption, '5'], { uid: weakRet.object.consoleUid, env: { DISPLAY: weakRet.object.xinfo.display, XAUTHORITY: weakRet.object.xinfo.xauthority, XDG_RUNTIME_DIR: xdg } });
|
||||
weakRet.object._notify.descriptorMetadata = 'toaster (kdialog)'
|
||||
weakRet.object._notify.weak = weakRet;
|
||||
weakRet.object._notify.stdout.on('data', function (chunk) { });
|
||||
weakRet.object._notify.stderr.on('data', function (chunk) { });
|
||||
weakRet.object._notify.on('exit', function (code) { this.weak.object.resolve('DISMISSED'); });
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -242,39 +237,39 @@ function Toaster()
|
||||
if (require('user-sessions').whoami() == 'root')
|
||||
{
|
||||
// We're root, so we must run in correct context
|
||||
var xdg = require('user-sessions').findEnv(retVal.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
retVal.child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
retVal.child.stdin.write('su - ' + retVal.username + ' -c "export DISPLAY=' + retVal.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + retVal.title + '\' \'' + retVal.caption + '\'"\nexit\n');
|
||||
var xdg = require('user-sessions').findEnv(weakRet.object.consoleUid, 'XDG_RUNTIME_DIR'); if (xdg == null) { xdg = ''; }
|
||||
weakRet.object.child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
weakRet.object.child.stdin.write('su - ' + weakRet.object.username + ' -c "export DISPLAY=' + weakRet.object.xinfo.display + '; export XDG_RUNTIME_DIR=' + xdg + '; notify-send \'' + weakRet.object.title + '\' \'' + weakRet.object.caption + '\'"\nexit\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're a regular user, so we don't need to do anything special
|
||||
retVal.child = require('child_process').execFile(require('message-box').notifysend.path, ['notify-send', retVal.title, retVal.caption]);
|
||||
weakRet.object.child = require('child_process').execFile(require('message-box').notifysend.path, ['notify-send', weakRet.object.title, weakRet.object.caption]);
|
||||
}
|
||||
retVal.child.descriptorMetadata = 'toaster (notify-send)'
|
||||
weakRet.object.child.descriptorMetadata = 'toaster (notify-send)'
|
||||
}
|
||||
else if (require('message-box').xmessage)
|
||||
{
|
||||
retVal._mb = require('message-box').create(title, caption, 5, 'OK');
|
||||
retVal._mb.ret = retVal;
|
||||
retVal._mb.then(function () { this.ret.resolve('DISMISSED'); }, function () { this.ret.resolve('DISMISSED'); });
|
||||
weakRet.object._mb = require('message-box').create(title, caption, 5, 'OK');
|
||||
weakRet.object._mb.weak = weakRet;
|
||||
weakRet.object._mb.then(function () { this.ret.resolve('DISMISSED'); }, function () { this.weak.object.resolve('DISMISSED'); });
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.reject('Zenity/KDialog/xmessage not found');
|
||||
weakRet.object.reject('Zenity/KDialog/xmessage not found');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'darwin':
|
||||
retVal._toast = require('message-box').notify(title, caption);
|
||||
retVal._toast.parent = retVal;
|
||||
retVal._toast.then(function (v) { this.parent.resolve(v); }, function (e) { this.parent.reject(e); });
|
||||
weakRet.object._toast = require('message-box').notify(title, caption);
|
||||
weakRet.object._toast.weak = weakRet;
|
||||
weakRet.object._toast.then(function (v) { this.weak.object.resolve(v); }, function (e) { this.weak.object.reject(e); });
|
||||
break;
|
||||
}
|
||||
|
||||
return (retVal);
|
||||
return (weakRet.object);
|
||||
};
|
||||
if(process.platform == 'win32')
|
||||
{
|
||||
@@ -312,8 +307,8 @@ if (process.platform == 'linux' && !require('linux-dbus').hasService)
|
||||
require('linux-dbus').hasService = function hasService(name)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
|
||||
child.stderr.str = ''; child.stderr.on('data', stdparser);
|
||||
child.stdout.str = ''; child.stdout.on('data', stdparser);
|
||||
child.stdin.write('cat /usr/share/dbus-1/services/*.service | grep "' + name + '" | awk -F= \'{ if( $2=="' + name + '" ) { print $2; } }\'\nexit\n');
|
||||
child.waitExit();
|
||||
return (child.stdout.str.trim() != '');
|
||||
|
||||
@@ -58,6 +58,11 @@ function columnParse(data, delimiter)
|
||||
return (ret);
|
||||
}
|
||||
|
||||
function stdparser(c)
|
||||
{
|
||||
if (this.str == null) { this.str = ''; }
|
||||
this.str += c.toString();
|
||||
}
|
||||
|
||||
function UserSessions()
|
||||
{
|
||||
@@ -445,7 +450,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.stdout.on('data', stdparser);
|
||||
child.stdin.write("getent passwd \"" + username + "\" | awk -F: '{print $3}'\nexit\n");
|
||||
child.waitExit();
|
||||
|
||||
@@ -564,8 +569,8 @@ function UserSessions()
|
||||
this.consoleUid = function consoleUid()
|
||||
{
|
||||
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.stdout.str = ''; child.stdout.on('data', stdparser);
|
||||
child.stderr.str = ''; child.stderr.on('data', stdparser);
|
||||
child.stdin.write("who | tr '\\n' '`' | awk -F'`' '{");
|
||||
child.stdin.write(" for(i=1;i<NF;++i) ");
|
||||
child.stdin.write(" { ");
|
||||
@@ -620,8 +625,7 @@ function UserSessions()
|
||||
this.getUsername = function getUsername(uid)
|
||||
{
|
||||
var child = require('child_process').execFile('/bin/sh', ['sh']);
|
||||
child.stdout.str = '';
|
||||
child.stdout.on('data', function (chunk) { this.str += chunk.toString(); });
|
||||
child.stdout.on('data', stdparser);
|
||||
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()); }
|
||||
@@ -1014,6 +1018,7 @@ function UserSessions()
|
||||
this.__resolver = res;
|
||||
this.__rejector = rej;
|
||||
});
|
||||
p.descriptorMetadata = 'user-sessions: enumerateUsers()';
|
||||
p.__handler = function __handler(users)
|
||||
{
|
||||
p.__resolver(users);
|
||||
|
||||
Reference in New Issue
Block a user