Added database records report to My Events / Reports tab.

This commit is contained in:
Ylian Saint-Hilaire 2022-08-12 15:53:35 -07:00
parent 630cfdda1e
commit 92e3d2e528
3 changed files with 46 additions and 5 deletions

8
db.js
View File

@ -1505,10 +1505,10 @@ module.exports.CreateDB = function (parent, func) {
// Get database information (TODO: Complete this)
obj.getDbStats = function (func) {
obj.stats = { c: 4 };
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); } });
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); } });
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); } });
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); } });
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); } });
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); } });
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); } });
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); } });
}
// Plugin operations

View File

@ -6203,7 +6203,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
function serverCommandReport(command) {
if (common.validateInt(command.type, 1, 3) == false) return; // Validate type
if (common.validateInt(command.type, 1, 4) == false) return; // Validate type
if (common.validateInt(command.groupBy, 1, 3) == false) return; // Validate groupBy: 1 = User, 2 = Device, 3 = Day
if ((typeof command.start != 'number') || (typeof command.end != 'number') || (command.start >= command.end)) return; // Validate start and end time
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
userLoginReport(command);
break;
}
case 4: {
databaseRecordsReport(command);
break;
}
}
}
@ -7352,6 +7356,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
});
}
function databaseRecordsReport(command) {
if (user.siteadmin != 0xFFFFFFFF) return; // This report is only available to full administrators
parent.parent.db.getDbStats(function (stats) {
var data = { groups: { 0: { entries: [] } } };
data.columns = [{ id: 'record', title: "Record", format: 'records' }, { id: 'recordcount', title: "Count", align: 'center', sumBy: true }];
for (var i in stats) { if ((i != 'total') && (stats[i] > 0)) { data.groups[0].entries.push({ record: i, recordcount: stats[i] }); } }
try { ws.send(JSON.stringify({ action: 'report', data: data })); } catch (ex) { }
});
}
// Return detailed information about an array of nodeid's
function getDeviceDetailedInfo(nodeids, type, func) {

View File

@ -16173,6 +16173,7 @@
var y = '', x = '', settings = JSON.parse(getstore('_ReportSettings', '{}'));
var options = { 1 : "Remote Sessions", 2 : "User Traffic Usage", 3 : "User Logins" }
if (userinfo.siteadmin == 0xFFFFFFFF) { options[4] = "Database Records"; }
for (var i in options) { y += '<option value=' + i + ((settings.type == i)?' selected':'') + '>' + options[i] + '</option>'; }
x += addHtmlValue("Type", '<select id=d2reportType style=float:right;width:250px onchange=generateReportDialogValidate()>' + y + '</select>');
@ -16197,11 +16198,13 @@
x += addHtmlValue("Device Group", '<select onchange=generateReportDialogValidate() id=d2groupId style=float:right;width:250px>' + y + '</select>');
x += '</div>';
x += '<div id=d2timeBackDiv style=display:none>';
y = '';
if (settings.timeRange == null) { settings.timeRange = 1; }
var options = { 1 : "Last Day", 7: "Last 7 days", 30: "Last 30 days", 0: "Time range" }
for (var i in options) { y += '<option value=' + i + ((settings.timeRange == i)?' selected':'') + '>' + options[i] + '</option>'; }
x += addHtmlValue("Time", '<select id=d2timeRange style=float:right;width:250px onchange=generateReportDialogValidate()>' + y + '</select>');
x += '</div>';
x += '<div id=d2timeRangeDiv style=display:none>';
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 @@
function generateReportDialogValidate() {
QV('d2timeRangeDiv', Q('d2timeRange').value == 0);
QV('d2timeBackDiv', Q('d2reportType').value != 4);
QV('d2GroupByDiv', Q('d2reportType').value == 1);
QV('d2GroupByDiv2', Q('d2reportType').value == 3);
QV('d2DeviceGroupDiv', Q('d2reportType').value == 1);
@ -16422,6 +16426,29 @@
if (v == 'ipaddr') { return "IP Address"; }
if (v == 'sso') { return "Single Sign-on"; }
}
if (f == 'records') {
var c = {
'node': "Device record",
'mesh': "Device group record",
'user': "User records",
'sysinfo': "Device information records",
'iploc': "IP location information records",
'note': "Text notes records",
'ifinfo': "Network interface information records",
'cfile': "Configuration file records",
'lastconnect': "Last connection time records",
'power': "Device power transition records",
'events': "Event records",
'serverstats': "Server statistics records",
'ugrp': "User group records",
'deviceshare': "Device sharing records",
'logintoken': "Account login token records",
'smbios': "Device SMBIOS record",
'pmt': "Device Push Notification Record",
'meshcentral': "Device, users, groups and other records"
}
return (c[v] != null)? c[v] : v;
}
return EscapeHtml(v);
}
@ -16459,6 +16486,7 @@
if (v == 109) return "Locked account";
if (v == 110) return "Invalid login attempt";
}
if (f == 'records') { return renderReportFormat(v, f); }
return '' + v;
}