Added MySQL/MariaDB support for reports.
This commit is contained in:
parent
a15a5e779d
commit
ce8b2a6bd8
15
db.js
15
db.js
|
@ -1166,6 +1166,14 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
sqlDbQuery('SELECT doc FROM events JOIN eventids ON id = fkid WHERE (domain = ? AND userid = ? AND target IN (?)) GROUP BY id ORDER BY time DESC LIMIT ?', [domain, userid, ids, limit], func);
|
sqlDbQuery('SELECT doc FROM events JOIN eventids ON id = fkid WHERE (domain = ? AND userid = ? AND target IN (?)) GROUP BY id ORDER BY time DESC LIMIT ?', [domain, userid, ids, limit], func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
obj.GetEventsTimeRange = function (ids, domain, msgids, start, end, func) {
|
||||||
|
//obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }], msgid: { $in: msgids }, time: { $gte: start, $lte: end } }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: 1 }).toArray(func);
|
||||||
|
if (ids.indexOf('*') >= 0) {
|
||||||
|
sqlDbQuery('SELECT doc FROM events WHERE ((domain = ?) AND (time BETWEEN ? AND ?)) ORDER BY time', [domain, start, end], func);
|
||||||
|
} else {
|
||||||
|
sqlDbQuery('SELECT doc FROM events JOIN eventids ON id = fkid WHERE ((domain = ?) AND (target IN (?)) AND (time BETWEEN ? AND ?)) GROUP BY id ORDER BY time', [domain, ids, start, end], func);
|
||||||
|
}
|
||||||
|
};
|
||||||
//obj.GetUserLoginEvents = function (domain, username, func) { } // TODO
|
//obj.GetUserLoginEvents = function (domain, username, func) { } // TODO
|
||||||
obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { sqlDbQuery('SELECT doc FROM events WHERE (nodeid = ?) AND (domain = ?) ORDER BY time DESC LIMIT ?', [nodeid, domain, limit], func); };
|
obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { sqlDbQuery('SELECT doc FROM events WHERE (nodeid = ?) AND (domain = ?) ORDER BY time DESC LIMIT ?', [nodeid, domain, limit], func); };
|
||||||
obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { sqlDbQuery('SELECT doc FROM events WHERE (nodeid = ?) AND (domain = ?) AND ((userid = ?) OR (userid IS NULL)) ORDER BY time DESC LIMIT ?', [nodeid, domain, userid, limit], func); };
|
obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { sqlDbQuery('SELECT doc FROM events WHERE (nodeid = ?) AND (domain = ?) AND ((userid = ?) OR (userid IS NULL)) ORDER BY time DESC LIMIT ?', [nodeid, domain, userid, limit], func); };
|
||||||
|
@ -1589,6 +1597,13 @@ module.exports.CreateDB = function (parent, func) {
|
||||||
obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func);
|
obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
obj.GetEventsTimeRange = function (ids, domain, msgids, start, end, func) {
|
||||||
|
if (obj.databaseType == 1) {
|
||||||
|
obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }], msgid: { $in: msgids }, time: { $gte: start, $lte: end } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: 1 }).exec(func);
|
||||||
|
} else {
|
||||||
|
obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }], msgid: { $in: msgids }, time: { $gte: start, $lte: end } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: 1 }, func);
|
||||||
|
}
|
||||||
|
};
|
||||||
obj.GetUserLoginEvents = function (domain, userid, func) {
|
obj.GetUserLoginEvents = function (domain, userid, func) {
|
||||||
if (obj.databaseType == 1) {
|
if (obj.databaseType == 1) {
|
||||||
obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, userid: userid, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1, tokenName: 1 }).sort({ time: -1 }).exec(func);
|
obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, userid: userid, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1, tokenName: 1 }).sort({ time: -1 }).exec(func);
|
||||||
|
|
|
@ -5420,6 +5420,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||||
if ((user.siteadmin & SITERIGHT_MANAGEUSERS) != 0) { ids = ['*']; }
|
if ((user.siteadmin & SITERIGHT_MANAGEUSERS) != 0) { ids = ['*']; }
|
||||||
|
|
||||||
// Get the events in the time range
|
// Get the events in the time range
|
||||||
|
// MySQL or MariaDB query will ignore the MsgID filter.
|
||||||
db.GetEventsTimeRange(ids, domain.id, [5, 10, 12], new Date(command.start * 1000), new Date(command.end * 1000), function (err, docs) {
|
db.GetEventsTimeRange(ids, domain.id, [5, 10, 12], new Date(command.start * 1000), new Date(command.end * 1000), function (err, docs) {
|
||||||
if (err != null) return;
|
if (err != null) return;
|
||||||
var data = { groups: {} };
|
var data = { groups: {} };
|
||||||
|
@ -5437,6 +5438,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||||
|
|
||||||
// Rows
|
// Rows
|
||||||
for (var i in docs) {
|
for (var i in docs) {
|
||||||
|
if ((docs[i].msgid != 5) && (docs[i].msgid != 10) && (docs[i].msgid != 12)) continue; // If MySQL or MariaDB query, we can't filter on MsgID, so we have to do it here.
|
||||||
|
|
||||||
var entry = { time: docs[i].time.valueOf() };
|
var entry = { time: docs[i].time.valueOf() };
|
||||||
|
|
||||||
// UserID
|
// UserID
|
||||||
|
|
Loading…
Reference in New Issue