Added device group name to reports. #3130
Ylian Saint-Hilaire committed
Sep 14, 2021 at 15:19 UTC
453eb369ee879c4b37c1143faa14eb8ea02ef53a
2 files changed
+48
-11
meshuser.js
+24
-9
@@ -5485,12 +5485,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5485
// Columns
5486
if (command.groupBy == 1) {
5487
data.groupFormat = 'user';
5488
- data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
5488
+ data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'meshid', title: "devgroup", format: 'mesh' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
5489
} else if (command.groupBy == 2) {
5490
- data.groupFormat = 'node';
5490
+ data.groupFormat = 'nodemesh';
5491
data.columns = [{ id: 'time', title: "time", format: 'datetime' }, { id: 'userid', title: "user", format: 'user' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
5492
} else if (command.groupBy == 3) {
5493
- data.columns = [{ id: 'time', title: "time", format: 'time' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'userid', title: "user", format: 'user' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
5493
+ data.columns = [{ id: 'time', title: "time", format: 'time' }, { id: 'nodeid', title: "device", format: 'node' }, { id: 'meshid', title: "devgroup", format: 'mesh' }, { id: 'guestname', title: "guest", align: 'center' }, { id: 'userid', title: "user", format: 'user' }, { id: 'protocol', title: "session", format: 'protocol', align: 'center' }, { id: 'length', title: "length", format: 'seconds', align: 'center', sumBy: 'protocol' } ];
5494
}
5495
5496
// Add traffic columns
@@ -5512,6 +5512,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5512
if (command.groupBy != 2) { entry.nodeid = docs[i].nodeid; }
5513
entry.protocol = docs[i].protocol;
5514
5515
+ // Device Group
5516
+ if (docs[i].ids != null) { for (var j in docs[i].ids) { if (docs[i].ids[j].startsWith('mesh/')) { entry.meshid = docs[i].ids[j]; } } }
5517
+
5518
// Add traffic data
5519
if (command.showTraffic) { entry.bytesin = docs[i].bytesin; entry.bytesout = docs[i].bytesout; }
5520
@@ -5522,13 +5525,19 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5525
if (((docs[i].msgid >= 10) && (docs[i].msgid <= 12)) && (docs[i].msgArgs != null) && (typeof docs[i].msgArgs == 'object') && (typeof docs[i].msgArgs[3] == 'number')) { entry.length = docs[i].msgArgs[3]; }
5526
else if ((docs[i].msgid >= 122) && (docs[i].msgid <= 126) && (docs[i].msgArgs != null) && (typeof docs[i].msgArgs == 'object') && (typeof docs[i].msgArgs[0] == 'number')) { entry.length = docs[i].msgArgs[0]; }
5527
5525
- if (command.groupBy == 1) { // Add entry to per user group
5528
+ if (command.groupBy == 1) { // Add entry to per user
5529
if (data.groups[docs[i].userid] == null) { data.groups[docs[i].userid] = { entries: [] }; }
5530
data.groups[docs[i].userid].entries.push(entry);
5528
- } else if (command.groupBy == 2) { // Add entry to per device group
5529
- if (data.groups[docs[i].nodeid] == null) { data.groups[docs[i].nodeid] = { entries: [] }; }
5530
- data.groups[docs[i].nodeid].entries.push(entry);
5531
- } else if (command.groupBy == 3) { // Add entry to per day group
5531
+ } else if (command.groupBy == 2) { // Add entry to per mesh+device
5532
+ if (entry.meshid != null) {
5533
+ var k = docs[i].nodeid + '/' + entry.meshid;
5534
+ if (data.groups[k] == null) { data.groups[k] = { entries: [] }; }
5535
+ data.groups[k].entries.push(entry);
5536
+ } else {
5537
+ if (data.groups[docs[i].nodeid] == null) { data.groups[docs[i].nodeid] = { entries: [] }; }
5538
+ data.groups[docs[i].nodeid].entries.push(entry);
5539
+ }
5540
+ } else if (command.groupBy == 3) { // Add entry to per day
5541
var day;
5542
if ((typeof command.l == 'string') && (typeof command.tz == 'string')) {
5543
day = new Date(docs[i].time).toLocaleDateString(command.l, { timeZone: command.tz });
@@ -5542,7 +5551,13 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5551
}
5552
5553
// Remove guest column if not needed
5545
- if (guestNamePresent == false) { data.columns.splice(2, 1); }
5554
+ if (guestNamePresent == false) {
5555
+ if ((command.groupBy == 1) || (command.groupBy == 3)) {
5556
+ data.columns.splice(3, 1);
5557
+ } else if (command.groupBy == 2) {
5558
+ data.columns.splice(2, 1);
5559
+ }
5560
+ }
5561
5562
try { ws.send(JSON.stringify({ action: 'report', data: data })); } catch (ex) { }
5563
});
views/default.handlebars
+24
-2
@@ -15019,7 +15019,7 @@
15019
}
15020
15021
function renderReport(r) {
15022
- var colTranslation = { time: "Time", device: "Device", session: "Session", user: "User", guest: "Guest", length: "Length", bytesin: "Bytes In", bytesout: "Bytes Out" }
15022
+ var colTranslation = { time: "Time", device: "Device", session: "Session", user: "User", devgroup: "Device Group", guest: "Guest", length: "Length", bytesin: "Bytes In", bytesout: "Bytes Out" }
15023
var x = '<table style=width:100%>', firstItem;
15024
var sumByCol = null; // Indicate by what colum we sum by
15025
var sumByValues = []; // Indicate by what values we sum by
@@ -15142,7 +15142,25 @@
15142
}
15143
if (f == 'node') {
15144
var node = getNodeFromId(v);
15145
- if (node != null) { return '<div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name); } else { return '<i>' + "Unknown Device" + '</i>'; }
15145
+ if (node != null) { return '<div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name); } else { return '<i>' + "Unknown" + '</i>'; }
15146
+ }
15147
+ if (f == 'mesh') {
15148
+ var mesh = meshes[v];
15149
+ if (mesh != null) { return '<div onclick=\'gotoMesh("' + mesh._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px;cursor:pointer class="m99"></div>' + EscapeHtml(mesh.name); } else { return '<i>' + "Unknown" + '</i>'; }
15150
+ }
15151
+ if (f == 'nodemesh') {
15152
+ var nodeid = null, meshid = null;
15153
+ var s = v.split('/'), x = '<table><tr>';
15154
+ if (s.length >= 3) { nodeid = s[0] + '/' + s[1] + '/' + s[2]; }
15155
+ if (s.length >= 6) { meshid = s[3] + '/' + s[4] + '/' + s[5]; }
15156
+ if (meshid != null) {
15157
+ var mesh = meshes[meshid];
15158
+ if (mesh != null) { x += '<td><div onclick=\'gotoMesh("' + mesh._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px;cursor:pointer class="m99"></div>' + EscapeHtml(mesh.name) + ' </td>'; } else { return '<i>' + "Unknown" + '</i>'; }
15159
+ }
15160
+ var node = getNodeFromId(nodeid);
15161
+ if (node != null) { x += '<td><div onclick=\'gotoDevice("' + node._id + '",10);haltEvent(event);\' style=float:left;margin-right:4px class="j' + node.icon + '"></div>' + EscapeHtml(node.name) + '</td>'; } else { return '<i>' + "Unknown" + '</i>'; }
15162
+ x += '</tr></table>';
15163
+ return x;
15164
}
15165
if (f == 'user') {
15166
var user = null;
@@ -15171,6 +15189,10 @@
15189
var node = getNodeFromId(v);
15190
if (node != null) { return node.name; }
15191
}
15192
+ if (f == 'mesh') {
15193
+ var mesh = meshes[v];
15194
+ if (mesh != null) { return mesh.name }
15195
+ }
15196
if (f == 'user') {
15197
var user = null;
15198
if (v == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[v]; } }