diff --git a/agents/MeshCmd-signed.exe b/agents/MeshCmd-signed.exe index d0cebce9..538b54ec 100644 Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ diff --git a/agents/MeshCmd64-signed.exe b/agents/MeshCmd64-signed.exe index ee85a022..e8f7bd64 100644 Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ diff --git a/agents/MeshService-signed.exe b/agents/MeshService-signed.exe index dee4ba85..64d419b4 100644 Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ diff --git a/agents/MeshService.exe b/agents/MeshService.exe index 47c5098c..d5dd0ebd 100644 Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ diff --git a/agents/MeshService64-signed.exe b/agents/MeshService64-signed.exe index 4e129b06..902a58d9 100644 Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ diff --git a/agents/MeshService64.exe b/agents/MeshService64.exe index e74b2315..7c670468 100644 Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ diff --git a/agents/meshcore.js b/agents/meshcore.js index 52d54743..bb8ed2b8 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -377,6 +377,7 @@ function createMeshCore(agent) { break; } } + break; } case 'wakeonlan': { // Send wake-on-lan on all interfaces for all MAC addresses in data.macs array. The array is a list of HEX MAC addresses. @@ -1308,6 +1309,7 @@ function createMeshCore(agent) { amtLms = new lme_heci(); amtLms.on('error', function (e) { amtLmsState = 0; amtLms = null; }); amtLms.on('connect', function () { amtLmsState = 2; }); + //amtLms.on('bind', function (map) { }); amtLms.on('notify', function (data, options, str) { if (str != null) { sendConsoleText('Intel AMT LMS: ' + str); } handleAmtNotification(data); @@ -1343,7 +1345,7 @@ function createMeshCore(agent) { return obj; } -var xexports = null; +var xexports = null, mainMeshCore = null; try { xexports = module.exports; } catch (e) { } if (xexports != null) { @@ -1351,5 +1353,6 @@ if (xexports != null) { module.exports.createMeshCore = createMeshCore; } else { // If we are not running in NodeJS, launch the core - createMeshCore().start(null); + mainMeshCore = createMeshCore(); + mainMeshCore.start(null); } diff --git a/agents/modules_meshcmd/amt-lme.js b/agents/modules_meshcmd/amt-lme.js index 725cfcda..a7bb12ec 100644 --- a/agents/modules_meshcmd/amt-lme.js +++ b/agents/modules_meshcmd/amt-lme.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ + var MemoryStream = require('MemoryStream'); var lme_id = 0; // Our next channel identifier var lme_port_offset = 0; // Debug: Set this to "-100" to bind to 16892 & 16893 and IN_ADDRANY. This is for LMS debugging. @@ -37,7 +38,6 @@ var APF_CHANNEL_DATA = 94; var APF_CHANNEL_CLOSE = 97; var APF_PROTOCOLVERSION = 192; - function lme_object() { this.ourId = ++lme_id; this.amtId = -1; @@ -379,16 +379,14 @@ function lme_heci(options) { buffer.writeUInt32BE(0xFFFFFFFF, 13); // Reserved this.write(buffer); - /* - var buffer = Buffer.alloc(17); - buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0); - buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel - buffer.writeUInt32BE(2, 5); // Reason code - buffer.writeUInt32BE(0, 9); // Reserved - buffer.writeUInt32BE(0, 13); // Reserved - this.write(buffer); - console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender); - */ + //var buffer = Buffer.alloc(17); + //buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0); + //buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel + //buffer.writeUInt32BE(2, 5); // Reason code + //buffer.writeUInt32BE(0, 9); // Reserved + //buffer.writeUInt32BE(0, 13); // Reserved + //this.write(buffer); + //console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender); break; } diff --git a/agents/modules_meshcmd/amt-xml.js b/agents/modules_meshcmd/amt-xml.js index 694a56e0..605d8baf 100644 --- a/agents/modules_meshcmd/amt-xml.js +++ b/agents/modules_meshcmd/amt-xml.js @@ -103,7 +103,7 @@ function _PutObjToBodyXml(resuri, putObj) { } // This is a drop-in replacement to _turnToXml() that works without xml parser dependency. -Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); +try { Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); } catch (ex) { } function _treeBuilder() { this.tree = []; this.push = function (element) { this.tree.push(element); }; diff --git a/agents/modules_meshcore/amt-lme.js b/agents/modules_meshcore/amt-lme.js index a70960bc..a7bb12ec 100644 --- a/agents/modules_meshcore/amt-lme.js +++ b/agents/modules_meshcore/amt-lme.js @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ + var MemoryStream = require('MemoryStream'); var lme_id = 0; // Our next channel identifier var lme_port_offset = 0; // Debug: Set this to "-100" to bind to 16892 & 16893 and IN_ADDRANY. This is for LMS debugging. @@ -37,7 +38,6 @@ var APF_CHANNEL_DATA = 94; var APF_CHANNEL_CLOSE = 97; var APF_PROTOCOLVERSION = 192; - function lme_object() { this.ourId = ++lme_id; this.amtId = -1; @@ -52,7 +52,7 @@ function stream_bufferedWrite() { var emitterUtils = require('events').inherits(this); this.buffer = []; this._readCheckImmediate = undefined; - + this._ObjectID = "bufferedWriteStream"; // Writable Events emitterUtils.createEvent('close'); emitterUtils.createEvent('drain'); @@ -115,17 +115,19 @@ function lme_heci(options) { emitterUtils.createEvent('error'); emitterUtils.createEvent('connect'); emitterUtils.createEvent('notify'); + emitterUtils.createEvent('bind'); if ((options != null) && (options.debug == true)) { lme_port_offset = -100; } // LMS debug mode var heci = require('heci'); this.INITIAL_RXWINDOW_SIZE = 4096; + this._ObjectID = "lme"; this._LME = heci.create(); + this._LME._binded = {}; this._LME.LMS = this; this._LME.on('error', function (e) { this.LMS.emit('error', e); }); this._LME.on('connect', function () { - this.LMS.emit('connect'); this.on('data', function (chunk) { // this = HECI var cmd = chunk.readUInt8(0); @@ -166,7 +168,8 @@ function lme_heci(options) { if (channel.localPort == port) { this.sockets[i].end(); delete this.sockets[i]; } // Close this socket } } - if (this[name][port] == null) { // Bind a new server socket if not already present + if (this[name][port] == null) + { // Bind a new server socket if not already present this[name][port] = require('net').createServer(); this[name][port].HECI = this; if (lme_port_offset == 0) { @@ -178,6 +181,8 @@ function lme_heci(options) { //console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort); this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset); }); + this._binded[port] = true; + this.LMS.emit('bind', this._binded); } var outBuffer = Buffer.alloc(5); outBuffer.writeUInt8(81, 0); @@ -374,20 +379,21 @@ function lme_heci(options) { buffer.writeUInt32BE(0xFFFFFFFF, 13); // Reserved this.write(buffer); - /* - var buffer = Buffer.alloc(17); - buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0); - buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel - buffer.writeUInt32BE(2, 5); // Reason code - buffer.writeUInt32BE(0, 9); // Reserved - buffer.writeUInt32BE(0, 13); // Reserved - this.write(buffer); - console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender); - */ + //var buffer = Buffer.alloc(17); + //buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0); + //buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel + //buffer.writeUInt32BE(2, 5); // Reason code + //buffer.writeUInt32BE(0, 9); // Reserved + //buffer.writeUInt32BE(0, 13); // Reserved + //this.write(buffer); + //console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender); break; } }); + this.LMS.emit('connect'); + this.resume(); + }); this.bindDuplexStream = function (duplexStream, remoteFamily, localPort) { diff --git a/agents/modules_meshcore/amt-mei.js b/agents/modules_meshcore/amt-mei.js index 479025f8..a6f0b17b 100644 --- a/agents/modules_meshcore/amt-mei.js +++ b/agents/modules_meshcore/amt-mei.js @@ -92,11 +92,12 @@ function amt_heci() { for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); } this.sendCommand(26, null, function (header, fn, opt) { if (header.Status == 0) { - var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4); + var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen).toString(), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4); for (i = 0; i < CodeVersion.readUInt32LE(this._amt.BiosVersionLen) ; ++i) { val.Versions[i] = { Description: v.slice(2, v.readUInt16LE(0) + 2).toString(), Version: v.slice(4 + this._amt.UnicodeStringLen, 4 + this._amt.UnicodeStringLen + v.readUInt16LE(2 + this._amt.UnicodeStringLen)).toString() }; v = v.slice(4 + (2 * this._amt.UnicodeStringLen)); } + if (val.BiosVersion.indexOf('\0') > 0) { val.BiosVersion = val.BiosVersion.substring(0, val.BiosVersion.indexOf('\0')); } opt.unshift(val); } else { opt.unshift(null); diff --git a/agents/modules_meshcore/amt-xml.js b/agents/modules_meshcore/amt-xml.js index 694a56e0..605d8baf 100644 --- a/agents/modules_meshcore/amt-xml.js +++ b/agents/modules_meshcore/amt-xml.js @@ -103,7 +103,7 @@ function _PutObjToBodyXml(resuri, putObj) { } // This is a drop-in replacement to _turnToXml() that works without xml parser dependency. -Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); +try { Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); } catch (ex) { } function _treeBuilder() { this.tree = []; this.push = function (element) { this.tree.push(element); }; diff --git a/meshagent.js b/meshagent.js index 9a3b510e..4c70d45e 100644 --- a/meshagent.js +++ b/meshagent.js @@ -48,6 +48,21 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Other clean up may be needed here if (obj.unauth) { delete obj.unauth; } if (obj.agentUpdate != null) { obj.fs.close(obj.agentUpdate.fd); obj.agentUpdate = null; } + if (obj.agentInfo.capabilities & 0x20) { // This is a temporary agent, remote it + // Delete this node including network interface information and events + obj.db.Remove(obj.dbNodeKey); + obj.db.Remove('if' + obj.dbNodeKey); + + // Event node deletion + obj.parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, { etype: 'node', action: 'removenode', nodeid: obj.dbNodeKey, domain: obj.domain.id, nolog: 1 }) + + // Disconnect all connections if needed + var state = obj.parent.parent.GetConnectivityState(obj.dbNodeKey); + if ((state != null) && (state.connectivity != null)) { + if ((state.connectivity & 1) != 0) { obj.parent.wsagents[obj.dbNodeKey].close(); } // Disconnect mesh agent + if ((state.connectivity & 2) != 0) { obj.parent.parent.mpsserver.close(obj.parent.parent.mpsserver.ciraConnections[obj.dbNodeKey]); } // Disconnect CIRA connection + } + } } // When data is received from the mesh agent web socket @@ -431,6 +446,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { delete command.userid; // Remove the userid, since we are sending to that userid, so it's implyed. for (var i in sessions) { sessions[i].send(JSON.stringify(command)); } } + + if (obj.parent.parent.multiServer != null) { + // TODO: Add multi-server support + } } } else { // Route this command to the mesh command.nodeid = obj.dbNodeKey; diff --git a/meshcentral.js b/meshcentral.js index 291fec2a..ce76045a 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -746,22 +746,24 @@ function CreateMeshCentralServer(config, args) { } // Read meshcore.js and all .js files in the modules folder. - var moduleAdditions = 'var addedModules = [];', moduleAdditionsNoMei = 'var addedModules = [];', modulesDir = null; - var meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString(); - try { modulesDir = obj.fs.readdirSync(obj.path.join(meshcorePath, 'modules_meshcore')); } catch (e) { } - if (modulesDir != null) { - for (var i in modulesDir) { - if (modulesDir[i].toLowerCase().endsWith('.js')) { - // Merge this module - var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3); - var moduleDataB64 = obj.fs.readFileSync(obj.path.join(meshcorePath, 'modules_meshcore', modulesDir[i])).toString('base64'); - moduleAdditions += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n'; - if ((moduleName != 'amt_heci') && (moduleName != 'lme_heci') && (moduleName != 'amt-0.2.0.js') && (moduleName != 'amt-script-0.2.0.js') && (moduleName != 'amt-wsman-0.2.0.js') && (moduleName != 'amt-wsman-duk-0.2.0.js')) { - moduleAdditionsNoMei += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n'; + var moduleAdditions = 'var addedModules = [];', moduleAdditionsNoMei = 'var addedModules = [];', meshCore = null, modulesDir = null; + try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString(); } catch (e) { } + if (meshCore != null) { + try { modulesDir = obj.fs.readdirSync(obj.path.join(meshcorePath, 'modules_meshcore')); } catch (e) { } + if (modulesDir != null) { + for (var i in modulesDir) { + if (modulesDir[i].toLowerCase().endsWith('.js')) { + // Merge this module + var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3); + var moduleDataB64 = obj.fs.readFileSync(obj.path.join(meshcorePath, 'modules_meshcore', modulesDir[i])).toString('base64'); + moduleAdditions += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n'; + if ((moduleName != 'amt_heci') && (moduleName != 'lme_heci') && (moduleName != 'amt-0.2.0.js') && (moduleName != 'amt-script-0.2.0.js') && (moduleName != 'amt-wsman-0.2.0.js') && (moduleName != 'amt-wsman-duk-0.2.0.js')) { + moduleAdditionsNoMei += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n'; + } } } } - } + } else { meshCore = ''; } // No meshcore.js // Set the new default meshcore.js with and without MEI support obj.defaultMeshCore = obj.common.IntToStr(0) + moduleAdditions + meshCore; diff --git a/package.json b/package.json index 6966e6f4..539d0d99 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.1.6-c", + "version": "0.1.6-d", "keywords": [ "Remote Management", "Intel AMT",