From 672235e0a3240f995bb58317c39e5dc0621e1122 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 8 Sep 2020 11:58:23 -0700 Subject: [PATCH] Removed SMBIOS collection when using NeDB. --- db.js | 18 ++++++++++-------- meshagent.js | 3 ++- webserver.js | 2 -- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/db.js b/db.js index ae71de12..5feda838 100644 --- a/db.js +++ b/db.js @@ -724,8 +724,9 @@ module.exports.CreateDB = function (parent, func) { obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds }); obj.powerfile.remove({ time: { '$lt': new Date(Date.now() - (expirePowerEventsSeconds * 1000)) } }, { multi: true }); // Force delete older events - // Setup the SMBIOS collection - obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true, corruptAlertThreshold: 1 }); + // Setup the SMBIOS collection, for NeDB we don't setup SMBIOS since NeDB will corrupt the database. Remove any existing ones. + //obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true, corruptAlertThreshold: 1 }); + parent.fs.unlink(parent.getConfigFilePath('meshcentral-smbios.db'), function () { }); // Setup the server stats collection and setup indexes obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true, corruptAlertThreshold: 1 }); @@ -1214,10 +1215,12 @@ module.exports.CreateDB = function (parent, func) { obj.removeAllPowerEventsForNode = function (nodeid) { obj.powerfile.remove({ nodeid: nodeid }, { multi: true }); }; // Database actions on the SMBIOS collection - obj.GetAllSMBIOS = function (func) { obj.smbiosfile.find({}, func); }; - obj.SetSMBIOS = function (smbios, func) { obj.smbiosfile.update({ _id: smbios._id }, smbios, { upsert: true }, func); }; - obj.RemoveSMBIOS = function (id) { obj.smbiosfile.remove({ _id: id }); }; - obj.GetSMBIOS = function (id, func) { obj.smbiosfile.find({ _id: id }, func); }; + if (obj.smbiosfile != null) { + obj.GetAllSMBIOS = function (func) { obj.smbiosfile.find({}, func); }; + obj.SetSMBIOS = function (smbios, func) { obj.smbiosfile.update({ _id: smbios._id }, smbios, { upsert: true }, func); }; + obj.RemoveSMBIOS = function (id) { obj.smbiosfile.remove({ _id: id }); }; + obj.GetSMBIOS = function (id, func) { obj.smbiosfile.find({ _id: id }, func); }; + } // Database actions on the Server Stats collection obj.SetServerStats = function (data, func) { obj.serverstatsfile.insert(data, func); }; @@ -1248,12 +1251,11 @@ module.exports.CreateDB = function (parent, func) { // Get database information obj.getDbStats = function (func) { - obj.stats = { c: 6 }; + obj.stats = { c: 5 }; obj.getStats(function (r) { obj.stats.recordTypes = r; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }) obj.file.count({}, function (err, count) { obj.stats.meshcentral = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }); obj.eventsfile.count({}, function (err, count) { obj.stats.events = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }); obj.powerfile.count({}, function (err, count) { obj.stats.power = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }); - obj.smbiosfile.count({}, function (err, count) { obj.stats.smbios = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }); obj.serverstatsfile.count({}, function (err, count) { obj.stats.serverstats = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } }); } diff --git a/meshagent.js b/meshagent.js index 8d38c962..f39a12c0 100644 --- a/meshagent.js +++ b/meshagent.js @@ -1164,7 +1164,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { } case 'smbios': { - // SMBIOS information should never be saved when NeDB is in use. + // SMBIOS information must never be saved when NeDB is in use. NeDB will currupt that database. + if (db.SetSMBIOS == null) break; // See if we need to save SMBIOS information if (domain.smbios === true) { diff --git a/webserver.js b/webserver.js index ec4d7382..6967ca28 100644 --- a/webserver.js +++ b/webserver.js @@ -2781,11 +2781,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { try { res.sendFile(obj.path.resolve(__dirname, path)); } catch (e) { res.sendStatus(404); } } else { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), messageid: 1, fileurl: req.path + '?download=1', filename: filename, filesize: stat.size }, req, domain)); - //render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), message: "" + filename + ", " + stat.size + " byte" + ((stat.size < 2) ? '' : 's') + "." }, req, domain)); } } else { render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), messageid: 2 }, req, domain)); - //render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), message: "Invalid file link, please check the URL again." }, req, domain)); } }