diff --git a/db.js b/db.js index ba3ae95a..71477ef3 100644 --- a/db.js +++ b/db.js @@ -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 diff --git a/meshuser.js b/meshuser.js index 7c0a9bac..dc5eec94 100644 --- a/meshuser.js +++ b/meshuser.js @@ -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) { diff --git a/views/default.handlebars b/views/default.handlebars index aaa25a18..e0ce4e73 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -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 += ''; } x += addHtmlValue("Type", ''); @@ -16197,11 +16198,13 @@ x += addHtmlValue("Device Group", ''); x += ''; + x += ''; x += '