mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-24 06:05:53 -05:00
Workaround a race condition on meshagent sending coreinfo messages.
This commit is contained in:
parent
de486bb02a
commit
b2d9dc5f87
Binary file not shown.
@ -58,9 +58,10 @@ function createMeshCore(agent) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// MeshAgent JavaScript Core Module. This code is sent to and running on the mesh agent.
|
// MeshAgent JavaScript Core Module. This code is sent to and running on the mesh agent.
|
||||||
obj.meshCoreInfo = "MeshCore v6";
|
var meshCoreObj = { "action": "coreinfo", "value": "MeshCore v6", "caps": 14 }; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript
|
||||||
obj.meshCoreCapabilities = 14; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript
|
|
||||||
obj.loggedInUsers = null;
|
// Get the operating system description string
|
||||||
|
try { require('os').name().then(function (v) { meshCoreObj.osdesc = v; }); } catch (ex) { }
|
||||||
|
|
||||||
var meshServerConnectionState = 0;
|
var meshServerConnectionState = 0;
|
||||||
var tunnels = {};
|
var tunnels = {};
|
||||||
@ -90,19 +91,15 @@ function createMeshCore(agent) {
|
|||||||
childProcess = require('child_process');
|
childProcess = require('child_process');
|
||||||
if (mesh.hasKVM == 1) { // if the agent is compiled with KVM support
|
if (mesh.hasKVM == 1) { // if the agent is compiled with KVM support
|
||||||
// Check if this computer supports a desktop
|
// Check if this computer supports a desktop
|
||||||
try { if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support)) { obj.meshCoreCapabilities |= 1; } } catch (ex) { }
|
try { if ((process.platform == 'win32') || (process.platform == 'darwin') || (require('monitor-info').kvm_x11_support)) { meshCoreObj.caps |= 1; } } catch (ex) { }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Running in nodejs
|
// Running in nodejs
|
||||||
obj.meshCoreInfo += '-NodeJS';
|
meshCoreObj.value += '-NodeJS';
|
||||||
obj.meshCoreCapabilities = 8;
|
meshCoreObj.caps = 8;
|
||||||
mesh = agent.getMeshApi();
|
mesh = agent.getMeshApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the operating system description string
|
|
||||||
var osDesc = null;
|
|
||||||
try { require('os').name().then(function (v) { osDesc = v; if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "coreinfo", "value": obj.meshCoreInfo, "osdesc": osDesc }); } }); } catch (ex) { }
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
var AMTScanner = require("AMTScanner");
|
var AMTScanner = require("AMTScanner");
|
||||||
var scan = new AMTScanner();
|
var scan = new AMTScanner();
|
||||||
@ -139,31 +136,33 @@ function createMeshCore(agent) {
|
|||||||
// Fetch the SMBios Tables
|
// Fetch the SMBios Tables
|
||||||
var SMBiosTables = null;
|
var SMBiosTables = null;
|
||||||
var SMBiosTablesRaw = null;
|
var SMBiosTablesRaw = null;
|
||||||
require('smbios').get(function (data) {
|
try {
|
||||||
if (data != null) {
|
require('smbios').get(function (data) {
|
||||||
SMBiosTablesRaw = data;
|
if (data != null) {
|
||||||
SMBiosTables = require('smbios').parse(data)
|
SMBiosTablesRaw = data;
|
||||||
if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
|
SMBiosTables = require('smbios').parse(data)
|
||||||
|
if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
|
||||||
|
|
||||||
// If SMBios tables say that AMT is present, try to connect MEI
|
// If SMBios tables say that AMT is present, try to connect MEI
|
||||||
if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) {
|
if (SMBiosTables.amtInfo && (SMBiosTables.amtInfo.AMT == true)) {
|
||||||
// Try to load up the MEI module
|
// Try to load up the MEI module
|
||||||
try {
|
try {
|
||||||
var amtMeiLib = require('amt-mei');
|
var amtMeiLib = require('amt-mei');
|
||||||
amtMei = new amtMeiLib();
|
amtMei = new amtMeiLib();
|
||||||
amtMei.on('error', function (e) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; });
|
amtMei.on('error', function (e) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; });
|
||||||
amtMeiConnected = 2;
|
amtMeiConnected = 2;
|
||||||
sendPeriodicServerUpdate(1);
|
sendPeriodicServerUpdate(1);
|
||||||
} catch (ex) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; }
|
} catch (ex) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
} catch (ex) { sendConsoleText(ex); }
|
||||||
|
|
||||||
// Try to load up the WIFI scanner
|
// Try to load up the WIFI scanner
|
||||||
try {
|
try {
|
||||||
var wifiScannerLib = require('wifi-scanner');
|
var wifiScannerLib = require('wifi-scanner');
|
||||||
wifiScanner = new wifiScannerLib();
|
wifiScanner = new wifiScannerLib();
|
||||||
wifiScanner.on('accessPoint', function (data) { sendConsoleText(JSON.stringify(data)); });
|
wifiScanner.on('accessPoint', function (data) { sendConsoleText(data); });
|
||||||
} catch (ex) { wifiScannerLib = null; wifiScanner = null; }
|
} catch (ex) { wifiScannerLib = null; wifiScanner = null; }
|
||||||
|
|
||||||
// Get our location (lat/long) using our public IP address
|
// Get our location (lat/long) using our public IP address
|
||||||
@ -931,8 +930,8 @@ function createMeshCore(agent) {
|
|||||||
case 'border':
|
case 'border':
|
||||||
{
|
{
|
||||||
if ((args['_'].length == 1) && (args['_'][0] == 'on')) {
|
if ((args['_'].length == 1) && (args['_'][0] == 'on')) {
|
||||||
if (obj.loggedInUsers.length > 0) {
|
if (meshCoreObj.users.length > 0) {
|
||||||
obj.borderManager.Start(obj.loggedInUsers[0]);
|
obj.borderManager.Start(meshCoreObj.users[0]);
|
||||||
response = 'Border blinking is on.';
|
response = 'Border blinking is on.';
|
||||||
} else {
|
} else {
|
||||||
response = 'Cannot turn on border blinking, no logged in users.';
|
response = 'Cannot turn on border blinking, no logged in users.';
|
||||||
@ -946,11 +945,10 @@ function createMeshCore(agent) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
*/
|
*/
|
||||||
case 'users':
|
case 'users': {
|
||||||
{
|
if (meshCoreObj.users == null) { response = 'Active users are unknown.'; } else { response = 'Active Users: ' + meshCoreObj.users.join(', ') + '.'; }
|
||||||
if (obj.loggedInUsers == null) { response = 'Active users are unknown.'; } else { response = 'Active Users: ' + obj.loggedInUsers.join(', ') + '.'; }
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'toast': {
|
case 'toast': {
|
||||||
if (process.platform == 'win32') {
|
if (process.platform == 'win32') {
|
||||||
if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else {
|
if (args['_'].length < 1) { response = 'Proper usage: toast "message"'; } else {
|
||||||
@ -1023,9 +1021,9 @@ function createMeshCore(agent) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'info': { // Return information about the agent and agent core module
|
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 (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\nModules: ' + addedModules.join(', ') + '.';
|
||||||
response += '\r\nServer Connection: ' + mesh.isControlChannelConnected + ', State: ' + meshServerConnectionState + '.';
|
response += '\r\nServer Connection: ' + mesh.isControlChannelConnected + ', State: ' + meshServerConnectionState + '.';
|
||||||
response += '\r\lastMeInfo: ' + lastMeInfo + '.';
|
response += '\r\lastMeInfo: ' + lastMeInfo + '.';
|
||||||
@ -1048,18 +1046,20 @@ function createMeshCore(agent) {
|
|||||||
if (args['_'].length == 0) {
|
if (args['_'].length == 0) {
|
||||||
response = 'Proper usage: sendcaps (number)'; // Display correct command usage
|
response = 'Proper usage: sendcaps (number)'; // Display correct command usage
|
||||||
} else {
|
} else {
|
||||||
var flags = { "action": "coreinfo", "value": obj.meshCoreInfo, "caps": parseInt(args['_'][0]) };
|
meshCoreObj.caps = parseInt(args['_'][0]);
|
||||||
mesh.SendCommand(flags);
|
mesh.SendCommand(meshCoreObj);
|
||||||
response = JSON.stringify(flags);
|
response = JSON.stringify(meshCoreObj);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'sendosdesc': { // Send OS description
|
case 'sendosdesc': { // Send OS description
|
||||||
var os = osDesc;
|
if (args['_'].length > 0) {
|
||||||
if (args['_'].length > 0) { os = args['_'][0]; }
|
meshCoreObj.osdesc = args['_'][0];
|
||||||
var flags = { "action": "coreinfo", "value": obj.meshCoreInfo, "osdesc": os };
|
mesh.SendCommand(meshCoreObj);
|
||||||
mesh.SendCommand(flags);
|
response = JSON.stringify(meshCoreObj);
|
||||||
response = JSON.stringify(flags);
|
} else {
|
||||||
|
response = 'Proper usage: sendosdesc [os description]'; // Display correct command usage
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'args': { // Displays parsed command arguments
|
case 'args': { // Displays parsed command arguments
|
||||||
@ -1362,17 +1362,12 @@ function createMeshCore(agent) {
|
|||||||
var oldNodeId = db.Get('OldNodeId');
|
var oldNodeId = db.Get('OldNodeId');
|
||||||
if (oldNodeId != null) { mesh.SendCommand({ action: 'mc1migration', oldnodeid: oldNodeId }); }
|
if (oldNodeId != null) { mesh.SendCommand({ action: 'mc1migration', oldnodeid: oldNodeId }); }
|
||||||
|
|
||||||
// Update the server with basic info
|
// Update the server with basic info, logged in users and more.
|
||||||
var r = { "action": "coreinfo", "value": obj.meshCoreInfo, "caps": obj.meshCoreCapabilities };
|
mesh.SendCommand(meshCoreObj);
|
||||||
if (osDesc != null) { r.osdesc = osDesc; }
|
|
||||||
mesh.SendCommand(r);
|
|
||||||
|
|
||||||
// Send SMBios tables if present
|
// Send SMBios tables if present
|
||||||
if (SMBiosTablesRaw != null) { mesh.SendCommand({ "action": "smbios", "value": SMBiosTablesRaw }); }
|
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
|
// Update the server on more advanced stuff, like Intel ME and Network Settings
|
||||||
meInfoStr = null;
|
meInfoStr = null;
|
||||||
sendPeriodicServerUpdate();
|
sendPeriodicServerUpdate();
|
||||||
@ -1410,8 +1405,12 @@ function createMeshCore(agent) {
|
|||||||
if (meinfo.OsHostname) { intelamt.host = meinfo.OsHostname; p = true; }
|
if (meinfo.OsHostname) { intelamt.host = meinfo.OsHostname; p = true; }
|
||||||
if (meinfo.UUID) { intelamt.uuid = meinfo.UUID; p = true; }
|
if (meinfo.UUID) { intelamt.uuid = meinfo.UUID; p = true; }
|
||||||
if (p == true) {
|
if (p == true) {
|
||||||
var meInfoStr = JSON.stringify({ "action": "coreinfo", "value": obj.meshCoreInfo, "intelamt": intelamt });
|
var meInfoStr = JSON.stringify(intelamt);
|
||||||
if (meInfoStr != lastMeInfo) { mesh.SendCommand(meInfoStr); lastMeInfo = meInfoStr; }
|
if (meInfoStr != lastMeInfo) {
|
||||||
|
meshCoreObj.intelamt = intelamt;
|
||||||
|
mesh.SendCommand(meshCoreObj);
|
||||||
|
lastMeInfo = meInfoStr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (ex) { }
|
} catch (ex) { }
|
||||||
});
|
});
|
||||||
@ -1492,8 +1491,8 @@ function createMeshCore(agent) {
|
|||||||
var un = a[i].Domain ? (a[i].Domain + '\\' + a[i].Username) : (a[i].Username);
|
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.
|
if (u.indexOf(un) == -1) { u.push(un); } // Only push users in the list once.
|
||||||
}
|
}
|
||||||
obj.loggedInUsers = u;
|
meshCoreObj.users = u;
|
||||||
if (mesh.isControlChannelConnected) { mesh.SendCommand({ "action": "coreinfo", "users": u }); }
|
mesh.SendCommand(meshCoreObj);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
userSession.emit('changed');
|
userSession.emit('changed');
|
||||||
|
@ -602,7 +602,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
|||||||
if (mesh == null) return;
|
if (mesh == null) return;
|
||||||
|
|
||||||
// Get the node and change it if needed
|
// 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;
|
if (nodes.length != 1) return;
|
||||||
var device = nodes[0];
|
var device = nodes[0];
|
||||||
if (device.agent) {
|
if (device.agent) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.2.3-c",
|
"version": "0.2.3-e",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
@ -1937,8 +1937,7 @@
|
|||||||
// If a device is no longer viewed, disconnect it.
|
// If a device is no longer viewed, disconnect it.
|
||||||
if (multiDesktop[i].xxdelete == true) { multiDesktop[i].Stop(); delete multiDesktop[i]; }
|
if (multiDesktop[i].xxdelete == true) { multiDesktop[i].Stop(); delete multiDesktop[i]; }
|
||||||
else if (debugmode && multiDesktop[i].m && multiDesktop[i].m.onScreenSizeChange) {
|
else if (debugmode && multiDesktop[i].m && multiDesktop[i].m.onScreenSizeChange) {
|
||||||
// Adjust screen size change (JOKO) - This is not good.
|
mdeskAdjust(multiDesktop[i].m, multiDesktop[i].m.ScreenWidth, multiDesktop[i].m.ScreenHeight, multiDesktop[i].m.CanvasId); // Adjust screen size change
|
||||||
multiDesktop[i].m.onScreenSizeChange();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deskAdjust();
|
deskAdjust();
|
||||||
|
Loading…
Reference in New Issue
Block a user