Fixed TCP/UDP server relay problem.
Ylian Saint-Hilaire committed
Apr 13, 2020 at 09:36 UTC
d4ee38842bd7e5dfa26663796009aadd15104939
3 files changed
+44
-53
meshrelay.js
+25
-33
@@ -80,44 +80,36 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie
80
var agent = parent.wsagents[command.nodeid];
81
if (agent != null) {
82
// Check if we have permission to send a message to that node
83
- parent.GetNodeWithRights(domain, user, agent.dbNodeKey, function (node, rights, visible) {
84
- mesh = parent.meshes[agent.dbMeshKey];
85
- if ((node != null) && (rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
86
- if (ws.sessionId) { command.sessionid = ws.sessionId; } // Set the session id, required for responses.
87
- command.rights = rights.rights; // Add user rights flags to the message
88
- command.consent = 0;
89
- if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
90
- if (typeof mesh.consent == 'number') { command.consent |= mesh.consent; } // Add device group user consent
91
- if (typeof node.consent == 'number') { command.consent |= node.consent; } // Add node user consent
92
- if (typeof user.consent == 'number') { command.consent |= user.consent; } // Add user consent
93
- command.username = user.name; // Add user name
94
- if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
95
- delete command.nodeid; // Remove the nodeid since it's implyed.
96
- agent.send(JSON.stringify(command));
97
- return true;
98
- }
99
- });
83
+ rights = parent.GetNodeRights(user, agent.dbMeshKey, agent.dbNodeKey);
84
+ mesh = parent.meshes[agent.dbMeshKey];
85
+ if ((rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
86
+ if (ws.sessionId) { command.sessionid = ws.sessionId; } // Set the session id, required for responses.
87
+ command.rights = rights.rights; // Add user rights flags to the message
88
+ command.consent = mesh.consent; // Add user consent
89
+ if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
90
+ command.username = user.name; // Add user name
91
+ if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
92
+ delete command.nodeid; // Remove the nodeid since it's implyed.
93
+ agent.send(JSON.stringify(command));
94
+ return true;
95
+ }
96
} else {
97
// Check if a peer server is connected to this agent
98
var routing = parent.parent.GetRoutingServerId(command.nodeid, 1); // 1 = MeshAgent routing type
99
if (routing != null) {
100
// Check if we have permission to send a message to that node
105
- parent.GetNodeWithRights(domain, user, agent.dbNodeKey, function (node, rights, visible) {
106
- mesh = parent.meshes[routing.meshid];
107
- if ((node != null) && (rights != null) && (mesh != null) || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
108
- if (ws.sessionId) { command.fromSessionid = ws.sessionId; } // Set the session id, required for responses.
109
- command.rights = rights.rights; // Add user rights flags to the message
110
- command.consent = 0;
111
- if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
112
- if (typeof mesh.consent == 'number') { command.consent |= mesh.consent; } // Add device group user consent
113
- if (typeof node.consent == 'number') { command.consent |= node.consent; } // Add node user consent
114
- if (typeof user.consent == 'number') { command.consent |= user.consent; } // Add user consent
115
- command.username = user.name; // Add user name
116
- if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
117
- parent.parent.multiServer.DispatchMessageSingleServer(command, routing.serverid);
118
- return true;
119
- }
120
- });
101
+ rights = parent.GetNodeRights(user, routing.meshid, command.nodeid);
102
+ mesh = parent.meshes[routing.meshid];
103
+ if (rights != null || ((rights & 16) != 0)) { // TODO: 16 is console permission, may need more gradular permission checking
104
+ if (ws.sessionId) { command.fromSessionid = ws.sessionId; } // Set the session id, required for responses.
105
+ command.rights = rights.rights; // Add user rights flags to the message
106
+ command.consent = mesh.consent; // Add user consent
107
+ if (typeof domain.userconsentflags == 'number') { command.consent |= domain.userconsentflags; } // Add server required consent flags
108
+ command.username = user.name; // Add user name
109
+ if (typeof domain.desktopprivacybartext == 'string') { command.privacybartext = domain.desktopprivacybartext; } // Privacy bar text
110
+ parent.parent.multiServer.DispatchMessageSingleServer(command, routing.serverid);
111
+ return true;
112
+ }
113
}
114
}
115
}
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.5.1-q",
3
+ "version": "0.5.1-r",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",
views/default.handlebars
+18
-19
@@ -2715,7 +2715,7 @@
2715
}
2716
}
2717
2718
- // Go tot he correct starting view page
2718
+ // Go to the correct starting view page
2719
function gotoStartViewPage() {
2720
if (xxcurrentView != -1) return;
2721
if ('{{currentNode}}' != '') {
@@ -2736,7 +2736,7 @@
2736
go(parseInt('{{viewmode}}'));
2737
goBackStack.push(4);
2738
} else if (args.gotougrp != null) {
2739
- if (usergroups['ugrp/' + domain + '/' + args.gotougrp] == null) return; // This user group is not loaded yet
2739
+ if ((usergroups == null) || usergroups['ugrp/' + domain + '/' + args.gotougrp] == null) return; // This user group is not loaded yet
2740
gotoUserGroup('ugrp/' + domain + '/' + args.gotougrp);
2741
go(parseInt('{{viewmode}}'));
2742
goBackStack.push(50);
@@ -4812,15 +4812,7 @@
4812
4813
// Attribute: Host
4814
if ((features & 1) == 0) { // If not WAN-only, local hostname is in use
4815
- if ((meshrights & 4) != 0) {
4816
- if (node.host) {
4817
- x += addDeviceAttribute("Hostname", '<span onclick=showEditNodeValueDialog(1) style=cursor:pointer>' + EscapeHtml(node.host) + '</span>');
4818
- } else {
4819
- x += addDeviceAttribute("Hostname", '<span onclick=showEditNodeValueDialog(1) style=cursor:pointer><i>' + "None" + '</i></span>');
4820
- }
4821
- } else {
4822
- x += addDeviceAttribute("Hostname", EscapeHtml(node.host));
4823
- }
4815
+ x += addDeviceAttribute("Hostname", addLinkConditional('<span onclick=showEditNodeValueDialog(1) style=cursor:pointer>' + (node.host?EscapeHtml(node.host):('<i>' + "None" + '</i>')) + '</span>', 'showEditNodeValueDialog(1)', meshrights & 4));
4816
}
4817
4818
// Attribute: Description
@@ -8583,7 +8575,7 @@
8575
var y = '';
8576
for (var i in meshes) { if ((currentUserGroup.links == null) || (currentUserGroup.links[i] == null)) { y += '<option value=' + encodeURIComponent(i) + '>' + EscapeHtml(meshes[i].name) + '</option>'; } }
8577
x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog() id=dp2groupid style=width:100%>' + y + '</select></div>');
8586
- } else if (userid === 4) {
8578
+ } else if ((userid === 4) || (userid == 7)) {
8579
var y = '', selectedMeshId = null, selectedNode = null;
8580
if (selected != null) { selectedNode = getNodeFromId(decodeURIComponent(selected)); if (selectedNode != null) { selectedMeshId = selectedNode.meshid; } }
8581
for (var i in meshes) {
@@ -8591,10 +8583,10 @@
8583
if (selectedMeshId == null) { selectedMeshId = meshes[i]._id; } y += '<option value=' + encodeURIComponent(meshes[i]._id) + ((selectedMeshId == meshes[i]._id)?' selected':' ') + '>' + EscapeHtml(meshes[i].name) + '</option>';
8584
}
8585
}
8594
- x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20changeMeshAddMeshUserDialog(4) id=dp2meshid style=width:100%>' + y + '</select></div>');
8586
+ x += addHtmlValue("Device Group", '<div style=width:230px;margin:0;padding:0><select onchange=p20changeMeshAddMeshUserDialog(' + userid + ') id=dp2meshid style=width:100%>' + y + '</select></div>');
8587
y = '';
8588
for (var i in nodes) { if (nodes[i].meshid == selectedMeshId) { y += '<option value=' + encodeURIComponent(nodes[i]._id) + ((selectedNode == nodes[i])?' selected':' ') + '>' + EscapeHtml(nodes[i].name) + '</option>'; } }
8597
- x += addHtmlValue("Device", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog(4) id=dp2nodeid style=width:100%>' + y + '</select></div>');
8589
+ x += addHtmlValue("Device", '<div style=width:230px;margin:0;padding:0><select onchange=p20validateAddMeshUserDialog(' + userid + ') id=dp2nodeid style=width:100%>' + y + '</select></div>');
8590
} else {
8591
userid = decodeURIComponent(userid);
8592
var uname = userid.split('/')[2];
@@ -8608,7 +8600,7 @@
8600
}
8601
}
8602
x += '<div style="height:120px;overflow-y:scroll;border:1px solid gray">';
8611
- if ((userid != 4) && (userid != 5) && (userid != 6)) {
8603
+ if ((userid != 4) && (userid != 5) && (userid != 6) && (userid != 7)) {
8604
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20fulladmin>' + "Full Administrator" + '</label><br>';
8605
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20editmesh>' + "Edit Device Group" + '</label><br>';
8606
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20manageusers>' + "Manage Device Group Users" + '</label><br>';
@@ -8642,6 +8634,11 @@
8634
setDialogMode(2, (selected == null)?"Add Device Permissions":"Edit Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8635
QE('dp2meshid', selected == null);
8636
QE('dp2nodeid', selected == null);
8637
+ } else if (userid === 7) {
8638
+ console.log('a1');
8639
+ setDialogMode(2, (selected == null)?"Add Device Permissions":"Edit Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8640
+ QE('dp2meshid', selected == null);
8641
+ QE('dp2nodeid', selected == null);
8642
} else if (userid === 5) {
8643
setDialogMode(2, selected?"Edit User Device Permissions":"Add User Device Permissions", 3, p20showAddMeshUserDialogEx, x, userid);
8644
if (selected != null) {
@@ -8742,6 +8739,7 @@
8739
}
8740
8741
function p20validateAddMeshUserDialog(updateId) {
8742
+ console.log('p20validateAddMeshUserDialog', updateId);
8743
var ok = true;
8744
8745
if (updateId === 4) {
@@ -8871,6 +8869,9 @@
8869
} else if (t === 6) {
8870
var ugrpid = decodeURIComponent(Q('dp2groupid').value);
8871
if (currentNode != null) { meshserver.send({ action: 'adddeviceuser', nodeid: currentNode._id, nodename: currentNode.name, userids: [ ugrpid ], rights: meshadmin }); }
8872
+ } else if (t === 7) {
8873
+ var nodeid = decodeURIComponent(Q('dp2nodeid').value), node = getNodeFromId(nodeid);
8874
+ if (node != null) { meshserver.send({ action: 'adddeviceuser', nodeid: nodeid, nodename: node.name, userids: [ currentGroup._id ], rights: meshadmin }); }
8875
} else {
8876
if (t == null) {
8877
var users = Q('dp20username').value.split(','), users2 = [];
@@ -10180,10 +10181,8 @@
10181
x += '</tbody></table>';
10182
10183
count = 1;
10183
- //var deviceGroupCount = 0, newDeviceGroup = false;
10184
- //for (var i in meshes) { deviceGroupCount++; if ((currentUserGroup.links == null) || (currentUserGroup.links[i] == null)) { newDeviceGroup = true; } }
10185
- //if ((deviceGroupCount > 0) && (newDeviceGroup)) { x += '<a href=# onclick="return p20showAddMeshUserDialog(3)" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Device Group" + '</a>'; }
10186
- x += '<br /><table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:left;width:430px>' + "Common Devices" + '</th><th scope=col style=text-align:left></th></tr>';
10184
+ x += '<br /><a href=# onclick="return p20showAddMeshUserDialog(7)" style=cursor:pointer;margin-right:10px><img src=images/icon-addnew.png border=0 height=12 width=12> ' + "Add Device" + '</a>';
10185
+ x += '<table style="color:black;background-color:#EEE;border-color:#AAA;border-width:1px;border-style:solid;border-collapse:collapse" border=0 cellpadding=2 cellspacing=0 width=100%><tbody><tr style=background-color:#AAAAAA;font-weight:bold><th scope=col style=text-align:left;width:430px>' + "Common Devices" + '</th><th scope=col style=text-align:left></th></tr>';
10186
if (currentUserGroup.links) {
10187
for (var i in currentUserGroup.links) {
10188
if (i.startsWith('node/')) {