Added removedevice command to meshctrl.js (#4753)

This commit is contained in:
Ylian Saint-Hilaire 2022-11-14 16:31:44 -08:00
parent 09bcb739b1
commit 876641f1ac
2 changed files with 41 additions and 26 deletions

View File

@ -16,7 +16,7 @@ var settings = {};
const crypto = require('crypto');
const args = require('minimist')(process.argv.slice(2));
const path = require('path');
const possibleCommands = ['edituser', 'listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'listevents', 'logintokens', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'editdevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config', 'movetodevicegroup', 'deviceinfo', 'editdevice', 'addusergroup', 'listusergroups', 'removeusergroup', 'runcommand', 'shell', 'upload', 'download', 'deviceopenurl', 'devicemessage', 'devicetoast', 'addtousergroup', 'removefromusergroup', 'removeallusersfromusergroup', 'devicesharing', 'devicepower', 'indexagenterrorlog', 'agentdownload'];
const possibleCommands = ['edituser', 'listusers', 'listusersessions', 'listdevicegroups', 'listdevices', 'listusersofdevicegroup', 'listevents', 'logintokens', 'serverinfo', 'userinfo', 'adduser', 'removeuser', 'adddevicegroup', 'removedevicegroup', 'editdevicegroup', 'broadcast', 'showevents', 'addusertodevicegroup', 'removeuserfromdevicegroup', 'addusertodevice', 'removeuserfromdevice', 'sendinviteemail', 'generateinvitelink', 'config', 'movetodevicegroup', 'deviceinfo', 'removedevice', 'editdevice', 'addusergroup', 'listusergroups', 'removeusergroup', 'runcommand', 'shell', 'upload', 'download', 'deviceopenurl', 'devicemessage', 'devicetoast', 'addtousergroup', 'removefromusergroup', 'removeallusersfromusergroup', 'devicesharing', 'devicepower', 'indexagenterrorlog', 'agentdownload'];
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) {
@ -37,6 +37,7 @@ if (args['_'].length == 0) {
console.log(" LoginTokens - List, create and remove login tokens.");
console.log(" DeviceInfo - Show information about a device.");
console.log(" EditDevice - Make changes to a device.");
console.log(" RemoveDevice - Delete a device.");
console.log(" Config - Perform operation on config.json file.");
console.log(" AddUser - Create a new user account.");
console.log(" EditUser - Change a user account.");
@ -97,16 +98,9 @@ if (args['_'].length == 0) {
case 'listdevices': { ok = true; break; }
case 'listevents': { ok = true; break; }
case 'logintokens': { ok = true; break; }
case 'listusersofdevicegroup': {
if (args.id == null) { console.log(winRemoveSingleQuotes("Missing group id, use --id '[groupid]'")); }
else { ok = true; }
break;
}
case 'deviceinfo': {
if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
else { ok = true; }
break;
}
case 'listusersofdevicegroup':
case 'deviceinfo':
case 'removedevice':
case 'editdevice': {
if (args.id == null) { console.log(winRemoveSingleQuotes("Missing device id, use --id '[deviceid]'")); }
else { ok = true; }
@ -764,6 +758,17 @@ if (args['_'].length == 0) {
console.log(" --json - Give results in JSON format.");
break;
}
case 'removedevice': {
console.log("Delete a device, Example usages:\r\n");
console.log(winRemoveSingleQuotes(" MeshCtrl RemoveDevice --id 'deviceid'"));
console.log("\r\nRequired arguments:\r\n");
if (process.platform == 'win32') {
console.log(" --id [deviceid] - The device identifier.");
} else {
console.log(" --id '[deviceid]' - The device identifier.");
}
break;
}
case 'editdevice': {
console.log("Change information about a device, Example usages:\r\n");
console.log(winRemoveSingleQuotes(" MeshCtrl EditDevice --id 'deviceid' --name 'device1'"));
@ -1488,6 +1493,11 @@ function serverConnect() {
ws.send(JSON.stringify({ action: 'getsysinfo', nodeid: args.id, nodeinfo: true, responseid: 'meshctrl' }));
break;
}
case 'removedevice': {
var op = { action: 'removedevices', nodeids: [ args.id ], responseid: 'meshctrl' };
ws.send(JSON.stringify(op));
break;
}
case 'editdevice': {
var op = { action: 'changedevice', nodeid: args.id, responseid: 'meshctrl' };
if (typeof args.name == 'string') { op.name = args.name; }
@ -1893,6 +1903,7 @@ function serverConnect() {
case 'toast': // TOAST
case 'adduser': // ADDUSER
case 'edituser': // EDITUSER
case 'removedevices': // REMOVEDEVICE
case 'changedevice': // EDITDEVICE
case 'deleteuser': // REMOVEUSER
case 'createmesh': // ADDDEVICEGROUP

View File

@ -2781,6 +2781,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
});
}
// Send response if required, in this case we always send ok which is not ideal.
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'removedevices', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
break;
}
case 'wakedevices':