Fixed MySQL/MariaDB server exception.

This commit is contained in:
Ylian Saint-Hilaire 2021-03-10 13:09:43 -08:00
parent 38412b1475
commit 19cfae4295
3 changed files with 11 additions and 6 deletions

4
db.js
View File

@ -450,7 +450,7 @@ module.exports.CreateDB = function (parent, func) {
}
//sqlDbQuery('DROP DATABASE MeshCentral', null, function (err, docs) { console.log('DROP'); }); return;
sqlDbQuery('USE meshcentral', null, function (err, docs) {
if (err != null) { parent.debug('db', 'ERROR: USE meshcentral: ' + err); }
if (err != null) { console.log(err); parent.debug('db', 'ERROR: USE meshcentral: ' + err); }
if (err == null) { setupFunctions(func); } else {
parent.debug('db', 'Creating database...');
sqlDbBatchExec([
@ -994,7 +994,7 @@ module.exports.CreateDB = function (parent, func) {
if (ids.indexOf('*') >= 0) {
sqlDbQuery('SELECT doc FROM meshcentral.events WHERE (domain = ? AND userid = ?) ORDER BY time DESC', [domain, userid], func);
} else {
sqlDbQuery('SELECT doc FROM meshcentral.events JOIN meshcentral.eventids ON id = fkid WHERE (domain = ? AND userid = ? AND target IN (?)) GROUP BY id ORDER BY time DESC', [domain, userid, ids, limit], func);
sqlDbQuery('SELECT doc FROM meshcentral.events JOIN meshcentral.eventids ON id = fkid WHERE (domain = ? AND userid = ? AND target IN (?)) GROUP BY id ORDER BY time DESC', [domain, userid, ids], func);
}
};
obj.GetUserEventsWithLimit = function (ids, domain, username, limit, func) {

View File

@ -2970,7 +2970,7 @@ function InstallModule(modulename, func, tag1, tag2) {
// Get the working directory
if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); }
child_process.exec(npmpath + ` install --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
child_process.exec(npmpath + ` install --no-save --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
if ((error != null) && (error != '')) {
var mcpath = __dirname;
if (mcpath.endsWith('\\node_modules\\meshcentral') || mcpath.endsWith('/node_modules/meshcentral')) { mcpath = require('path').join(mcpath, '..', '..'); }
@ -3076,7 +3076,8 @@ function mainStart() {
if (sessionRecording == true) { modules.push('image-size'); } // Need to get the remote desktop JPEG sizes to index the recodring file.
if (config.letsencrypt != null) { if (nodeVersion < 8) { addServerWarning("Let's Encrypt support requires Node v8.x or higher.", !args.launch); } else { modules.push('acme-client'); } } // Add acme-client module
if (config.settings.mqtt != null) { modules.push('aedes'); } // Add MQTT Modules
if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL, official driver.
if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL.
//if (config.settings.mysql != null) { modules.push('@mysql/xdevapi'); } // Add MySQL, official driver (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/)
if (config.settings.mongodb != null) { modules.push('mongodb'); modules.push('saslprep'); } // Add MongoDB, official driver.
if (config.settings.mariadb != null) { modules.push('mariadb'); } // Add MariaDB, official driver.
if (config.settings.vault != null) { modules.push('node-vault'); } // Add official HashiCorp's Vault module.

View File

@ -5412,7 +5412,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
if (err != null) return;
var e = [];
for (var i in docs) { if ((docs[i].msgArgs) && (docs[i].userid == command.userid) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } }
for (var i in docs) {
if ((docs[i].msgArgs) && (docs[i].userid == user._id) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) {
e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs });
}
}
try { ws.send(JSON.stringify({ action: 'previousLogins', events: e })); } catch (ex) { }
});
}
@ -5423,7 +5427,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if ((obj.crossDomain === true) || (splitUser[1] === domain.id)) {
if (db.GetUserLoginEvents) {
// New way
db.GetUserLoginEvents(splitUser[1], user._id, function (err, docs) {
db.GetUserLoginEvents(splitUser[1], command.userid, function (err, docs) {
if (err != null) return;
var e = [];
for (var i in docs) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); }