mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-22 21:31:35 +03:00
Added device group edit in MeshCtrl.js.
This commit is contained in:
parent
a2a47a1320
commit
39295112ad
59
meshctrl.js
59
meshctrl.js
@ -7,7 +7,7 @@ try { require('ws'); } catch (ex) { console.log('Missing module "ws", type "npm
|
||||
var settings = {};
|
||||
const crypto = require('crypto');
|
||||
const args = require('minimist')(process.argv.slice(2));
|
||||
const possibleCommands = ['listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config', 'movetodevicegroup', 'deviceinfo', 'addusergroup', 'listusergroups', 'removeusergroup', 'runcommand', 'shell', 'upload', 'download'];
|
||||
const possibleCommands = ['listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'editdevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config', 'movetodevicegroup', 'deviceinfo', 'addusergroup', 'listusergroups', 'removeusergroup', 'runcommand', 'shell', 'upload', 'download'];
|
||||
if (args.proxy != null) { try { require('https-proxy-agent'); } catch (ex) { console.log('Missing module "https-proxy-agent", type "npm install https-proxy-agent" to install it.'); return; } }
|
||||
|
||||
if (args['_'].length == 0) {
|
||||
@ -32,6 +32,7 @@ if (args['_'].length == 0) {
|
||||
console.log(" RemoveUserGroup - Delete a user group.");
|
||||
console.log(" AddDeviceGroup - Create a new device group.");
|
||||
console.log(" RemoveDeviceGroup - Delete a device group.");
|
||||
console.log(" EditDeviceGroup - Change a device group values.");
|
||||
console.log(" MoveToDeviceGroup - Move a device to a different device group.");
|
||||
console.log(" AddUserToDeviceGroup - Add a user to a device group.");
|
||||
console.log(" RemoveUserFromDeviceGroup - Remove a user from a device group.");
|
||||
@ -109,6 +110,7 @@ if (args['_'].length == 0) {
|
||||
else { ok = true; }
|
||||
break;
|
||||
}
|
||||
case 'editdevicegroup':
|
||||
case 'removedevicegroup': {
|
||||
if ((args.id == null) && (args.group == null)) { console.log(winRemoveSingleQuotes("Device group identifier missing, use --id '[groupid]' or --group [groupname]")); }
|
||||
else { ok = true; }
|
||||
@ -360,6 +362,35 @@ if (args['_'].length == 0) {
|
||||
console.log(" --group [groupname] - Device group name (or --id).");
|
||||
break;
|
||||
}
|
||||
case 'editdevicegroup': {
|
||||
console.log("Edit a device group, Example usages:\r\n");
|
||||
console.log(" MeshCtrl EditDeviceGroup --id 'groupid' --name 'NewName'");
|
||||
console.log("\r\nRequired arguments:\r\n");
|
||||
if (process.platform == 'win32') {
|
||||
console.log(" --id [groupid] - Device group identifier (or --group).");
|
||||
} else {
|
||||
console.log(" --id '[groupid]' - Device group identifier (or --group).");
|
||||
}
|
||||
console.log(" --group [groupname] - Device group name (or --id).");
|
||||
console.log("\r\nOptional arguments:\r\n");
|
||||
console.log(" --name [name] - Set new device group name.");
|
||||
console.log(" --desc [name] - Set new device group description, blank to clear.");
|
||||
console.log(" --flags [number] - Set device group flags, sum of the values below, 0 for none.");
|
||||
console.log(" 1 = Auto remove device on disconnect.");
|
||||
console.log(" 2 = Sync hostname.");
|
||||
console.log(" --consent [number] - Set device group consent options, sum of the values below, 0 for none.");
|
||||
console.log(" 1 = Desktop notify user.");
|
||||
console.log(" 2 = Terminal notify user.");
|
||||
console.log(" 4 = Files notify user.");
|
||||
console.log(" 8 = Desktop prompt for user consent.");
|
||||
console.log(" 16 = Terminal prompt for user consent.");
|
||||
console.log(" 32 = Files prompt for user consent.");
|
||||
console.log(" 64 = Desktop show connection toolbar.");
|
||||
console.log(" --invitecodes [aa,bb] - Comma seperated list of invite codes, blank to clear.");
|
||||
console.log(" --backgroundonly - When used with invitecodes, set agent to only install in background.");
|
||||
console.log(" --interactiveonly - When used with invitecodes, set agent to only run on demand.");
|
||||
break;
|
||||
}
|
||||
case 'movetodevicegroup': {
|
||||
console.log("Move a device to a new device group, Example usages:\r\n");
|
||||
console.log(winRemoveSingleQuotes(" MeshCtrl MoveToDeviceGroup --devid 'deviceid' --id 'groupid'"));
|
||||
@ -814,6 +845,31 @@ function serverConnect() {
|
||||
ws.send(JSON.stringify(op));
|
||||
break;
|
||||
}
|
||||
case 'editdevicegroup': {
|
||||
var op = { action: 'editmesh', responseid: 'meshctrl' };
|
||||
if (args.id) { op.meshid = args.id; } else if (args.group) { op.meshidname = args.group; }
|
||||
if ((typeof args.name == 'string') && (args.name != '')) { op.meshname = args.name; }
|
||||
if (args.desc === true) { op.desc = ""; } else if (typeof args.desc == 'string') { op.desc = args.desc; }
|
||||
if (args.invitecodes === true) { op.invite = "*"; } else if (typeof args.invitecodes == 'string') {
|
||||
var invitecodes = args.invitecodes.split(','), invitecodes2 = [];
|
||||
for (var i in invitecodes) { if (invitecodes[i].length > 0) { invitecodes2.push(invitecodes[i]); } }
|
||||
if (invitecodes2.length > 0) {
|
||||
op.invite = { codes: invitecodes2, flags: 0 };
|
||||
if (args.backgroundonly === true) { op.invite.flags = 2; }
|
||||
else if (args.interactiveonly === true) { op.invite.flags = 1; }
|
||||
}
|
||||
}
|
||||
if (args.flags != null) {
|
||||
var flags = parseInt(args.flags);
|
||||
if (typeof flags == 'number') { op.flags = flags; }
|
||||
}
|
||||
if (args.consent != null) {
|
||||
var consent = parseInt(args.consent);
|
||||
if (typeof consent == 'number') { op.consent = consent; }
|
||||
}
|
||||
ws.send(JSON.stringify(op));
|
||||
break;
|
||||
}
|
||||
case 'movetodevicegroup': {
|
||||
var op = { action: 'changeDeviceMesh', responseid: 'meshctrl', nodeids: [ args.devid ] };
|
||||
if (args.id) { op.meshid = args.id; } else if (args.group) { op.meshname = args.group; }
|
||||
@ -1000,6 +1056,7 @@ function serverConnect() {
|
||||
case 'deleteuser': // REMOVEUSER
|
||||
case 'createmesh': // ADDDEVICEGROUP
|
||||
case 'deletemesh': // REMOVEDEVICEGROUP
|
||||
case 'editmesh': // EDITDEVICEGROUP
|
||||
case 'changeDeviceMesh':
|
||||
case 'addmeshuser': //
|
||||
case 'removemeshuser': //
|
||||
|
34
meshuser.js
34
meshuser.js
@ -2590,6 +2590,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
case 'deletemesh':
|
||||
{
|
||||
// Delete a mesh and all computers within it
|
||||
var err = null;
|
||||
|
||||
// Resolve the device group name if needed
|
||||
@ -2602,8 +2603,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
}
|
||||
}
|
||||
|
||||
// Validate input
|
||||
try {
|
||||
// Delete a mesh and all computers within it
|
||||
if (common.validateString(command.meshid, 1, 1024) == false) { err = 'Invalid group identifier'; } // Check the meshid
|
||||
else if (command.meshid.indexOf('/') == -1) { command.meshid = 'mesh/' + domain.id + '/' + command.meshid; }
|
||||
} catch (ex) { err = 'Validation exception: ' + ex; }
|
||||
@ -2682,11 +2683,33 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
case 'editmesh':
|
||||
{
|
||||
// Change the name or description of a device group (mesh)
|
||||
if (common.validateString(command.meshid, 1, 1024) == false) break; // Check the meshid
|
||||
var err = null;
|
||||
|
||||
// Resolve the device group name if needed
|
||||
if ((typeof command.meshidname == 'string') && (command.meshid == null)) {
|
||||
for (var i in parent.meshes) {
|
||||
var m = parent.meshes[i];
|
||||
if ((m.mtype == 2) && (m.name == command.meshidname) && parent.IsMeshViewable(user, m)) {
|
||||
if (command.meshid == null) { command.meshid = m._id; } else { err = 'Duplicate device groups found'; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate input
|
||||
try {
|
||||
if (common.validateString(command.meshid, 1, 1024) == false) { err = 'Invalid group identifier'; } // Check the meshid
|
||||
else if (command.meshid.indexOf('/') == -1) { command.meshid = 'mesh/' + domain.id + '/' + command.meshid; }
|
||||
if (err == null) {
|
||||
mesh = parent.meshes[command.meshid];
|
||||
if (mesh == null) { err = 'Invalid group identifier '; }
|
||||
}
|
||||
} catch (ex) { err = 'Validation exception: ' + ex; }
|
||||
|
||||
// Handle any errors
|
||||
if (err != null) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'editmesh', responseid: command.responseid, result: err })); } catch (ex) { } } break; }
|
||||
|
||||
change = '';
|
||||
|
||||
if (mesh) {
|
||||
// Check if this user has rights to do this
|
||||
if ((parent.GetMeshRights(user, mesh) & MESHRIGHT_EDITMESH) == 0) return;
|
||||
if ((command.meshid.split('/').length != 3) || (command.meshid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
|
||||
@ -2702,7 +2725,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
// Clear invite codes
|
||||
if (mesh.invite != null) { delete mesh.invite; }
|
||||
if (change != '') { change += ' and invite code changed'; } else { change += 'Group "' + mesh.name + '" invite code changed'; }
|
||||
} else if (typeof command.invite === 'object') {
|
||||
} else if ((typeof command.invite == 'object') && (Array.isArray(command.invite.codes)) && (typeof command.invite.flags == 'number')) {
|
||||
// Set invite codes
|
||||
if ((mesh.invite == null) || (mesh.invite.codes != command.invite.codes) || (mesh.invite.flags != command.invite.flags)) {
|
||||
// Check if an invite code is not already in use.
|
||||
@ -2729,7 +2752,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
|
||||
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event);
|
||||
}
|
||||
}
|
||||
|
||||
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'editmesh', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
||||
break;
|
||||
}
|
||||
case 'addmeshuser':
|
||||
|
Loading…
Reference in New Issue
Block a user