Added user group management commands to MeshCtrl.js
This commit is contained in:
parent
f5a8865ff8
commit
5a6c3bc6b5
124
meshctrl.js
124
meshctrl.js
|
@ -7,7 +7,7 @@ try { require('ws'); } catch (ex) { console.log('Missing module "ws", type "npm
|
||||||
var settings = {};
|
var settings = {};
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const args = require('minimist')(process.argv.slice(2));
|
const args = require('minimist')(process.argv.slice(2));
|
||||||
const possibleCommands = ['listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'listusersofusergroup', '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', 'deviceopenurl', 'devicemessage', 'devicetoast'];
|
const possibleCommands = ['listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'listusersofusergroup', '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', 'deviceopenurl', 'devicemessage', 'devicetoast', 'addusertousergroup', 'removeuserfromusergroup', 'removeallusersfromusergroup'];
|
||||||
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.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) {
|
if (args['_'].length == 0) {
|
||||||
|
@ -31,6 +31,11 @@ if (args['_'].length == 0) {
|
||||||
console.log(" RemoveUser - Delete a user account.");
|
console.log(" RemoveUser - Delete a user account.");
|
||||||
console.log(" AddUserGroup - Create a new user group.");
|
console.log(" AddUserGroup - Create a new user group.");
|
||||||
console.log(" RemoveUserGroup - Delete a user group.");
|
console.log(" RemoveUserGroup - Delete a user group.");
|
||||||
|
|
||||||
|
console.log(" AddUserToUserGroup - Add a user to an existing user group.");
|
||||||
|
console.log(" RemoveUserFromUserGroup - Remove a user from a user group.");
|
||||||
|
console.log(" RemoveAllUsersFromUserGroup - Remove all users from a user group.");
|
||||||
|
|
||||||
console.log(" AddDeviceGroup - Create a new device group.");
|
console.log(" AddDeviceGroup - Create a new device group.");
|
||||||
console.log(" RemoveDeviceGroup - Delete a device group.");
|
console.log(" RemoveDeviceGroup - Delete a device group.");
|
||||||
console.log(" EditDeviceGroup - Change a device group values.");
|
console.log(" EditDeviceGroup - Change a device group values.");
|
||||||
|
@ -163,6 +168,23 @@ if (args['_'].length == 0) {
|
||||||
else { ok = true; }
|
else { ok = true; }
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'addusertousergroup': {
|
||||||
|
if (args.groupid == null) { console.log(winRemoveSingleQuotes("Group id missing, use --groupid '[id]'")); }
|
||||||
|
if (args.userid == null) { console.log(winRemoveSingleQuotes("User id missing, use --userid '[id]'")); }
|
||||||
|
else { ok = true; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeuserfromusergroup': {
|
||||||
|
if (args.groupid == null) { console.log(winRemoveSingleQuotes("Group id missing, use --groupid '[id]'")); }
|
||||||
|
if (args.userid == null) { console.log(winRemoveSingleQuotes("User id missing, use --userid '[id]'")); }
|
||||||
|
else { ok = true; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeallusersfromusergroup': {
|
||||||
|
if (args.groupid == null) { console.log(winRemoveSingleQuotes("Group id missing, use --groupid '[id]'")); }
|
||||||
|
else { ok = true; }
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'sendinviteemail': {
|
case 'sendinviteemail': {
|
||||||
if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
|
if ((args.id == null) && (args.group == null)) { console.log("Device group identifier missing, use --id '[groupid]' or --group [groupname]"); }
|
||||||
else if (args.email == null) { console.log("Device email is missing, use --email [email]"); }
|
else if (args.email == null) { console.log("Device email is missing, use --email [email]"); }
|
||||||
|
@ -379,6 +401,61 @@ if (args['_'].length == 0) {
|
||||||
console.log(" --userid [id] - Account identifier.");
|
console.log(" --userid [id] - Account identifier.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'addusergroup': {
|
||||||
|
console.log("Create a new user group, Example usages:\r\n");
|
||||||
|
console.log(" MeshCtrl AddUserGroup --name \"Test Group\"");
|
||||||
|
console.log("\r\nRequired arguments:\r\n");
|
||||||
|
console.log(" --name [name] - Name of the user group.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeusergroup': {
|
||||||
|
console.log("Remove a user group, Example usages:\r\n");
|
||||||
|
console.log(winRemoveSingleQuotes(" MeshCtrl RemoveUserGroup --groupid 'ugrp//abcdf'"));
|
||||||
|
console.log("\r\nRequired arguments:\r\n");
|
||||||
|
if (process.platform == 'win32') {
|
||||||
|
console.log(" --groupid [groupid] - User group identifier.");
|
||||||
|
} else {
|
||||||
|
console.log(" --groupid '[groupid]' - User group identifier.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'addusertousergroup': {
|
||||||
|
console.log("Add a user to a user group, Example usages:\r\n");
|
||||||
|
console.log(winRemoveSingleQuotes(" MeshCtrl AddUserToUserGroup --userid 'user//abcdef' --groupid 'ugrp//abcdf'"));
|
||||||
|
console.log("\r\nRequired arguments:\r\n");
|
||||||
|
if (process.platform == 'win32') {
|
||||||
|
console.log(" --userid [userid] - User identifier.");
|
||||||
|
console.log(" --groupid [groupid] - User group identifier.");
|
||||||
|
} else {
|
||||||
|
console.log(" --userid '[userid]' - User identifier.");
|
||||||
|
console.log(" --groupid '[groupid]' - User group identifier.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeuserfromusergroup': {
|
||||||
|
console.log("Remove a user from a user group, Example usages:\r\n");
|
||||||
|
console.log(winRemoveSingleQuotes(" MeshCtrl RemoveUserFromUserGroup --userid 'user//abcdef' --groupid 'ugrp//abcdf'"));
|
||||||
|
console.log("\r\nRequired arguments:\r\n");
|
||||||
|
if (process.platform == 'win32') {
|
||||||
|
console.log(" --userid [userid] - User identifier.");
|
||||||
|
console.log(" --groupid [groupid] - User group identifier.");
|
||||||
|
} else {
|
||||||
|
console.log(" --userid '[userid]' - User identifier.");
|
||||||
|
console.log(" --groupid '[groupid]' - User group identifier.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeallusersfromusergroup': {
|
||||||
|
console.log("Remove all users from a user group, Example usages:\r\n");
|
||||||
|
console.log(winRemoveSingleQuotes(" MeshCtrl RemoveAllUsersFromUserGroup --groupid 'ugrp//abcdf'"));
|
||||||
|
console.log("\r\nRequired arguments:\r\n");
|
||||||
|
if (process.platform == 'win32') {
|
||||||
|
console.log(" --groupid [groupid] - User group identifier.");
|
||||||
|
} else {
|
||||||
|
console.log(" --groupid '[groupid]' - User group identifier.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'adddevicegroup': {
|
case 'adddevicegroup': {
|
||||||
console.log("Add a device group, Example usages:\r\n");
|
console.log("Add a device group, Example usages:\r\n");
|
||||||
console.log(" MeshCtrl AddDeviceGroup --name newgroupname");
|
console.log(" MeshCtrl AddDeviceGroup --name newgroupname");
|
||||||
|
@ -870,9 +947,10 @@ function serverConnect() {
|
||||||
case 'serverinfo': { break; }
|
case 'serverinfo': { break; }
|
||||||
case 'userinfo': { break; }
|
case 'userinfo': { break; }
|
||||||
case 'listusers': { ws.send(JSON.stringify({ action: 'users', responseid: 'meshctrl' })); break; }
|
case 'listusers': { ws.send(JSON.stringify({ action: 'users', responseid: 'meshctrl' })); break; }
|
||||||
case 'listusersessions': { ws.send(JSON.stringify({ action: 'wssessioncount', responseid: 'meshctrl' })); }
|
case 'listusersessions': { ws.send(JSON.stringify({ action: 'wssessioncount', responseid: 'meshctrl' })); break; }
|
||||||
case 'listusersofusergroup':
|
case 'listusersofusergroup':
|
||||||
case 'listusergroups': { ws.send(JSON.stringify({ action: 'usergroups', responseid: 'meshctrl' })); }
|
case 'removeallusersfromusergroup':
|
||||||
|
case 'listusergroups': { ws.send(JSON.stringify({ action: 'usergroups', responseid: 'meshctrl' })); break; }
|
||||||
case 'listdevicegroups': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
case 'listdevicegroups': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
||||||
case 'listusersofdevicegroup': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
case 'listusersofdevicegroup': { ws.send(JSON.stringify({ action: 'meshes', responseid: 'meshctrl' })); break; }
|
||||||
case 'listdevices': {
|
case 'listdevices': {
|
||||||
|
@ -922,6 +1000,22 @@ function serverConnect() {
|
||||||
ws.send(JSON.stringify({ action: 'deleteusergroup', ugrpid: ugrpid, responseid: 'meshctrl' }));
|
ws.send(JSON.stringify({ action: 'deleteusergroup', ugrpid: ugrpid, responseid: 'meshctrl' }));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'addusertousergroup': {
|
||||||
|
var ugrpid = args.groupid;
|
||||||
|
if ((args.domain != null) && (userid.indexOf('/') < 0)) { ugrpid = 'ugrp/' + args.domain + '/' + ugrpid; }
|
||||||
|
var userid = args.userid;
|
||||||
|
if ((args.domain != null) && (userid.indexOf('/') < 0)) { userid = 'user/' + args.domain + '/' + userid; }
|
||||||
|
ws.send(JSON.stringify({ action: 'addusertousergroup', ugrpid: ugrpid, usernames: [userid], responseid: 'meshctrl' }));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'removeuserfromusergroup': {
|
||||||
|
var ugrpid = args.groupid;
|
||||||
|
if ((args.domain != null) && (userid.indexOf('/') < 0)) { ugrpid = 'ugrp/' + args.domain + '/' + ugrpid; }
|
||||||
|
var userid = args.userid;
|
||||||
|
if ((args.domain != null) && (userid.indexOf('/') < 0)) { userid = 'user/' + args.domain + '/' + userid; }
|
||||||
|
ws.send(JSON.stringify({ action: 'removeuserfromusergroup', ugrpid: ugrpid, userid: userid, responseid: 'meshctrl' }));
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'adddevicegroup': {
|
case 'adddevicegroup': {
|
||||||
var op = { action: 'createmesh', meshname: args.name, meshtype: 2, responseid: 'meshctrl' };
|
var op = { action: 'createmesh', meshname: args.name, meshtype: 2, responseid: 'meshctrl' };
|
||||||
if (args.desc) { op.desc = args.desc; }
|
if (args.desc) { op.desc = args.desc; }
|
||||||
|
@ -1167,7 +1261,10 @@ function serverConnect() {
|
||||||
case 'createusergroup': //
|
case 'createusergroup': //
|
||||||
case 'deleteusergroup': //
|
case 'deleteusergroup': //
|
||||||
case 'runcommands':
|
case 'runcommands':
|
||||||
|
case 'addusertousergroup':
|
||||||
|
case 'removeuserfromusergroup':
|
||||||
case 'userbroadcast': { // BROADCAST
|
case 'userbroadcast': { // BROADCAST
|
||||||
|
if ((settings.multiresponse != null) && (settings.multiresponse > 1)) { settings.multiresponse--; break; }
|
||||||
if (data.responseid == 'meshctrl') {
|
if (data.responseid == 'meshctrl') {
|
||||||
if (data.meshid) { console.log(data.result, data.meshid); }
|
if (data.meshid) { console.log(data.result, data.meshid); }
|
||||||
else if (data.userid) { console.log(data.result, data.userid); }
|
else if (data.userid) { console.log(data.result, data.userid); }
|
||||||
|
@ -1216,6 +1313,27 @@ function serverConnect() {
|
||||||
if (usercount == 0) { console.log('No users in this user group.'); }
|
if (usercount == 0) { console.log('No users in this user group.'); }
|
||||||
}
|
}
|
||||||
process.exit();
|
process.exit();
|
||||||
|
} else if (settings.cmd == 'removeallusersfromusergroup') {
|
||||||
|
var ugrpid = args.groupid, exit = false;
|
||||||
|
if ((args.domain != null) && (userid.indexOf('/') < 0)) { ugrpid = 'ugrp/' + args.domain + '/' + ugrpid; }
|
||||||
|
var ugroup = data.ugroups[ugrpid];
|
||||||
|
if (ugroup == null) {
|
||||||
|
console.log('User group not found.');
|
||||||
|
exit = true;
|
||||||
|
} else {
|
||||||
|
var usercount = 0;
|
||||||
|
if (ugroup.links) {
|
||||||
|
for (var i in ugroup.links) {
|
||||||
|
if (i.startsWith('user/')) {
|
||||||
|
usercount++;
|
||||||
|
ws.send(JSON.stringify({ action: 'removeuserfromusergroup', ugrpid: ugrpid, userid: i, responseid: 'meshctrl' }));
|
||||||
|
console.log('Removing ' + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (usercount == 0) { console.log('No users in this user group.'); exit = true; } else { settings.multiresponse = usercount; }
|
||||||
|
}
|
||||||
|
if (exit) { process.exit(); }
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2360,6 +2360,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the user exists
|
// Check if the user exists
|
||||||
|
if (command.userid.startsWith('user/') == false) { command.userid = 'user/' + removeUserDomain.id + '/' + command.userid.toLowerCase(); }
|
||||||
var chguser = parent.users[command.userid];
|
var chguser = parent.users[command.userid];
|
||||||
if (chguser != null) {
|
if (chguser != null) {
|
||||||
var change = false;
|
var change = false;
|
||||||
|
@ -2396,6 +2397,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'removeuserfromusergroup', responseid: command.responseid, result: 'ok', added: addedCount, failed: failCount })); } catch (ex) { } }
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'changemeshnotify':
|
case 'changemeshnotify':
|
||||||
|
|
Loading…
Reference in New Issue