mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-03-09 15:40:18 +00:00 
			
		
		
		
	Improved event translation, #3516
This commit is contained in:
		
							parent
							
								
									0d457bb6e5
								
							
						
					
					
						commit
						9c0e3bd4c5
					
				
					 5 changed files with 690 additions and 626 deletions
				
			
		
							
								
								
									
										25
									
								
								meshuser.js
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								meshuser.js
									
										
									
									
									
								
							|  | @ -2097,18 +2097,20 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                     if ((parent.GetMeshRights(user, mesh) & MESHRIGHT_EDITMESH) == 0) return; | ||||
|                     if ((command.meshid.split('/').length != 3) || (command.meshid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
 | ||||
| 
 | ||||
|                     if ((common.validateString(command.meshname, 1, 128) == true) && (command.meshname != mesh.name)) { change = 'Group name changed from "' + mesh.name + '" to "' + command.meshname + '"'; mesh.name = command.meshname; } | ||||
|                     if ((common.validateString(command.desc, 0, 1024) == true) && (command.desc != mesh.desc)) { if (change != '') change += ' and description changed'; else change += 'Group "' + mesh.name + '" description changed'; mesh.desc = command.desc; } | ||||
|                     if ((common.validateInt(command.flags) == true) && (command.flags != mesh.flags)) { if (change != '') change += ' and flags changed'; else change += 'Group "' + mesh.name + '" flags changed'; mesh.flags = command.flags; } | ||||
|                     if ((common.validateInt(command.consent) == true) && (command.consent != mesh.consent)) { if (change != '') change += ' and consent changed'; else change += 'Group "' + mesh.name + '" consent changed'; mesh.consent = command.consent; } | ||||
|                     if ((common.validateInt(command.expireDevs, 0, 2000) == true) && (command.expireDevs != mesh.expireDevs)) { if (change != '') change += ' and auto-remove changed'; else change += 'Group "' + mesh.name + '" auto-remove changed'; if (command.expireDevs == 0) { delete mesh.expireDevs; } else { mesh.expireDevs = command.expireDevs; } } | ||||
|                     var changesids = []; | ||||
|                     if ((common.validateString(command.meshname, 1, 128) == true) && (command.meshname != mesh.name)) { change = 'Device group name changed from "' + mesh.name + '" to "' + command.meshname + '"'; changesids.push(1); mesh.name = command.meshname; } | ||||
|                     if ((common.validateString(command.desc, 0, 1024) == true) && (command.desc != mesh.desc)) { if (change != '') change += ' and description changed'; else change += 'Device group "' + mesh.name + '" description changed'; changesids.push(2); mesh.desc = command.desc; } | ||||
|                     if ((common.validateInt(command.flags) == true) && (command.flags != mesh.flags)) { if (change != '') change += ' and flags changed'; else change += 'Device group "' + mesh.name + '" flags changed'; changesids.push(3); mesh.flags = command.flags; } | ||||
|                     if ((common.validateInt(command.consent) == true) && (command.consent != mesh.consent)) { if (change != '') change += ' and consent changed'; else change += 'Device group "' + mesh.name + '" consent changed'; changesids.push(4); mesh.consent = command.consent; } | ||||
|                     if ((common.validateInt(command.expireDevs, 0, 2000) == true) && (command.expireDevs != mesh.expireDevs)) { if (change != '') change += ' and auto-remove changed'; else change += 'Device group "' + mesh.name + '" auto-remove changed'; changesids.push(5); if (command.expireDevs == 0) { delete mesh.expireDevs; } else { mesh.expireDevs = command.expireDevs; } } | ||||
| 
 | ||||
|                     // See if we need to change device group invitation codes
 | ||||
|                     if (mesh.mtype == 2) { | ||||
|                         if (command.invite === '*') { | ||||
|                             // Clear invite codes
 | ||||
|                             if (mesh.invite != null) { delete mesh.invite; } | ||||
|                             if (change != '') { change += ' and invite code changed'; } else { change += 'Group "' + mesh.name + '" invite code changed'; } | ||||
|                             if (change != '') { change += ' and invite code changed'; } else { change += 'Device group "' + mesh.name + '" invite code changed'; } | ||||
|                             changesids.push(6); | ||||
|                         } else if ((typeof command.invite == 'object') && (Array.isArray(command.invite.codes)) && (typeof command.invite.flags == 'number')) { | ||||
|                             // Set invite codes
 | ||||
|                             if ((mesh.invite == null) || (mesh.invite.codes != command.invite.codes) || (mesh.invite.flags != command.invite.flags)) { | ||||
|  | @ -2125,14 +2127,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                                     return; | ||||
|                                 } | ||||
|                                 mesh.invite = { codes: command.invite.codes, flags: command.invite.flags }; | ||||
|                                 if (change != '') { change += ' and invite code changed'; } else { change += 'Group "' + mesh.name + '" invite code changed'; } | ||||
|                                 if (change != '') { change += ' and invite code changed'; } else { change += 'Device group "' + mesh.name + '" invite code changed'; } | ||||
|                                 changesids.push(6); | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
| 
 | ||||
|                     if (change != '') { | ||||
|                         db.Set(mesh); | ||||
|                         var event = { etype: 'mesh', userid: user._id, username: user.name, meshid: mesh._id, name: mesh.name, mtype: mesh.mtype, desc: mesh.desc, flags: mesh.flags, consent: mesh.consent, action: 'meshchange', links: mesh.links, msg: change, domain: domain.id, invite: mesh.invite, expireDevs: command.expireDevs }; | ||||
|                         var event = { etype: 'mesh', userid: user._id, username: user.name, meshid: mesh._id, name: mesh.name, mtype: mesh.mtype, desc: mesh.desc, flags: mesh.flags, consent: mesh.consent, action: 'meshchange', links: mesh.links, msgid: 142, msgArgs: [ mesh.name, changesids ], msg: change, domain: domain.id, invite: mesh.invite, expireDevs: command.expireDevs }; | ||||
|                         if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
 | ||||
|                         parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event); | ||||
|                     } | ||||
|  | @ -2256,7 +2259,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                     } | ||||
| 
 | ||||
|                     mesh = parent.meshes[command.meshid]; | ||||
|                     change = ''; | ||||
|                     if (mesh) { | ||||
|                         // Check if this user has rights to do this
 | ||||
|                         if ((parent.GetMeshRights(user, mesh) & MESHRIGHT_EDITMESH) == 0) return; | ||||
|  | @ -2265,7 +2267,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                         // TODO: Check if this is a change from the existing policy
 | ||||
| 
 | ||||
|                         // Perform the Intel AMT policy change
 | ||||
|                         change = 'Intel AMT policy change'; | ||||
|                         var amtpolicy = { type: command.amtpolicy.type }; | ||||
|                         if ((command.amtpolicy.type === 2) || (command.amtpolicy.type === 3)) { | ||||
|                             amtpolicy = { type: command.amtpolicy.type, badpass: command.amtpolicy.badpass, cirasetup: command.amtpolicy.cirasetup }; | ||||
|  | @ -2277,7 +2278,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                         db.Set(mesh); | ||||
|                         var amtpolicy2 = Object.assign({}, amtpolicy); // Shallow clone
 | ||||
|                         if (amtpolicy2.password != null) { amtpolicy2.password = 1; } | ||||
|                         var event = { etype: 'mesh', userid: user._id, username: user.name, meshid: mesh._id, amt: amtpolicy2, action: 'meshchange', links: mesh.links, msg: change, domain: domain.id, invite: mesh.invite }; | ||||
|                         var event = { etype: 'mesh', userid: user._id, username: user.name, meshid: mesh._id, amt: amtpolicy2, action: 'meshchange', links: mesh.links, msgid: 141, msg: "Intel(r) AMT policy change", domain: domain.id, invite: mesh.invite }; | ||||
|                         if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
 | ||||
|                         parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event); | ||||
| 
 | ||||
|  | @ -2963,6 +2964,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use | |||
|                             // Event the node change. Only do this if the database will not do it.
 | ||||
|                             event.msg = 'Changed device ' + node.name + ' from group ' + mesh.name + ': ' + changes.join(', '); | ||||
|                             event.node = parent.CloneSafeNode(node); | ||||
|                             event.msgid = 140; | ||||
|                             event.msgArgs = [ node.name, mesh.name, changes.join(', ') ]; | ||||
|                             if (amtchange == 1) { event.amtchange = 1; } // This will give a hint to the AMT Manager to reconnect using new AMT credentials
 | ||||
|                             if (command.rdpport == 3389) { event.node.rdpport = 3389; } | ||||
|                             if (command.rfbport == 5900) { event.node.rfbport = 5900; } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue