Improved toast notifications

This commit is contained in:
Ylian Saint-Hilaire 2018-04-20 14:23:41 -07:00
parent bd82453c3b
commit e8294491cb
6 changed files with 109 additions and 52 deletions

View File

@ -343,7 +343,7 @@ function run(argv) {
if (mestate.ProvisioningState.stateStr == 'PRE') { str += ', pre-provisioning state'; } if (mestate.ProvisioningState.stateStr == 'PRE') { str += ', pre-provisioning state'; }
else if (mestate.ProvisioningState.stateStr == 'IN') { str += ', in-provisioning state'; } else if (mestate.ProvisioningState.stateStr == 'IN') { str += ', in-provisioning state'; }
else if (mestate.ProvisioningState.stateStr == 'POST') { if (mestate.ProvisioningMode.modeStr == 'ENTERPRISE') { str += ', activated in ' + ["none", "client control mode", "admin control mode", "remote assistance mode"][mestate.controlmode.controlMode]; } else { str += ', activated in ' + mestate.ProvisioningMode.modeStr; } } else if (mestate.ProvisioningState.stateStr == 'POST') { if (mestate.ProvisioningMode.modeStr == 'ENTERPRISE') { str += ', activated in ' + ["none", "client control mode", "admin control mode", "remote assistance mode"][mestate.controlmode.controlMode]; } else { str += ', activated in ' + mestate.ProvisioningMode.modeStr; } }
if (mestate.ehbc.EHBC == true) { str += ', EHBC enabled'; } if ((mestate.ehbc) && (mestate.ehbc.EHBC == true)) { str += ', EHBC enabled'; }
str += '.'; str += '.';
if (mestate.net0 != null) { str += '\r\nWired ' + ((mestate.net0.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net0.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net0.mac + (mestate.net0.address == '0.0.0.0' ? '' : (', ' + mestate.net0.address)); } if (mestate.net0 != null) { str += '\r\nWired ' + ((mestate.net0.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net0.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net0.mac + (mestate.net0.address == '0.0.0.0' ? '' : (', ' + mestate.net0.address)); }
if (mestate.net1 != null) { str += '\r\nWireless ' + ((mestate.net1.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net1.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net1.mac + (mestate.net1.address == '0.0.0.0' ? '' : (', ' + mestate.net1.address)); } if (mestate.net1 != null) { str += '\r\nWireless ' + ((mestate.net1.enabled == 1) ? 'Enabled' : 'Disabled') + ((mestate.net1.dhcpEnabled == 1) ? ', DHCP' : ', Static') + ', ' + mestate.net1.mac + (mestate.net1.address == '0.0.0.0' ? '' : (', ' + mestate.net1.address)); }

View File

@ -852,7 +852,7 @@ function createMeshCore(agent) {
var response = null; var response = null;
switch (cmd) { switch (cmd) {
case 'help': { // Displays available commands case 'help': { // Displays available commands
response = 'aaaAvailable commands: help, info, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast.'; response = 'Available commands: help, info, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast.';
break; break;
} }
case 'toast': { case 'toast': {

View File

@ -1,13 +1,25 @@
/*
Copyright 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// JavaScript source code // JavaScript source code
var GM = require('_GenericMarshal'); var GM = require('_GenericMarshal');
function processManager() {
function processManager()
{
this._ObjectID = 'processManager'; this._ObjectID = 'processManager';
switch(process.platform) switch (process.platform) {
{
case 'win32': case 'win32':
this._kernel32 = GM.CreateNativeProxy('kernel32.dll'); this._kernel32 = GM.CreateNativeProxy('kernel32.dll');
this._kernel32.CreateMethod('GetLastError'); this._kernel32.CreateMethod('GetLastError');
@ -20,24 +32,19 @@ function processManager()
break; break;
default: default:
throw (process.platform + ' not supported'); throw (process.platform + ' not supported');
break;
} }
this.getProcesses = function getProcesses(callback) this.getProcesses = function getProcesses(callback) {
{ switch (process.platform) {
switch(process.platform)
{
default: default:
throw ('Enumerating processes on ' + process.platform + ' not supported'); throw ('Enumerating processes on ' + process.platform + ' not supported');
break;
case 'win32': case 'win32':
var retVal = []; var retVal = [];
var h = this._kernel32.CreateToolhelp32Snapshot(2, 0); var h = this._kernel32.CreateToolhelp32Snapshot(2, 0);
var info = GM.CreateVariable(304); var info = GM.CreateVariable(304);
info.toBuffer().writeUInt32LE(304, 0); info.toBuffer().writeUInt32LE(304, 0);
var nextProcess = this._kernel32.Process32First(h, info); var nextProcess = this._kernel32.Process32First(h, info);
while (nextProcess.Val) while (nextProcess.Val) {
{ retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), cmd: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String });
retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), command: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String });
nextProcess = this._kernel32.Process32Next(h, info); nextProcess = this._kernel32.Process32Next(h, info);
} }
if (callback) { callback.apply(this, [retVal]); } if (callback) { callback.apply(this, [retVal]); }
@ -51,32 +58,21 @@ function processManager()
p.callback = callback; p.callback = callback;
p.args = []; p.args = [];
for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); } for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); }
p.on('exit', function onGetProcesses() p.on('exit', function onGetProcesses() {
{ delete this.Parent._psp[this.pid];
delete this.Parent._psp[this.pid]; var retVal = [], lines = this.ps.split('\x0D\x0A'), key = {}, keyi = 0;
var retVal = []; for (var i in lines) {
var lines = this.ps.split('\x0D\x0A');
var key = {};
var keyi = 0;
for (var i in lines)
{
var tokens = lines[i].split(' '); var tokens = lines[i].split(' ');
var tokenList = []; var tokenList = [];
for(var x in tokens) for (var x in tokens) {
{
if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; } if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; }
if (i > 0 && tokens[x]) { tokenList.push(tokens[x]);} if (i > 0 && tokens[x]) { tokenList.push(tokens[x]); }
} }
if(i>0) if ((i > 0) && (tokenList[key.PID])) {
{ retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], cmd: tokenList[key.COMMAND] });
if (tokenList[key.PID])
{
retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], command: tokenList[key.COMMAND] });
}
} }
} }
if (this.callback) if (this.callback) {
{
this.args.unshift(retVal); this.args.unshift(retVal);
this.callback.apply(this.parent, this.args); this.callback.apply(this.parent, this.args);
} }
@ -85,25 +81,18 @@ function processManager()
break; break;
} }
}; };
this.getProcessInfo = function getProcessInfo(pid) this.getProcessInfo = function getProcessInfo(pid) {
{ switch (process.platform) {
switch(process.platform)
{
default: default:
throw ('getProcessInfo() not supported for ' + process.platform); throw ('getProcessInfo() not supported for ' + process.platform);
break;
case 'linux': case 'linux':
var status = require('fs').readFileSync('/proc/' + pid + '/status'); var status = require('fs').readFileSync('/proc/' + pid + '/status'), info = {}, lines = status.toString().split('\n');
var info = {}; for (var i in lines) {
var lines = status.toString().split('\n');
for(var i in lines)
{
var tokens = lines[i].split(':'); var tokens = lines[i].split(':');
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); } if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
info[tokens[0]] = tokens[1]; info[tokens[0]] = tokens[1];
} }
return (info); return (info);
break;
} }
}; };
} }

View File

@ -1,4 +1,18 @@
/*
Copyright 2018 Intel Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
function UserSessions() function UserSessions()
{ {
@ -87,6 +101,8 @@ function UserSessions()
} }
this._wts.WTSFreeMemory(pinfo.Deref()); this._wts.WTSFreeMemory(pinfo.Deref());
Object.defineProperty(retVal, 'connected', { value: showActiveOnly(retVal) });
return (retVal); return (retVal);
}; };
} }
@ -94,9 +110,58 @@ function UserSessions()
{ {
this.Current = function Current() this.Current = function Current()
{ {
return ({}); var retVal = {};
var emitterUtils = require('events').inherits(retVal);
emitterUtils.createEvent('logon');
retVal._child = require('child_process').execFile('/usr/bin/last', ['last', '-f', '/var/run/utmp']);
retVal._child.Parent = retVal;
retVal._child._txt = '';
retVal._child.on('exit', function (code)
{
var lines = this._txt.split('\n');
var sessions = [];
for(var i in lines)
{
if (lines[i])
{
console.log(getTokens(lines[i]));
var user = lines[i].substring(0, lines[i].indexOf(' '));
sessions.push(user);
}
}
sessions.pop();
console.log(sessions);
});
retVal._child.stdout.Parent = retVal._child;
retVal._child.stdout.on('data', function (chunk) { this.Parent._txt += chunk.toString(); });
return (retVal);
} }
} }
} }
function showActiveOnly(source)
{
var retVal = [];
for (var i in source)
{
if (source[i].State == 'Active' || source[i].State == 'Connected')
{
retVal.push(source[i]);
}
}
return (retVal);
}
function getTokens(str)
{
var columns = [];
var i;
columns.push(str.substring(0, (i=str.indexOf(' '))));
while (str[++i] == ' ');
columns.push(str.substring(i, str.substring(i).indexOf(' ') + i));
return (columns);
}
module.exports = new UserSessions(); module.exports = new UserSessions();

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.1.6-s", "version": "0.1.6-v",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",

View File

@ -385,6 +385,7 @@
<td style=padding-top:2px;padding-bottom:2px;background:#C0C0C0> <td style=padding-top:2px;padding-bottom:2px;background:#C0C0C0>
<div style=float:right;text-align:right> <div style=float:right;text-align:right>
<select id=termdisplays style=display:none onchange=deskSetDisplay(event) onclick=deskGetDisplayNumbers(event)></select>&nbsp; <select id=termdisplays style=display:none onchange=deskSetDisplay(event) onclick=deskGetDisplayNumbers(event)></select>&nbsp;
<input id=DeskToastButton type=button value=Toast title="Display a notification message on the remote computer" onkeypress="return false" onkeydown="return false" onclick="deviceToastFunction()">&nbsp;
<input id=DeskToolsButton type=button value=Tools title="Toggle tools view" onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()">&nbsp; <input id=DeskToolsButton type=button value=Tools title="Toggle tools view" onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()">&nbsp;
</div> </div>
<div> <div>
@ -2849,7 +2850,7 @@
// Show action button, only show if we have permissions 4, 8, 64 // Show action button, only show if we have permissions 4, 8, 64
if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; } if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; }
x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />'; x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="Display a text message of the remote device" onclick=deviceToastFunction() />'; } //if ((connectivity & 1) && (meshrights & 8) && (node.agent.id < 5)) { x += '<input type=button value=Toast title="Display a text message of the remote device" onclick=deviceToastFunction() />'; }
QH('p10html', x); QH('p10html', x);
// Show node last 7 days timeline // Show node last 7 days timeline
@ -3306,7 +3307,7 @@
QV('d7meshkvm', (mesh.mtype == 2) && ((deskState == false) || (desktop.contype == 1))); QV('d7meshkvm', (mesh.mtype == 2) && ((deskState == false) || (desktop.contype == 1)));
// Enable buttons // Enable buttons
var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable Terminal var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop
QE('connectbutton1', online); QE('connectbutton1', online);
var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
QE('connectbutton1h', hwonline); QE('connectbutton1h', hwonline);
@ -3314,6 +3315,8 @@
QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus)); QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus));
QE('DeskCAD', deskState == 3); QE('DeskCAD', deskState == 3);
QE('DeskToolsButton', online); QE('DeskToolsButton', online);
QV('DeskToastButton', (currentNode.agent) && (currentNode.agent.id < 5));
QE('DeskToastButton', online);
if (online == false) QV('DeskTools', false); if (online == false) QV('DeskTools', false);
} }