Added manual device events, fixed MQTT publish filter.
Ylian Saint-Hilaire committed
Oct 16, 2019 at 14:46 UTC
66c715db1c892c854668e29eaba520db32b2ecf6
5 files changed
+44
-3
meshuser.js
+25
@@ -2456,6 +2456,31 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2456
2457
// Send a response if needed
2458
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'inviteAgent', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
2459
+ break;
2460
+ }
2461
+ case 'setDeviceEvent':
2462
+ {
2463
+ // Argument validation
2464
+ if (common.validateString(command.msg, 1, 4096) == false) break; // Check event
2465
+ if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
2466
+ var splitid = command.nodeid.split('/');
2467
+ if ((splitid.length != 3) || (splitid[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
2468
+ var idtype = splitid[0];
2469
+ if ((idtype != 'node')) return;
2470
+
2471
+ // Check if this user has rights on this id to set notes
2472
+ db.Get(command.nodeid, function (err, nodes) {
2473
+ if ((nodes == null) || (nodes.length == 1)) {
2474
+ meshlinks = user.links[nodes[0].meshid];
2475
+ if ((meshlinks) && (meshlinks.rights) && (meshlinks.rights != 0)) {
2476
+ // Add an event for this device
2477
+ var targets = ['*', 'server-users', user._id, nodes[0].meshid];
2478
+ var event = { etype: 'node', userid: user._id, username: user.name, nodeid: nodes[0]._id, action: 'manual', msg: decodeURIComponent(command.msg), domain: domain.id };
2479
+ parent.parent.DispatchEvent(targets, obj, event);
2480
+ }
2481
+ }
2482
+ });
2483
+
2484
break;
2485
}
2486
case 'setNotes':
mqttbroker.js
+2
-2
@@ -126,8 +126,8 @@ module.exports.CreateMQTTBroker = function (parent, db, args) {
126
if (clients == null) return;
127
if (typeof message == 'string') { message = new Buffer(message); }
128
for (var i in clients) {
129
- // if (clients[i].subscriptions[topic] != null) { } // Add this if we only want to send subscribed topics.
130
- clients[i].publish({ cmd: 'publish', qos: 0, topic: topic, payload: message, retain: false });
129
+ // Only publish to client that subscribe to the topic
130
+ if (clients[i].subscriptions[topic] != null) { clients[i].publish({ cmd: 'publish', qos: 0, topic: topic, payload: message, retain: false }); }
131
}
132
}
133
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.4.2-r",
3
+ "version": "0.4.2-t",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default-min.handlebars
+8
@@ -10356,6 +10356,7 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
10356
// Show action button, only show if we have permissions 4, 8, 64
10357
if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; }
10358
x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
10359
+ x += '<input type=button value="Log Event" title="Write an event for this device" onclick=writeDeviceEvent("' + encodeURIComponent(node._id) + '") />';
10360
//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() />'; }
10361
QH('p10html', x);
10362
@@ -10479,6 +10480,13 @@ var QRCode;!function(){function a(a){this.mode=c.MODE_8BIT_BYTE,this.data=a,this
10480
go(panel);
10481
}
10482
10483
+ function writeDeviceEvent(nodeid) {
10484
+ if (xxdialogMode) return;
10485
+ setDialogMode(2, "Add Device Event", 3, writeDeviceEventEx, '<textarea id=d2devEvent style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>This will add an entry to this device\'s event log.<span>', nodeid);
10486
+ }
10487
+
10488
+ function writeDeviceEventEx(buttons, tag) { meshserver.send({ action: 'setDeviceEvent', nodeid: decodeURIComponent(tag), msg: encodeURIComponent(Q('d2devEvent').value) }); }
10489
+
10490
function showNotes(readonly, noteid) {
10491
if (xxdialogMode) return;
10492
setDialogMode(2, "Notes", 2, showNotesEx, '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>Device group notes can be viewed and changed by other device group administrators.<span>', noteid);
views/default.handlebars
+8
@@ -4327,6 +4327,7 @@
4327
// Show action button, only show if we have permissions 4, 8, 64
4328
if ((meshrights & 76) != 0) { x += '<input type=button value=Actions title="Perform power actions on the device" onclick=deviceActionFunction() />'; }
4329
x += '<input type=button value=Notes title="View notes about this device" onclick=showNotes(' + ((meshrights & 128) == 0) + ',"' + encodeURIComponent(node._id) + '") />';
4330
+ x += '<input type=button value="Log Event" title="Write an event for this device" onclick=writeDeviceEvent("' + encodeURIComponent(node._id) + '") />';
4331
//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() />'; }
4332
QH('p10html', x);
4333
@@ -4450,6 +4451,13 @@
4451
go(panel);
4452
}
4453
4454
+ function writeDeviceEvent(nodeid) {
4455
+ if (xxdialogMode) return;
4456
+ setDialogMode(2, "Add Device Event", 3, writeDeviceEventEx, '<textarea id=d2devEvent style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>This will add an entry to this device\'s event log.<span>', nodeid);
4457
+ }
4458
+
4459
+ function writeDeviceEventEx(buttons, tag) { meshserver.send({ action: 'setDeviceEvent', nodeid: decodeURIComponent(tag), msg: encodeURIComponent(Q('d2devEvent').value) }); }
4460
+
4461
function showNotes(readonly, noteid) {
4462
if (xxdialogMode) return;
4463
setDialogMode(2, "Notes", 2, showNotesEx, '<textarea id=d2devNotes ro=' + readonly + ' noteid=' + noteid + ' readonly style=background-color:#fcf3cf;width:100%;height:200px;resize:none;overflow-y:scroll></textarea><span style=font-size:10px>Device group notes can be viewed and changed by other device group administrators.<span>', noteid);