Improved toast notifications
Ylian Saint-Hilaire committed
Apr 20, 2018 at 14:23 UTC
e8294491cb353eb6f87c0ec04d28b450f8b9e706
6 files changed
+109
-52
agents/meshcmd.js
+1
-1
@@ -343,7 +343,7 @@ function run(argv) {
343
if (mestate.ProvisioningState.stateStr == 'PRE') { str += ', pre-provisioning state'; }
344
else if (mestate.ProvisioningState.stateStr == 'IN') { str += ', in-provisioning state'; }
345
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; } }
346
- if (mestate.ehbc.EHBC == true) { str += ', EHBC enabled'; }
346
+ if ((mestate.ehbc) && (mestate.ehbc.EHBC == true)) { str += ', EHBC enabled'; }
347
str += '.';
348
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)); }
349
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)); }
agents/meshcore.js
+1
-1
@@ -852,7 +852,7 @@ function createMeshCore(agent) {
852
var response = null;
853
switch (cmd) {
854
case 'help': { // Displays available commands
855
- 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.';
855
+ 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.';
856
break;
857
}
858
case 'toast': {
agents/modules_meshcmd/process-manager.js
renamed
+35
-46
@@ -1,13 +1,25 @@
1
-// JavaScript source code
2
-var GM = require('_GenericMarshal');
1
+/*
2
+Copyright 2018 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+*/
16
+
17
+// JavaScript source code
18
+var GM = require('_GenericMarshal');
19
6
-function processManager()
7
-{
20
+function processManager() {
21
this._ObjectID = 'processManager';
9
- switch(process.platform)
10
- {
22
+ switch (process.platform) {
23
case 'win32':
24
this._kernel32 = GM.CreateNativeProxy('kernel32.dll');
25
this._kernel32.CreateMethod('GetLastError');
@@ -20,24 +32,19 @@ function processManager()
32
break;
33
default:
34
throw (process.platform + ' not supported');
23
- break;
35
}
25
- this.getProcesses = function getProcesses(callback)
26
- {
27
- switch(process.platform)
28
- {
36
+ this.getProcesses = function getProcesses(callback) {
37
+ switch (process.platform) {
38
default:
39
throw ('Enumerating processes on ' + process.platform + ' not supported');
31
- break;
40
case 'win32':
41
var retVal = [];
42
var h = this._kernel32.CreateToolhelp32Snapshot(2, 0);
43
var info = GM.CreateVariable(304);
44
info.toBuffer().writeUInt32LE(304, 0);
45
var nextProcess = this._kernel32.Process32First(h, info);
38
- while (nextProcess.Val)
39
- {
40
- retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), command: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String });
46
+ while (nextProcess.Val) {
47
+ retVal.push({ pid: info.Deref(8, 4).toBuffer().readUInt32LE(0), cmd: info.Deref(GM.PointerSize == 4 ? 36 : 44, 260).String });
48
nextProcess = this._kernel32.Process32Next(h, info);
49
}
50
if (callback) { callback.apply(this, [retVal]); }
@@ -51,32 +58,21 @@ function processManager()
58
p.callback = callback;
59
p.args = [];
60
for (var i = 1; i < arguments.length; ++i) { p.args.push(arguments[i]); }
54
- p.on('exit', function onGetProcesses()
55
- {
56
- delete this.Parent._psp[this.pid];
57
- var retVal = [];
58
- var lines = this.ps.split('\x0D\x0A');
59
- var key = {};
60
- var keyi = 0;
61
- for (var i in lines)
62
- {
61
+ p.on('exit', function onGetProcesses() {
62
+ delete this.Parent._psp[this.pid];
63
+ var retVal = [], lines = this.ps.split('\x0D\x0A'), key = {}, keyi = 0;
64
+ for (var i in lines) {
65
var tokens = lines[i].split(' ');
66
var tokenList = [];
65
- for(var x in tokens)
66
- {
67
+ for (var x in tokens) {
68
if (i == 0 && tokens[x]) { key[tokens[x]] = keyi++; }
68
- if (i > 0 && tokens[x]) { tokenList.push(tokens[x]);}
69
+ if (i > 0 && tokens[x]) { tokenList.push(tokens[x]); }
70
}
70
- if(i>0)
71
- {
72
- if (tokenList[key.PID])
73
- {
74
- retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], command: tokenList[key.COMMAND] });
75
- }
71
+ if ((i > 0) && (tokenList[key.PID])) {
72
+ retVal.push({ pid: tokenList[key.PID], user: tokenList[key.USER], cmd: tokenList[key.COMMAND] });
73
}
74
}
78
- if (this.callback)
79
- {
75
+ if (this.callback) {
76
this.args.unshift(retVal);
77
this.callback.apply(this.parent, this.args);
78
}
@@ -85,25 +81,18 @@ function processManager()
81
break;
82
}
83
};
88
- this.getProcessInfo = function getProcessInfo(pid)
89
- {
90
- switch(process.platform)
91
- {
84
+ this.getProcessInfo = function getProcessInfo(pid) {
85
+ switch (process.platform) {
86
default:
87
throw ('getProcessInfo() not supported for ' + process.platform);
94
- break;
88
case 'linux':
96
- var status = require('fs').readFileSync('/proc/' + pid + '/status');
97
- var info = {};
98
- var lines = status.toString().split('\n');
99
- for(var i in lines)
100
- {
89
+ var status = require('fs').readFileSync('/proc/' + pid + '/status'), info = {}, lines = status.toString().split('\n');
90
+ for (var i in lines) {
91
var tokens = lines[i].split(':');
92
if (tokens.length > 1) { tokens[1] = tokens[1].trim(); }
93
info[tokens[0]] = tokens[1];
94
}
95
return (info);
106
- break;
96
}
97
};
98
}
agents/modules_meshcmd/user-sessions.js
renamed
+66
-1
@@ -1,4 +1,18 @@
1
+/*
2
+Copyright 2018 Intel Corporation
3
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+*/
16
17
function UserSessions()
18
{
@@ -87,6 +101,8 @@ function UserSessions()
101
}
102
103
this._wts.WTSFreeMemory(pinfo.Deref());
104
+
105
+ Object.defineProperty(retVal, 'connected', { value: showActiveOnly(retVal) });
106
return (retVal);
107
};
108
}
@@ -94,9 +110,58 @@ function UserSessions()
110
{
111
this.Current = function Current()
112
{
97
- return ({});
113
+ var retVal = {};
114
+ var emitterUtils = require('events').inherits(retVal);
115
+ emitterUtils.createEvent('logon');
116
+
117
+ retVal._child = require('child_process').execFile('/usr/bin/last', ['last', '-f', '/var/run/utmp']);
118
+ retVal._child.Parent = retVal;
119
+ retVal._child._txt = '';
120
+ retVal._child.on('exit', function (code)
121
+ {
122
+ var lines = this._txt.split('\n');
123
+ var sessions = [];
124
+ for(var i in lines)
125
+ {
126
+ if (lines[i])
127
+ {
128
+ console.log(getTokens(lines[i]));
129
+ var user = lines[i].substring(0, lines[i].indexOf(' '));
130
+ sessions.push(user);
131
+ }
132
+ }
133
+ sessions.pop();
134
+ console.log(sessions);
135
+ });
136
+ retVal._child.stdout.Parent = retVal._child;
137
+ retVal._child.stdout.on('data', function (chunk) { this.Parent._txt += chunk.toString(); });
138
+
139
+ return (retVal);
140
+ }
141
+ }
142
+}
143
+function showActiveOnly(source)
144
+{
145
+ var retVal = [];
146
+ for (var i in source)
147
+ {
148
+ if (source[i].State == 'Active' || source[i].State == 'Connected')
149
+ {
150
+ retVal.push(source[i]);
151
}
152
}
153
+ return (retVal);
154
+}
155
+function getTokens(str)
156
+{
157
+ var columns = [];
158
+ var i;
159
+
160
+ columns.push(str.substring(0, (i=str.indexOf(' '))));
161
+ while (str[++i] == ' ');
162
+ columns.push(str.substring(i, str.substring(i).indexOf(' ') + i));
163
+
164
+ return (columns);
165
}
166
167
module.exports = new UserSessions();
\ No newline at end of file
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.1.6-s",
3
+ "version": "0.1.6-v",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default.handlebars
+5
-2
@@ -385,6 +385,7 @@
385
<td style=padding-top:2px;padding-bottom:2px;background:#C0C0C0>
386
<div style=float:right;text-align:right>
387
<select id=termdisplays style=display:none onchange=deskSetDisplay(event) onclick=deskGetDisplayNumbers(event)></select>
388
+ <input id=DeskToastButton type=button value=Toast title="Display a notification message on the remote computer" onkeypress="return false" onkeydown="return false" onclick="deviceToastFunction()">
389
<input id=DeskToolsButton type=button value=Tools title="Toggle tools view" onkeypress="return false" onkeydown="return false" onclick="toggleDeskTools()">
390
</div>
391
<div>
@@ -2849,7 +2850,7 @@
2850
// Show action button, only show if we have permissions 4, 8, 64
2851
if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; }
2852
x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
2852
- 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() />'; }
2853
+ //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() />'; }
2854
QH('p10html', x);
2855
2856
// Show node last 7 days timeline
@@ -3306,7 +3307,7 @@
3307
QV('d7meshkvm', (mesh.mtype == 2) && ((deskState == false) || (desktop.contype == 1)));
3308
3309
// Enable buttons
3309
- var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable Terminal
3310
+ var online = ((currentNode.conn & 1) != 0); // If Agent (1) connected, enable remote desktop
3311
QE('connectbutton1', online);
3312
var hwonline = ((currentNode.conn & 6) != 0); // If CIRA (2) or AMT (4) connected, enable hardware terminal
3313
QE('connectbutton1h', hwonline);
@@ -3314,6 +3315,8 @@
3315
QV('deskFocusBtn', (desktop != null) && (desktop.contype == 2) && (deskState != 0) && (desktopsettings.showfocus));
3316
QE('DeskCAD', deskState == 3);
3317
QE('DeskToolsButton', online);
3318
+ QV('DeskToastButton', (currentNode.agent) && (currentNode.agent.id < 5));
3319
+ QE('DeskToastButton', online);
3320
if (online == false) QV('DeskTools', false);
3321
}
3322