Fixed MySQL/MariaDB server exception.

Ylian Saint-Hilaire committed Mar 10, 2021 at 13:09 UTC 19cfae4295973a17a2030157f4e296a81cf66c35
3 files changed +11 -6
db.js
+2 -2
@@ -450,7 +450,7 @@ module.exports.CreateDB = function (parent, func) {
450 }
451 //sqlDbQuery('DROP DATABASE MeshCentral', null, function (err, docs) { console.log('DROP'); }); return;
452 sqlDbQuery('USE meshcentral', null, function (err, docs) {
453 - if (err != null) { parent.debug('db', 'ERROR: USE meshcentral: ' + err); }
453 + if (err != null) { console.log(err); parent.debug('db', 'ERROR: USE meshcentral: ' + err); }
454 if (err == null) { setupFunctions(func); } else {
455 parent.debug('db', 'Creating database...');
456 sqlDbBatchExec([
@@ -994,7 +994,7 @@ module.exports.CreateDB = function (parent, func) {
994 if (ids.indexOf('*') >= 0) {
995 sqlDbQuery('SELECT doc FROM meshcentral.events WHERE (domain = ? AND userid = ?) ORDER BY time DESC', [domain, userid], func);
996 } else {
997 - 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);
997 + 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);
998 }
999 };
1000 obj.GetUserEventsWithLimit = function (ids, domain, username, limit, func) {
meshcentral.js
+3 -2
@@ -2970,7 +2970,7 @@ function InstallModule(modulename, func, tag1, tag2) {
2970 // Get the working directory
2971 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, '../..'); }
2972
2973 - child_process.exec(npmpath + ` install --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
2973 + child_process.exec(npmpath + ` install --no-save --no-optional ${modulename}`, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) {
2974 if ((error != null) && (error != '')) {
2975 var mcpath = __dirname;
2976 if (mcpath.endsWith('\\node_modules\\meshcentral') || mcpath.endsWith('/node_modules/meshcentral')) { mcpath = require('path').join(mcpath, '..', '..'); }
@@ -3076,7 +3076,8 @@ function mainStart() {
3076 if (sessionRecording == true) { modules.push('image-size'); } // Need to get the remote desktop JPEG sizes to index the recodring file.
3077 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
3078 if (config.settings.mqtt != null) { modules.push('aedes'); } // Add MQTT Modules
3079 - if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL, official driver.
3079 + if (config.settings.mysql != null) { modules.push('mysql'); } // Add MySQL.
3080 + //if (config.settings.mysql != null) { modules.push('@mysql/xdevapi'); } // Add MySQL, official driver (https://dev.mysql.com/doc/dev/connector-nodejs/8.0/)
3081 if (config.settings.mongodb != null) { modules.push('mongodb'); modules.push('saslprep'); } // Add MongoDB, official driver.
3082 if (config.settings.mariadb != null) { modules.push('mariadb'); } // Add MariaDB, official driver.
3083 if (config.settings.vault != null) { modules.push('node-vault'); } // Add official HashiCorp's Vault module.
meshuser.js
+6 -2
@@ -5412,7 +5412,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5412 db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
5413 if (err != null) return;
5414 var e = [];
5415 - 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 }); } }
5415 + for (var i in docs) {
5416 + if ((docs[i].msgArgs) && (docs[i].userid == user._id) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) {
5417 + e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs });
5418 + }
5419 + }
5420 try { ws.send(JSON.stringify({ action: 'previousLogins', events: e })); } catch (ex) { }
5421 });
5422 }
@@ -5423,7 +5427,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
5427 if ((obj.crossDomain === true) || (splitUser[1] === domain.id)) {
5428 if (db.GetUserLoginEvents) {
5429 // New way
5426 - db.GetUserLoginEvents(splitUser[1], user._id, function (err, docs) {
5430 + db.GetUserLoginEvents(splitUser[1], command.userid, function (err, docs) {
5431 if (err != null) return;
5432 var e = [];
5433 for (var i in docs) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); }