Added database records report to My Events / Reports tab.
Ylian Saint-Hilaire committed
Aug 12, 2022 at 15:53 UTC
92e3d2e528cc47fd3bcf1aadad259a5b7e7ddce8
3 files changed
+46
-5
db.js
+4
-4
@@ -1505,10 +1505,10 @@ module.exports.CreateDB = function (parent, func) {
1505
// Get database information (TODO: Complete this)
1506
obj.getDbStats = function (func) {
1507
obj.stats = { c: 4 };
1508
- sqlDbExec('SELECT COUNT(id) FROM main', null, function (err, response) { obj.stats.meshcentral = response['COUNT(id)']; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1509
- sqlDbExec('SELECT COUNT(time) FROM serverstats', null, function (err, response) { obj.stats.serverstats = response['COUNT(time)']; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1510
- sqlDbExec('SELECT COUNT(id) FROM power', null, function (err, response) { obj.stats.power = response['COUNT(id)']; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1511
- sqlDbExec('SELECT COUNT(id) FROM smbios', null, function (err, response) { obj.stats.smbios = response['COUNT(id)']; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1508
+ sqlDbExec('SELECT COUNT(id) FROM main', null, function (err, response) { obj.stats.meshcentral = Number(response['COUNT(id)']); if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1509
+ sqlDbExec('SELECT COUNT(time) FROM serverstats', null, function (err, response) { obj.stats.serverstats = Number(response['COUNT(time)']); if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1510
+ sqlDbExec('SELECT COUNT(id) FROM power', null, function (err, response) { obj.stats.power = Number(response['COUNT(id)']); if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1511
+ sqlDbExec('SELECT COUNT(id) FROM smbios', null, function (err, response) { obj.stats.smbios = Number(response['COUNT(id)']); if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1512
}
1513
1514
// Plugin operations
meshuser.js
+14
-1
@@ -6203,7 +6203,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6203
}
6204
6205
function serverCommandReport(command) {
6206
- if (common.validateInt(command.type, 1, 3) == false) return; // Validate type
6206
+ if (common.validateInt(command.type, 1, 4) == false) return; // Validate type
6207
if (common.validateInt(command.groupBy, 1, 3) == false) return; // Validate groupBy: 1 = User, 2 = Device, 3 = Day
6208
if ((typeof command.start != 'number') || (typeof command.end != 'number') || (command.start >= command.end)) return; // Validate start and end time
6209
const manageAllDeviceGroups = ((user.siteadmin == 0xFFFFFFFF) && (parent.parent.config.settings.managealldevicegroups.indexOf(user._id) >= 0));
@@ -6223,6 +6223,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
6223
userLoginReport(command);
6224
break;
6225
}
6226
+ case 4: {
6227
+ databaseRecordsReport(command);
6228
+ break;
6229
+ }
6230
}
6231
}
6232
@@ -7352,6 +7356,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
7356
});
7357
}
7358
7359
+ function databaseRecordsReport(command) {
7360
+ if (user.siteadmin != 0xFFFFFFFF) return; // This report is only available to full administrators
7361
+ parent.parent.db.getDbStats(function (stats) {
7362
+ var data = { groups: { 0: { entries: [] } } };
7363
+ data.columns = [{ id: 'record', title: "Record", format: 'records' }, { id: 'recordcount', title: "Count", align: 'center', sumBy: true }];
7364
+ for (var i in stats) { if ((i != 'total') && (stats[i] > 0)) { data.groups[0].entries.push({ record: i, recordcount: stats[i] }); } }
7365
+ try { ws.send(JSON.stringify({ action: 'report', data: data })); } catch (ex) { }
7366
+ });
7367
+ }
7368
7369
// Return detailed information about an array of nodeid's
7370
function getDeviceDetailedInfo(nodeids, type, func) {
views/default.handlebars
+28
@@ -16173,6 +16173,7 @@
16173
var y = '', x = '', settings = JSON.parse(getstore('_ReportSettings', '{}'));
16174
16175
var options = { 1 : "Remote Sessions", 2 : "User Traffic Usage", 3 : "User Logins" }
16176
+ if (userinfo.siteadmin == 0xFFFFFFFF) { options[4] = "Database Records"; }
16177
for (var i in options) { y += '<option value=' + i + ((settings.type == i)?' selected':'') + '>' + options[i] + '</option>'; }
16178
x += addHtmlValue("Type", '<select id=d2reportType style=float:right;width:250px onchange=generateReportDialogValidate()>' + y + '</select>');
16179
@@ -16197,11 +16198,13 @@
16198
x += addHtmlValue("Device Group", '<select onchange=generateReportDialogValidate() id=d2groupId style=float:right;width:250px>' + y + '</select>');
16199
x += '</div>';
16200
16201
+ x += '<div id=d2timeBackDiv style=display:none>';
16202
y = '';
16203
if (settings.timeRange == null) { settings.timeRange = 1; }
16204
var options = { 1 : "Last Day", 7: "Last 7 days", 30: "Last 30 days", 0: "Time range" }
16205
for (var i in options) { y += '<option value=' + i + ((settings.timeRange == i)?' selected':'') + '>' + options[i] + '</option>'; }
16206
x += addHtmlValue("Time", '<select id=d2timeRange style=float:right;width:250px onchange=generateReportDialogValidate()>' + y + '</select>');
16207
+ x += '</div>';
16208
16209
x += '<div id=d2timeRangeDiv style=display:none>';
16210
x += addHtmlValue("Time Range", '<input id=d2timeRangeSelector style=float:right;width:250px class=flatpickr type="text" placeholder="' + "Select Date & Time..." + '" data-id="altinput">');
@@ -16222,6 +16225,7 @@
16225
16226
function generateReportDialogValidate() {
16227
QV('d2timeRangeDiv', Q('d2timeRange').value == 0);
16228
+ QV('d2timeBackDiv', Q('d2reportType').value != 4);
16229
QV('d2GroupByDiv', Q('d2reportType').value == 1);
16230
QV('d2GroupByDiv2', Q('d2reportType').value == 3);
16231
QV('d2DeviceGroupDiv', Q('d2reportType').value == 1);
@@ -16422,6 +16426,29 @@
16426
if (v == 'ipaddr') { return "IP Address"; }
16427
if (v == 'sso') { return "Single Sign-on"; }
16428
}
16429
+ if (f == 'records') {
16430
+ var c = {
16431
+ 'node': "Device record",
16432
+ 'mesh': "Device group record",
16433
+ 'user': "User records",
16434
+ 'sysinfo': "Device information records",
16435
+ 'iploc': "IP location information records",
16436
+ 'note': "Text notes records",
16437
+ 'ifinfo': "Network interface information records",
16438
+ 'cfile': "Configuration file records",
16439
+ 'lastconnect': "Last connection time records",
16440
+ 'power': "Device power transition records",
16441
+ 'events': "Event records",
16442
+ 'serverstats': "Server statistics records",
16443
+ 'ugrp': "User group records",
16444
+ 'deviceshare': "Device sharing records",
16445
+ 'logintoken': "Account login token records",
16446
+ 'smbios': "Device SMBIOS record",
16447
+ 'pmt': "Device Push Notification Record",
16448
+ 'meshcentral': "Device, users, groups and other records"
16449
+ }
16450
+ return (c[v] != null)? c[v] : v;
16451
+ }
16452
return EscapeHtml(v);
16453
}
16454
@@ -16459,6 +16486,7 @@
16486
if (v == 109) return "Locked account";
16487
if (v == 110) return "Invalid login attempt";
16488
}
16489
+ if (f == 'records') { return renderReportFormat(v, f); }
16490
return '' + v;
16491
}
16492