MeshCtrl will now fail is duplicate device groups are found.
Ylian Saint-Hilaire committed
Apr 7, 2020 at 16:37 UTC
5a3802301d4432af8fad1888faed70b9ab71fc39
1 file changed
+10
-4
meshuser.js
+10
-4
@@ -3126,15 +3126,18 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3126
}
3127
case 'inviteAgent':
3128
{
3129
+ var err = null, mesh = null;
3130
+
3131
// Resolve the device group name if needed
3132
if ((typeof command.meshname == 'string') && (command.meshid == null)) {
3133
for (var i in parent.meshes) {
3134
var m = parent.meshes[i];
3133
- if ((m.mtype == 2) && (m.name == command.meshname) && parent.IsMeshViewable(user, m)) { command.meshid = m._id; break; }
3135
+ if ((m.mtype == 2) && (m.name == command.meshname) && parent.IsMeshViewable(user, m)) {
3136
+ if (command.meshid == null) { command.meshid = m._id; } else { err = 'Duplicate device groups found'; }
3137
+ }
3138
}
3139
}
3140
3137
- var err = null, mesh = null;
3141
try {
3142
if ((parent.parent.mailserver == null) || (args.lanonly == true)) { err = 'Unsupported feature'; } // This operation requires the email server
3143
else if ((parent.parent.certificates.CommonName == null) || (parent.parent.certificates.CommonName.indexOf('.') == -1)) { err = 'Unsupported feature'; } // Server name must be configured
@@ -3581,15 +3584,18 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3584
break;
3585
}
3586
case 'createInviteLink': {
3587
+ var err = null;
3588
+
3589
// Resolve the device group name if needed
3590
if ((typeof command.meshname == 'string') && (command.meshid == null)) {
3591
for (var i in parent.meshes) {
3592
var m = parent.meshes[i];
3588
- if ((m.mtype == 2) && (m.name == command.meshname) && parent.IsMeshViewable(user, m)) { command.meshid = m._id; break; }
3593
+ if ((m.mtype == 2) && (m.name == command.meshname) && parent.IsMeshViewable(user, m)) {
3594
+ if (command.meshid == null) { command.meshid = m._id; } else { err = 'Duplicate device groups found'; }
3595
+ }
3596
}
3597
}
3598
3592
- var err = null;
3599
if (common.validateString(command.meshid, 8, 128) == false) { err = 'Invalid group id'; } // Check the meshid
3600
else if (common.validateInt(command.expire, 0, 99999) == false) { err = 'Invalid expire time'; } // Check the expire time in hours
3601
else if (common.validateInt(command.flags, 0, 256) == false) { err = 'Invalid flags'; } // Check the flags