From b2d9dc5f8748c4f97e42244502ded1f56c329000 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 25 Nov 2018 12:59:42 -0800 Subject: [PATCH] Workaround a race condition on meshagent sending coreinfo messages. --- agents/MeshAgentOSXPackager.zip | Bin 596967 -> 596971 bytes agents/meshcore.js | 109 ++++++++++++++++---------------- meshagent.js | 2 +- package.json | 2 +- views/default.handlebars | 3 +- 5 files changed, 57 insertions(+), 59 deletions(-) diff --git a/agents/MeshAgentOSXPackager.zip b/agents/MeshAgentOSXPackager.zip index e21ec2db6ad259ccdb09a8d09539739ae27d0a62..5b713d6a3d8233ed64d0aa32b168c425fb88c677 100644 GIT binary patch delta 292 zcmaF9UFG$5m4+6^7N!>F7M2#)7Pc1lEgZLgi~On0^JSXi!1MdeZ$++8 zNuHZCp;sVElK-gTufz@Onw!&@cl+)BvEwfH!IfVptmm8@?B?3^F7M2#)7Pc1lEgZLg3roc0`9{Y)?O)2kz>vhqz@WguFnxkF zr{eVZf2_;5@BG8DO^z2u&GZ^+PDee44@{Q>YOXNef59af2&7^B0B=?{ph*k{Kqx2A Lz_9rb2apE 0) { - obj.borderManager.Start(obj.loggedInUsers[0]); + if (meshCoreObj.users.length > 0) { + obj.borderManager.Start(meshCoreObj.users[0]); response = 'Border blinking is on.'; } else { response = 'Cannot turn on border blinking, no logged in users.'; @@ -946,11 +945,10 @@ function createMeshCore(agent) { } break; */ - case 'users': - { - if (obj.loggedInUsers == null) { response = 'Active users are unknown.'; } else { response = 'Active Users: ' + obj.loggedInUsers.join(', ') + '.'; } - } + case 'users': { + if (meshCoreObj.users == null) { response = 'Active users are unknown.'; } else { response = 'Active Users: ' + meshCoreObj.users.join(', ') + '.'; } break; + } case 'toast': { if (process.platform == 'win32') { if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else { @@ -1023,9 +1021,9 @@ function createMeshCore(agent) { break; } case 'info': { // Return information about the agent and agent core module - response = 'Current Core: ' + obj.meshCoreInfo + '.\r\nAgent Time: ' + Date() + '.\r\nUser Rights: 0x' + rights.toString(16) + '.\r\nPlatform: ' + process.platform + '.\r\nCapabilities: ' + obj.meshCoreCapabilities + '.\r\nServer URL: ' + mesh.ServerUrl + '.'; + response = 'Current Core: ' + meshCoreObj.value + '.\r\nAgent Time: ' + Date() + '.\r\nUser Rights: 0x' + rights.toString(16) + '.\r\nPlatform: ' + process.platform + '.\r\nCapabilities: ' + meshCoreObj.caps + '.\r\nServer URL: ' + mesh.ServerUrl + '.'; if (amtLmsState >= 0) { response += '\r\nBuilt-in LMS: ' + ['Disabled', 'Connecting..', 'Connected'][amtLmsState] + '.'; } - if (osDesc) { response += '\r\nOS: ' + osDesc + '.'; } + if (meshCoreObj.osdesc) { response += '\r\nOS: ' + meshCoreObj.osdesc + '.'; } response += '\r\nModules: ' + addedModules.join(', ') + '.'; response += '\r\nServer Connection: ' + mesh.isControlChannelConnected + ', State: ' + meshServerConnectionState + '.'; response += '\r\lastMeInfo: ' + lastMeInfo + '.'; @@ -1048,18 +1046,20 @@ function createMeshCore(agent) { if (args['_'].length == 0) { response = 'Proper usage: sendcaps (number)'; // Display correct command usage } else { - var flags = { "action": "coreinfo", "value": obj.meshCoreInfo, "caps": parseInt(args['_'][0]) }; - mesh.SendCommand(flags); - response = JSON.stringify(flags); + meshCoreObj.caps = parseInt(args['_'][0]); + mesh.SendCommand(meshCoreObj); + response = JSON.stringify(meshCoreObj); } break; } case 'sendosdesc': { // Send OS description - var os = osDesc; - if (args['_'].length > 0) { os = args['_'][0]; } - var flags = { "action": "coreinfo", "value": obj.meshCoreInfo, "osdesc": os }; - mesh.SendCommand(flags); - response = JSON.stringify(flags); + if (args['_'].length > 0) { + meshCoreObj.osdesc = args['_'][0]; + mesh.SendCommand(meshCoreObj); + response = JSON.stringify(meshCoreObj); + } else { + response = 'Proper usage: sendosdesc [os description]'; // Display correct command usage + } break; } case 'args': { // Displays parsed command arguments @@ -1362,17 +1362,12 @@ function createMeshCore(agent) { var oldNodeId = db.Get('OldNodeId'); if (oldNodeId != null) { mesh.SendCommand({ action: 'mc1migration', oldnodeid: oldNodeId }); } - // Update the server with basic info - var r = { "action": "coreinfo", "value": obj.meshCoreInfo, "caps": obj.meshCoreCapabilities }; - if (osDesc != null) { r.osdesc = osDesc; } - mesh.SendCommand(r); + // Update the server with basic info, logged in users and more. + mesh.SendCommand(meshCoreObj); // Send SMBios tables if present if (SMBiosTablesRaw != null) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); } - // Update list of logged in users - if (obj.loggedInUsers != null) { mesh.SendCommand({ "action": "coreinfo", "v": { "users": obj.loggedInUsers } }); } - // Update the server on more advanced stuff, like Intel ME and Network Settings meInfoStr = null; sendPeriodicServerUpdate(); @@ -1410,8 +1405,12 @@ function createMeshCore(agent) { if (meinfo.OsHostname) { intelamt.host = meinfo.OsHostname; p = true; } if (meinfo.UUID) { intelamt.uuid = meinfo.UUID; p = true; } if (p == true) { - var meInfoStr = JSON.stringify({ "action": "coreinfo", "value": obj.meshCoreInfo, "intelamt": intelamt }); - if (meInfoStr != lastMeInfo) { mesh.SendCommand(meInfoStr); lastMeInfo = meInfoStr; } + var meInfoStr = JSON.stringify(intelamt); + if (meInfoStr != lastMeInfo) { + meshCoreObj.intelamt = intelamt; + mesh.SendCommand(meshCoreObj); + lastMeInfo = meInfoStr; + } } } catch (ex) { } }); @@ -1492,8 +1491,8 @@ function createMeshCore(agent) { var un = a[i].Domain ? (a[i].Domain + '\\' + a[i].Username) : (a[i].Username); if (u.indexOf(un) == -1) { u.push(un); } // Only push users in the list once. } - obj.loggedInUsers = u; - if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "coreinfo", "users": u }); } + meshCoreObj.users = u; + mesh.SendCommand(meshCoreObj); }); }); userSession.emit('changed'); diff --git a/meshagent.js b/meshagent.js index f779cf50..f662a8d6 100644 --- a/meshagent.js +++ b/meshagent.js @@ -602,7 +602,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if (mesh == null) return; // Get the node and change it if needed - obj.db.Get(obj.dbNodeKey, function (err, nodes) { + obj.db.Get(obj.dbNodeKey, function (err, nodes) { // TODO: THIS IS A BIG RACE CONDITION HERE, WE NEED TO FIX THAT. If this call is made twice at the same time on the same device, data will be missed. if (nodes.length != 1) return; var device = nodes[0]; if (device.agent) { diff --git a/package.json b/package.json index ebe26c06..550b71d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.2.3-c", + "version": "0.2.3-e", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index c2812e68..ad19207d 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1937,8 +1937,7 @@ // If a device is no longer viewed, disconnect it. if (multiDesktop[i].xxdelete == true) { multiDesktop[i].Stop(); delete multiDesktop[i]; } else if (debugmode && multiDesktop[i].m && multiDesktop[i].m.onScreenSizeChange) { - // Adjust screen size change (JOKO) - This is not good. - multiDesktop[i].m.onScreenSizeChange(); + mdeskAdjust(multiDesktop[i].m, multiDesktop[i].m.ScreenWidth, multiDesktop[i].m.ScreenHeight, multiDesktop[i].m.CanvasId); // Adjust screen size change } } deskAdjust();