From 9342720a404e8a791fce280d95711d37e5ba29af Mon Sep 17 00:00:00 2001
From: Ylian Saint-Hilaire
Date: Sat, 29 Aug 2020 11:43:09 -0700
Subject: [PATCH] Now need agent uninstall permission to delete a device, mesh
edit permission to move a device between groups.
---
agents/meshcore.js | 9 +++++----
meshuser.js | 4 ++--
public/scripts/amt-wsman-0.2.0-min.js | 2 +-
translate/translate.json | 27 ++++++++++++++++-----------
views/default-mobile.handlebars | 2 +-
views/default.handlebars | 14 ++++++++------
6 files changed, 33 insertions(+), 25 deletions(-)
diff --git a/agents/meshcore.js b/agents/meshcore.js
index 1c7faec0..95616c82 100644
--- a/agents/meshcore.js
+++ b/agents/meshcore.js
@@ -251,17 +251,18 @@ function createMeshCore(agent) {
return (svc);
}
- /*
// TODO: Monitor the file 'batterystate.txt' in the agent's folder and sends battery update when this file is changed.
- if (require('fs').existsSync('batterystate.txt')) {
+ /*
+ if (require('fs').existsSync(process.cwd() + 'batterystate.txt')) {
// Setup manual battery monitoring
- require('MeshAgent')._batteryFileWatcher = require('fs').watch('.', function (a) {
+ sendConsoleText('Manual Battery State Monitor');
+ require('MeshAgent')._batteryFileWatcher = require('fs').watch(process.cwd(), function (a) {
if (require('MeshAgent')._batteryFileTimer != null) return;
require('MeshAgent')._batteryFileTimer = setTimeout(function () {
sendConsoleText('Battery State Changed');
try {
require('MeshAgent')._batteryFileTimer = null;
- var data = require('fs').readFileSync('batterystate.txt').toString();
+ var data = require('fs').readFileSync(process.cwd() + 'batterystate.txt').toString();
if (data.length < 10) {
data = data.split(',');
if ((data.length == 2) && ((data[0] == 'ac') || (data[0] == 'dc'))) { require('MeshAgent').SendCommand({ action: 'battery', state: data[0], level: parseInt(data[1]) }); }
diff --git a/meshuser.js b/meshuser.js
index 86af7c65..2055a7a8 100644
--- a/meshuser.js
+++ b/meshuser.js
@@ -3333,7 +3333,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
// Make sure that we have rights on both source and destination mesh
const targetMeshRights = parent.GetMeshRights(user, command.meshid);
- if (((rights & MESHRIGHT_MANAGECOMPUTERS) == 0) || ((targetMeshRights & MESHRIGHT_MANAGECOMPUTERS) == 0)) {
+ if (((rights & MESHRIGHT_EDITMESH) == 0) || ((targetMeshRights & MESHRIGHT_EDITMESH) == 0)) {
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'changeDeviceMesh', responseid: command.responseid, result: 'Permission denied' })); } catch (ex) { } }
return;
}
@@ -3385,7 +3385,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
// Get the node and the rights for this node
parent.GetNodeWithRights(domain, user, command.nodeids[i], function (node, rights, visible) {
// Check we have the rights to delete this device
- if ((rights & MESHRIGHT_MANAGECOMPUTERS) == 0) return;
+ if ((rights & MESHRIGHT_UNINSTALL) == 0) return;
// Delete this node including network interface information, events and timeline
db.Remove(node._id); // Remove node with that id
diff --git a/public/scripts/amt-wsman-0.2.0-min.js b/public/scripts/amt-wsman-0.2.0-min.js
index 293387e7..389c6296 100644
--- a/public/scripts/amt-wsman-0.2.0-min.js
+++ b/public/scripts/amt-wsman-0.2.0-min.js
@@ -1 +1 @@
-var WsmanStackCreateService=function(e,s,r,a,o,t){var p={};function l(e){if(!e)return"";var s=" ";for(var r in e)e.hasOwnProperty(r)&&0===r.indexOf("@")&&(s+=r.substring(1)+'="'+e[r]+'" ');return s}function w(e){if(!e)return"";if("string"==typeof e)return e;if(e.InstanceID)return''+e.InstanceID+" ";var s="";for(var r in e)if(e.hasOwnProperty(r)){if(s+='',e[r].ReferenceParameters){s+="",s+=""+e[r].Address+" "+e[r].ReferenceParameters.ResourceURI+" ";var a=e[r].ReferenceParameters.SelectorSet.Selector;if(Array.isArray(a))for(var o=0;o"+a[o].Value+" ";else s+=""+a.Value+" ";s+=" "}else s+=e[r];s+=""}return s+=""}return p.NextMessageId=1,p.Address="/wsman",p.comm=CreateWsmanComm(e,s,r,a,o,t),p.PerformAjax=function(e,o,s,r,a){null==a&&(a=""),p.comm.PerformAjax('"+e,function(e,s,r){if(200==s){var a=p.ParseWsman(e);a&&null!=a?o(p,a.Header.ResourceURI,a,200,r):o(p,null,{Header:{HttpError:s}},601,r)}else o(p,null,{Header:{HttpError:s}},s,r)},s,r)},p.CancelAllQueries=function(e){p.comm.CancelAllQueries(e)},p.GetNameFromUrl=function(e){var s=e.lastIndexOf("/");return-1==s?e:e.substring(s+1)},p.ExecSubscribe=function(e,s,r,a,o,t,n,l,d,c){var m="",i="";null!=d&&null!=c&&(m="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken "+d+' '+c+" ",i=' '),l=null!=l&&null!=l?""+l+" ":"";var u="http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe "+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous "+w(n)+m+''+r+" "+i+"PT0.000000S ";p.PerformAjax(u+" ",a,o,t,'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:se="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:m="http://x.com"')},p.ExecUnSubscribe=function(e,s,r,a,o){var t="http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous "+w(o)+" ";p.PerformAjax(t+"",s,r,a,'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing"')},p.ExecPut=function(e,s,r,a,o,t){var n="http://schemas.xmlsoap.org/ws/2004/09/transfer/Put"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60.000S "+w(t)+""+function(e,s){if(!e||null==s)return"";var r=p.GetNameFromUrl(e),a="';for(var o in s)if(s.hasOwnProperty(o)&&0!==o.indexOf("__")&&0!==o.indexOf("@")&&void 0!==s[o]&&null!==s[o]&&"function"!=typeof s[o])if("object"==typeof s[o]&&s[o].ReferenceParameters){a+=""+s[o].Address+" "+s[o].ReferenceParameters.ResourceURI+" ";var t=s[o].ReferenceParameters.SelectorSet.Selector;if(Array.isArray(t))for(var n=0;n"+t[n].Value+"";else a+=""+t.Value+" ";a+=" "}else if(Array.isArray(s[o]))for(n=0;n"+s[o][n].toString()+" ";else a+=""+s[o].toString()+" ";return a+=""}(e,s);p.PerformAjax(n+"",r,a,o)},p.ExecCreate=function(e,s,r,a,o,t){var n=p.GetNameFromUrl(e),l="http://schemas.xmlsoap.org/ws/2004/09/transfer/Create"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S "+w(t)+"';for(var d in s)l+=""+s[d]+" ";p.PerformAjax(l+" ",r,a,o)},p.ExecCreateXml=function(e,s,r,a,o){var t=p.GetNameFromUrl(e);p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Create"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60.000S '+s+" ",r,a,o)},p.ExecDelete=function(e,s,r,a,o){var t="http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S "+w(s)+" ";p.PerformAjax(t,r,a,o)},p.ExecGet=function(e,s,r,a){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S
'+r+" ",a,o,t)},p.ExecEnum=function(e,s,r,a){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate"+p.Address+" "+e+" "+p.NextMessageId+++' http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S ',s,r,a)},p.ExecPull=function(e,s,r,a,o){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull"+p.Address+" "+e+" "+p.NextMessageId+++' http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S '+s+" 999 99999 ",r,a,o)},p.ParseWsman=function(s){try{s.childNodes||(s=function(e){{if(window.DOMParser)return(new DOMParser).parseFromString(e,"text/xml");var s=new ActiveXObject("Microsoft.XMLDOM");return s.async=!1,s.loadXML(e),s}}(s));var e,r={Header:{}},a=s.getElementsByTagName("Header")[0];if(!(a=a||s.getElementsByTagName("a:Header")[0]))return null;for(var o=0;o'+e.InstanceID+" ";var s="";for(var r in e)if(e.hasOwnProperty(r)){if(s+='',e[r].ReferenceParameters){s+="",s+=""+e[r].Address+" "+e[r].ReferenceParameters.ResourceURI+" ";var a=e[r].ReferenceParameters.SelectorSet.Selector;if(Array.isArray(a))for(var o=0;o"+a[o].Value+" ";else s+=""+a.Value+" ";s+=" "}else s+=e[r];s+=""}return s+=""}return p.NextMessageId=1,p.Address="/wsman",p.comm=CreateWsmanComm(e,s,r,a,o,t),p.PerformAjax=function(e,o,s,r,a){null==a&&(a=""),p.comm.PerformAjax('"+e,function(e,s,r){if(200==s){var a=p.ParseWsman(e);a&&null!=a?o(p,a.Header.ResourceURI,a,200,r):o(p,null,{Header:{HttpError:s}},601,r)}else o(p,null,{Header:{HttpError:s}},s,r)},s,r)},p.CancelAllQueries=function(e){p.comm.CancelAllQueries(e)},p.GetNameFromUrl=function(e){var s=e.lastIndexOf("/");return-1==s?e:e.substring(s+1)},p.ExecSubscribe=function(e,s,r,a,o,t,n,l,c,d){var m="",i="";null!=c&&null!=d&&(m="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#UsernameToken "+c+' '+d+" ",i=' '),l=null!=l&&null!=l?""+l+" ":"";var u="http://schemas.xmlsoap.org/ws/2004/08/eventing/Subscribe "+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous "+w(n)+m+''+r+" "+i+"PT0.000000S ";p.PerformAjax(u+" ",a,o,t,'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing" xmlns:t="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:se="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:m="http://x.com"')},p.ExecUnSubscribe=function(e,s,r,a,o){var t="http://schemas.xmlsoap.org/ws/2004/08/eventing/Unsubscribe"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous "+w(o)+" ";p.PerformAjax(t+"",s,r,a,'xmlns:e="http://schemas.xmlsoap.org/ws/2004/08/eventing"')},p.ExecPut=function(e,s,r,a,o,t){var n="http://schemas.xmlsoap.org/ws/2004/09/transfer/Put"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60.000S "+w(t)+""+function(e,s){if(!e||null==s)return"";var r=p.GetNameFromUrl(e),a="';for(var o in s)if(s.hasOwnProperty(o)&&0!==o.indexOf("__")&&0!==o.indexOf("@")&&void 0!==s[o]&&null!==s[o]&&"function"!=typeof s[o])if("object"==typeof s[o]&&s[o].ReferenceParameters){a+=""+s[o].Address+" "+s[o].ReferenceParameters.ResourceURI+" ";var t=s[o].ReferenceParameters.SelectorSet.Selector;if(Array.isArray(t))for(var n=0;n"+t[n].Value+"";else a+=""+t.Value+" ";a+=" "}else if(Array.isArray(s[o]))for(n=0;n"+s[o][n].toString()+" ";else a+=""+s[o].toString()+" ";return a+=""}(e,s);p.PerformAjax(n+"",r,a,o)},p.ExecCreate=function(e,s,r,a,o,t){var n=p.GetNameFromUrl(e),l="http://schemas.xmlsoap.org/ws/2004/09/transfer/Create"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S "+w(t)+"';for(var c in s)l+=""+s[c]+" ";p.PerformAjax(l+" ",r,a,o)},p.ExecCreateXml=function(e,s,r,a,o){var t=p.GetNameFromUrl(e);p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Create"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60.000S '+s+" ",r,a,o)},p.ExecDelete=function(e,s,r,a,o){var t="http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S "+w(s)+" ";p.PerformAjax(t,r,a,o)},p.ExecGet=function(e,s,r,a){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/transfer/Get"+p.Address+" "+e+" "+p.NextMessageId+++" http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S '+r+" ",a,o,t)},p.ExecEnum=function(e,s,r,a){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate"+p.Address+" "+e+" "+p.NextMessageId+++' http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S ',s,r,a)},p.ExecPull=function(e,s,r,a,o){p.PerformAjax("http://schemas.xmlsoap.org/ws/2004/09/enumeration/Pull"+p.Address+" "+e+" "+p.NextMessageId+++' http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous PT60S '+s+" 999 99999 ",r,a,o)},p.ParseWsman=function(s){try{s.childNodes||(s=function(e){{if(window.DOMParser)return(new DOMParser).parseFromString(e,"text/xml");var s=new ActiveXObject("Microsoft.XMLDOM");return s.async=!1,s.loadXML(e),s}}(s));var e,r={Header:{}},a=s.getElementsByTagName("Header")[0];if(!(a=a||s.getElementsByTagName("a:Header")[0]))return null;for(var o=0;o27->456"
+ "default.handlebars->27->457"
]
},
{
@@ -21114,7 +21114,7 @@
"zh-chs": "移至設備組",
"zh-cht": "移至設備組",
"xloc": [
- "default.handlebars->27->457"
+ "default.handlebars->27->448"
]
},
{
@@ -23584,7 +23584,7 @@
"default-mobile.handlebars->9->264",
"default.handlebars->27->1605",
"default.handlebars->27->1686",
- "default.handlebars->27->450",
+ "default.handlebars->27->451",
"default.handlebars->27->471",
"default.handlebars->27->731"
]
@@ -24936,7 +24936,7 @@
"zh-chs": "關閉設備電源",
"zh-cht": "關閉設備電源",
"xloc": [
- "default.handlebars->27->455"
+ "default.handlebars->27->456"
]
},
{
@@ -26834,7 +26834,7 @@
"zh-chs": "重置設備",
"zh-cht": "重置設備",
"xloc": [
- "default.handlebars->27->454"
+ "default.handlebars->27->455"
]
},
{
@@ -27195,7 +27195,7 @@
"zh-chs": "运行命令",
"zh-cht": "運行命令",
"xloc": [
- "default.handlebars->27->452"
+ "default.handlebars->27->453"
]
},
{
@@ -27973,7 +27973,7 @@
"zh-chs": "選擇要在所有選定設備上執行的操作。僅在擁有適當權限的情況下才能執行操作。",
"zh-cht": "選擇要在所有選定設備上執行的操作。僅在擁有適當權限的情況下才能執行操作。",
"xloc": [
- "default.handlebars->27->449"
+ "default.handlebars->27->450"
]
},
{
@@ -29734,7 +29734,7 @@
"zh-chs": "睡眠裝置",
"zh-cht": "睡眠裝置",
"xloc": [
- "default.handlebars->27->453"
+ "default.handlebars->27->454"
]
},
{
@@ -32947,11 +32947,16 @@
"zh-cht": "卸載代理",
"xloc": [
"default-mobile.handlebars->9->426",
- "default.handlebars->27->1426",
- "default.handlebars->27->448",
+ "default.handlebars->27->449",
"default.handlebars->27->730"
]
},
+ {
+ "en": "Uninstall Agent / Delete Device",
+ "xloc": [
+ "default.handlebars->27->1426"
+ ]
+ },
{
"cs": "Odinstalovat agenta",
"de": "Agenten deinstallieren",
@@ -34703,7 +34708,7 @@
"zh-chs": "喚醒設備",
"zh-cht": "喚醒設備",
"xloc": [
- "default.handlebars->27->451"
+ "default.handlebars->27->452"
]
},
{
diff --git a/views/default-mobile.handlebars b/views/default-mobile.handlebars
index 3a15c40e..740c333a 100644
--- a/views/default-mobile.handlebars
+++ b/views/default-mobile.handlebars
@@ -2630,7 +2630,7 @@
// Show bottom buttons
x = '';
//if (mesh.mtype == 2) x += '
Interfaces ';
//if (xxmap != null) x += '
Location ';
diff --git a/views/default.handlebars b/views/default.handlebars
index 402acec2..204c2032 100644
--- a/views/default.handlebars
+++ b/views/default.handlebars
@@ -4375,13 +4375,13 @@
// Display the "Uninstall Agent" option if allowed and we selected connected devices.
for (var i in nodeids) {
- var node = getNodeFromId(nodeids[i]);
- var rights = GetNodeRights(node);
- if (((node.conn & 1) != 0) && ((rights & 32768) != 0)) { addedOptions += '
' + "Uninstall Agent" + ' '; break; }
+ var node = getNodeFromId(nodeids[i]), rights = GetNodeRights(node), added = 0;
+ if ((rights & 1) && ((added & 2) == 0)) { added += 2; addedOptions += '
' + "Move to device group" + ' '; }
+ if (((node.conn & 1) != 0) && ((rights & 0x8000) != 0) && ((added & 1) == 0)) { added += 1; addedOptions += '
' + "Uninstall Agent" + ' '; }
}
var x = "Select an operation to perform on all selected devices. Actions will be performed only with proper rights." + '
';
- x += addHtmlValue("Operation", '
' + "Wake-up devices" + ' ' + "Run commands" + ' ' + "Sleep devices" + ' ' + "Reset devices" + ' ' + "Power off devices" + ' ' + "Export device information" + ' ' + "Move to device group" + ' ' + '' + "Edit tags" + ' ' + "Device notification" + ' ' + addedOptions + '' + "Delete devices" + ' ');
+ x += addHtmlValue("Operation", '
' + "Wake-up devices" + ' ' + "Run commands" + ' ' + "Sleep devices" + ' ' + "Reset devices" + ' ' + "Power off devices" + ' ' + "Export device information" + ' ' + '' + "Edit tags" + ' ' + "Device notification" + ' ' + addedOptions + '' + "Delete devices" + ' ');
setDialogMode(2, "Group Action", 3, groupActionFunctionEx, x);
}
@@ -5689,9 +5689,11 @@
// Show bottom buttons
x = '
';
- if ((meshrights & 4) != 0) {
+ if ((meshrights & 1) != 0) { // MESHRIGHT_EDITMESH
// TODO: Show change group only if there is another mesh of the same type.
x += '
' + "Change Group" + ' ';
+ }
+ if ((meshrights & 0x8000) != 0) { // MESHRIGHT_UNINSTALL
x += '
' + "Delete Device" + ' ';
}
x += '
';
@@ -9689,7 +9691,7 @@
x += ' ' + "Edit Device Notes" + ' ';
x += ' ' + "Show Only Own Events" + ' ';
x += ' ' + "Chat & Notify" + ' ';
- x += ' ' + "Uninstall Agent" + ' ';
+ x += ' ' + "Uninstall Agent / Delete Device" + ' ';
x += ' ' + "Lock Account Settings" + ' ';
x += '
';