1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Probably fixed the MongoDB dot exception.

This commit is contained in:
Ylian Saint-Hilaire 2019-10-10 14:06:14 -07:00
parent 6b8619f542
commit a744a52bc7
5 changed files with 30 additions and 30 deletions

36
db.js
View file

@ -608,11 +608,11 @@ module.exports.CreateDB = function (parent, func) {
}
// Check the object names for a "."
function checkObjectNames(r) {
function checkObjectNames(r, tag) {
if (typeof r != 'object') return;
for (var i in r) {
if (i.indexOf('.') >= 0) { throw('BadDbName: ' + JSON.stringify(r)); }
checkObjectNames(r[i]);
if (i.indexOf('.') >= 0) { throw('BadDbName (' + tag + '): ' + JSON.stringify(r)); }
checkObjectNames(r[i], tag);
}
}
@ -620,7 +620,7 @@ module.exports.CreateDB = function (parent, func) {
if (obj.databaseType == 3) {
// Database actions on the main collection (MongoDB)
obj.Set = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x1'); // DEBUG CHECKING
obj.file.replaceOne({ _id: data._id }, performTypedRecordEncrypt(data), { upsert: true }, func);
};
obj.Get = function (id, func) {
@ -651,21 +651,21 @@ module.exports.CreateDB = function (parent, func) {
obj.RemoveAll = function (func) { obj.file.deleteMany({}, { multi: true }, func); };
obj.RemoveAllOfType = function (type, func) { obj.file.deleteMany({ type: type }, { multi: true }, func); };
obj.InsertMany = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x2'); // DEBUG CHECKING
obj.file.insertMany(data, func);
};
obj.RemoveMeshDocuments = function (id) { obj.file.deleteMany({ meshid: id }, { multi: true }); obj.file.deleteOne({ _id: 'nt' + id }); };
obj.MakeSiteAdmin = function (username, domain) {
obj.Get('user/' + domain + '/' + username, function (err, docs) {
if (docs.length == 1) {
checkObjectNames(docs[0]); // DEBUG CHECKING
checkObjectNames(docs[0], 'x3'); // DEBUG CHECKING
docs[0].siteadmin = 0xFFFFFFFF; obj.Set(docs[0]);
}
});
};
obj.DeleteDomain = function (domain, func) { obj.file.deleteMany({ domain: domain }, { multi: true }, func); };
obj.SetUser = function (user) {
checkObjectNames(user); // DEBUG CHECKING
checkObjectNames(user, 'x4'); // DEBUG CHECKING
var u = Clone(user);
if (u.subscriptions) { delete u.subscriptions; } obj.Set(u);
};
@ -681,7 +681,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the events collection
obj.GetAllEvents = function (func) { obj.eventsfile.find({}).toArray(func); };
obj.StoreEvent = function (event) {
checkObjectNames(event); // DEBUG CHECKING
checkObjectNames(event, 'x5'); // DEBUG CHECKING
obj.eventsfile.insertOne(event);
};
obj.GetEvents = function (ids, domain, func) { obj.eventsfile.find({ domain: domain, ids: { $in: ids } }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).toArray(func); };
@ -696,7 +696,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the power collection
obj.getAllPower = function (func) { obj.powerfile.find({}).toArray(func); };
obj.storePowerEvent = function (event, multiServer, func) {
checkObjectNames(event); // DEBUG CHECKING
checkObjectNames(event, 'x6'); // DEBUG CHECKING
if (multiServer != null) { event.server = multiServer.serverid; } obj.powerfile.insertOne(event, func);
};
obj.getPowerTimeline = function (nodeid, func) { obj.powerfile.find({ nodeid: { $in: ['*', nodeid] } }).project({ _id: 0, nodeid: 0, s: 0 }).sort({ time: 1 }).toArray(func); };
@ -705,7 +705,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the SMBIOS collection
obj.SetSMBIOS = function (smbios, func) {
checkObjectNames(smbios); // DEBUG CHECKING
checkObjectNames(smbios, 'x7'); // DEBUG CHECKING
obj.smbiosfile.updateOne({ _id: smbios._id }, { $set: smbios }, { upsert: true }, func);
};
obj.RemoveSMBIOS = function (id) { obj.smbiosfile.deleteOne({ _id: id }); };
@ -713,7 +713,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the Server Stats collection
obj.SetServerStats = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x8'); // DEBUG CHECKING
obj.serverstatsfile.insertOne(data, func);
};
obj.GetServerStats = function (hours, func) { var t = new Date(); t.setTime(t.getTime() - (60 * 60 * 1000 * hours)); obj.serverstatsfile.find({ time: { $gt: t } }, { _id: 0, cpu: 0 }).toArray(func); };
@ -743,7 +743,7 @@ module.exports.CreateDB = function (parent, func) {
} else {
// Database actions on the main collection (NeDB and MongoJS)
obj.Set = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x9'); // DEBUG CHECKING
var xdata = performTypedRecordEncrypt(data);
obj.file.update({ _id: xdata._id }, xdata, { upsert: true }, func);
};
@ -775,21 +775,21 @@ module.exports.CreateDB = function (parent, func) {
obj.RemoveAll = function (func) { obj.file.remove({}, { multi: true }, func); };
obj.RemoveAllOfType = function (type, func) { obj.file.remove({ type: type }, { multi: true }, func); };
obj.InsertMany = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x10'); // DEBUG CHECKING
obj.file.insert(data, func);
};
obj.RemoveMeshDocuments = function (id) { obj.file.remove({ meshid: id }, { multi: true }); obj.file.remove({ _id: 'nt' + id }); };
obj.MakeSiteAdmin = function (username, domain) {
obj.Get('user/' + domain + '/' + username, function (err, docs) {
if (docs.length == 1) {
checkObjectNames(docs[0]); // DEBUG CHECKING
checkObjectNames(docs[0], 'x11'); // DEBUG CHECKING
docs[0].siteadmin = 0xFFFFFFFF; obj.Set(docs[0]);
}
});
};
obj.DeleteDomain = function (domain, func) { obj.file.remove({ domain: domain }, { multi: true }, func); };
obj.SetUser = function (user) {
checkObjectNames(user); // DEBUG CHECKING
checkObjectNames(user, 'x12'); // DEBUG CHECKING
var u = Clone(user); if (u.subscriptions) { delete u.subscriptions; } obj.Set(u);
};
obj.dispose = function () { for (var x in obj) { if (obj[x].close) { obj[x].close(); } delete obj[x]; } };
@ -800,7 +800,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the events collection
obj.GetAllEvents = function (func) { obj.eventsfile.find({}, func); };
obj.StoreEvent = function (event) {
checkObjectNames(event); // DEBUG CHECKING
checkObjectNames(event, 'x13'); // DEBUG CHECKING
obj.eventsfile.insert(event);
};
obj.GetEvents = function (ids, domain, func) { if (obj.databaseType == 1) { obj.eventsfile.find({ domain: domain, ids: { $in: ids } }, { _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).exec(func); } else { obj.eventsfile.find({ domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }, func); } };
@ -827,7 +827,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the power collection
obj.getAllPower = function (func) { obj.powerfile.find({}, func); };
obj.storePowerEvent = function (event, multiServer, func) {
checkObjectNames(event); // DEBUG CHECKING
checkObjectNames(event, 'x14'); // DEBUG CHECKING
if (multiServer != null) { event.server = multiServer.serverid; } obj.powerfile.insert(event, func);
};
obj.getPowerTimeline = function (nodeid, func) { if (obj.databaseType == 1) { obj.powerfile.find({ nodeid: { $in: ['*', nodeid] } }, { _id: 0, nodeid: 0, s: 0 }).sort({ time: 1 }).exec(func); } else { obj.powerfile.find({ nodeid: { $in: ['*', nodeid] } }, { _id: 0, nodeid: 0, s: 0 }).sort({ time: 1 }, func); } };
@ -841,7 +841,7 @@ module.exports.CreateDB = function (parent, func) {
// Database actions on the Server Stats collection
obj.SetServerStats = function (data, func) {
checkObjectNames(data); // DEBUG CHECKING
checkObjectNames(data, 'x15'); // DEBUG CHECKING
obj.serverstatsfile.insert(data, func);
};
obj.GetServerStats = function (hours, func) { var t = new Date(); t.setTime(t.getTime() - (60 * 60 * 1000 * hours)); obj.serverstatsfile.find({ time: { $gt: t } }, { _id: 0, cpu: 0 }, func); };