Removed SMBIOS collection when using NeDB.

Ylian Saint-Hilaire committed Sep 8, 2020 at 11:58 UTC 672235e0a3240f995bb58317c39e5dc0621e1122
3 files changed +12 -11
db.js
+10 -8
@@ -724,8 +724,9 @@ module.exports.CreateDB = function (parent, func) {
724 obj.powerfile.ensureIndex({ fieldName: 'time', expireAfterSeconds: expirePowerEventsSeconds });
725 obj.powerfile.remove({ time: { '$lt': new Date(Date.now() - (expirePowerEventsSeconds * 1000)) } }, { multi: true }); // Force delete older events
726
727 - // Setup the SMBIOS collection
728 - obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true, corruptAlertThreshold: 1 });
727 + // Setup the SMBIOS collection, for NeDB we don't setup SMBIOS since NeDB will corrupt the database. Remove any existing ones.
728 + //obj.smbiosfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-smbios.db'), autoload: true, corruptAlertThreshold: 1 });
729 + parent.fs.unlink(parent.getConfigFilePath('meshcentral-smbios.db'), function () { });
730
731 // Setup the server stats collection and setup indexes
732 obj.serverstatsfile = new Datastore({ filename: parent.getConfigFilePath('meshcentral-stats.db'), autoload: true, corruptAlertThreshold: 1 });
@@ -1214,10 +1215,12 @@ module.exports.CreateDB = function (parent, func) {
1215 obj.removeAllPowerEventsForNode = function (nodeid) { obj.powerfile.remove({ nodeid: nodeid }, { multi: true }); };
1216
1217 // Database actions on the SMBIOS collection
1217 - obj.GetAllSMBIOS = function (func) { obj.smbiosfile.find({}, func); };
1218 - obj.SetSMBIOS = function (smbios, func) { obj.smbiosfile.update({ _id: smbios._id }, smbios, { upsert: true }, func); };
1219 - obj.RemoveSMBIOS = function (id) { obj.smbiosfile.remove({ _id: id }); };
1220 - obj.GetSMBIOS = function (id, func) { obj.smbiosfile.find({ _id: id }, func); };
1218 + if (obj.smbiosfile != null) {
1219 + obj.GetAllSMBIOS = function (func) { obj.smbiosfile.find({}, func); };
1220 + obj.SetSMBIOS = function (smbios, func) { obj.smbiosfile.update({ _id: smbios._id }, smbios, { upsert: true }, func); };
1221 + obj.RemoveSMBIOS = function (id) { obj.smbiosfile.remove({ _id: id }); };
1222 + obj.GetSMBIOS = function (id, func) { obj.smbiosfile.find({ _id: id }, func); };
1223 + }
1224
1225 // Database actions on the Server Stats collection
1226 obj.SetServerStats = function (data, func) { obj.serverstatsfile.insert(data, func); };
@@ -1248,12 +1251,11 @@ module.exports.CreateDB = function (parent, func) {
1251
1252 // Get database information
1253 obj.getDbStats = function (func) {
1251 - obj.stats = { c: 6 };
1254 + obj.stats = { c: 5 };
1255 obj.getStats(function (r) { obj.stats.recordTypes = r; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } })
1256 obj.file.count({}, function (err, count) { obj.stats.meshcentral = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1257 obj.eventsfile.count({}, function (err, count) { obj.stats.events = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1258 obj.powerfile.count({}, function (err, count) { obj.stats.power = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1256 - obj.smbiosfile.count({}, function (err, count) { obj.stats.smbios = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1259 obj.serverstatsfile.count({}, function (err, count) { obj.stats.serverstats = { count: count }; if (--obj.stats.c == 0) { delete obj.stats.c; func(obj.stats); } });
1260 }
1261
meshagent.js
+2 -1
@@ -1164,7 +1164,8 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1164 }
1165 case 'smbios':
1166 {
1167 - // SMBIOS information should never be saved when NeDB is in use.
1167 + // SMBIOS information must never be saved when NeDB is in use. NeDB will currupt that database.
1168 + if (db.SetSMBIOS == null) break;
1169
1170 // See if we need to save SMBIOS information
1171 if (domain.smbios === true) {
webserver.js
-2
@@ -2781,11 +2781,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
2781 try { res.sendFile(obj.path.resolve(__dirname, path)); } catch (e) { res.sendStatus(404); }
2782 } else {
2783 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));
2784 - //render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), message: "<a href='" + req.path + "?download=1'>" + filename + "</a>, " + stat.size + " byte" + ((stat.size < 2) ? '' : 's') + "." }, req, domain));
2784 }
2785 } else {
2786 render(req, res, getRenderPage((domain.sitestyle == 2) ? 'download2' : 'download', req, domain), getRenderArgs({ rootCertLink: getRootCertLink(), messageid: 2 }, req, domain));
2788 - //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));
2787 }
2788 }
2789