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

Plugin and meshcmd fixes.

This commit is contained in:
Ylian Saint-Hilaire 2019-10-25 01:16:00 -07:00
parent 5f044e2fd2
commit ccf8999e29
5 changed files with 27 additions and 26 deletions

View file

@ -611,7 +611,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
try { fs.mkdirSync(path); } catch (e) { }
try { fs.mkdirSync(path + "/" + command.newfolder); } catch (e) { }
}
}
}
else if (command.fileop == 'delete') {
// Delete a file
if (common.validateArray(command.delfiles, 1) == false) return;
@ -669,7 +669,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
switch (cmd) {
case 'help': {
r = 'Available commands: help, info, versions, args, resetserver, showconfig, usersessions, tasklimiter, setmaxtasks, cores,\r\n'
r = 'Available commands: help, info, versions, args, resetserver, showconfig, usersessions, tasklimiter, setmaxtasks, cores,\r\n'
r += 'migrationagents, agentstats, webstats, mpsstats, swarmstats, acceleratorsstats, updatecheck, serverupdate, nodeconfig,\r\n';
r += 'heapdump, relays, autobackup, backupconfig, dupagents, dispatchtable.';
break;
@ -735,7 +735,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
case 'info': {
var info = process.memoryUsage();
info.dbType = ['None','NeDB','MongoJS','MongoDB'][parent.db.databaseType];
info.dbType = ['None', 'NeDB', 'MongoJS', 'MongoDB'][parent.db.databaseType];
if (parent.db.databaseType == 3) { info.dbChangeStream = parent.db.changeStream; }
try { info.platform = process.platform; } catch (ex) { }
try { info.arch = process.arch; } catch (ex) { }
@ -813,7 +813,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (config.domains[i].yubikey && config.domains[i].yubikey.secret) { config.domains[i].yubikey.secret = '(present)'; }
}
}
r = JSON.stringify(removeAllUnderScore(config), null, 4);
break;
}
@ -1335,7 +1335,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (command.email != null) { newuser.email = command.email.toLowerCase(); if (command.emailVerified === true) { newuser.emailVerified = true; } } // Email
if (command.resetNextLogin === true) { newuser.passchange = -1; } else { newuser.passchange = Math.floor(Date.now() / 1000); }
if (user.groups) { newuser.groups = user.groups; } // New accounts are automatically part of our groups (Realms).
parent.users[newuserid] = newuser;
// Create a user, generate a salt and hash the password
@ -1862,7 +1862,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (unknownUsers.length > 0) {
// Send error back, user not found.
displayNotificationMessage('User' + ((unknownUsers.length > 1)?'s':'') + ' ' + EscapeHtml(unknownUsers.join(', ')) + ' not found.', 'Device Group', 'ServerNotify');
displayNotificationMessage('User' + ((unknownUsers.length > 1) ? 's' : '') + ' ' + EscapeHtml(unknownUsers.join(', ')) + ' not found.', 'Device Group', 'ServerNotify');
}
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'addmeshuser', responseid: command.responseid, result: 'ok', removed: removedCount, failed: failCount })); } catch (ex) { } }
@ -2483,8 +2483,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
case 'inviteAgent':
{
var err = null, mesh = null;
try
{
try {
if ((parent.parent.mailserver == null) || (args.lanonly == true)) { err = 'Unsupported feature'; } // This operation requires the email server
else if ((parent.parent.certificates.CommonName == null) || (parent.parent.certificates.CommonName.indexOf('.') == -1)) { err = 'Unsupported feature'; } // Server name must be configured
else if (common.validateString(command.meshid, 1, 1024) == false) { err = 'Invalid group identifier'; } // Check meshid
@ -3034,7 +3033,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
db.Get(nodeid, function (err, nodes) {
if ((nodes == null) || (nodes.length != 1)) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'getmqttlogin', responseid: command.responseid, result: 'Invalid node id' })); } catch (ex) { } return; } }
var node = nodes[0];
// Get the device group for this node
var mesh = parent.meshes[node.meshid];
if (mesh) {
@ -3071,11 +3070,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
if (common.validateInt(command.mode, 0, 3) == false) break; // Check connection mode
// Validate if communication mode is possible
if (command.mode == null || command.mode==0) {
if (command.mode == null || command.mode == 0) {
break; //unsupported
} else if (command.mode == 1) {
var state = parent.parent.GetConnectivityState(command.nodeid);
if ( (state == null) || (state.connectivity & 4)==0 ) break;
if ((state == null) || (state.connectivity & 4) == 0) break;
} else if (command.mode == 2) {
if (parent.parent.mpsserver.ciraConnections[command.nodeid] == null) break;
} else if (command.mode == 3) {
@ -3101,18 +3100,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
break;
}
case 'plugin': {
if (parent.parent.pluginHandler == null) break; // If the plugin's are not supported, reject this command.
command.userid = user._id;
if (command.routeToNode === true) {
routeCommandToNode(command);
routeCommandToNode(command);
} else {
try {
var pluginHandler = require('./pluginHandler.js').pluginHandler(parent.parent);
pluginHandler.plugins[command.plugin].serveraction(command, obj, parent);
} catch (e) { console.log('Error loading plugin handler (' + e + ')'); }
try {
var pluginHandler = require('./pluginHandler.js').pluginHandler(parent.parent);
pluginHandler.plugins[command.plugin].serveraction(command, obj, parent);
} catch (e) { console.log('Error loading plugin handler (' + e + ')'); }
}
break;
break;
}
default: {
// Unknown user action