Added support for temporary agents
Ylian Saint-Hilaire committed
Apr 12, 2018 at 11:15 UTC
bcb7100ced1b322f96dd656cb1db7271fb6564e6
15 files changed
+73
-44
agents/MeshCmd-signed.exe
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd-signed.exe differ
agents/MeshCmd64-signed.exe
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64-signed.exe differ
agents/MeshService-signed.exe
Binary files a/agents/MeshService-signed.exe and b/agents/MeshService-signed.exe differ
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64-signed.exe
Binary files a/agents/MeshService64-signed.exe and b/agents/MeshService64-signed.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshcore.js
+5
-2
@@ -377,6 +377,7 @@ function createMeshCore(agent) {
377
break;
378
}
379
}
380
+ break;
381
}
382
case 'wakeonlan': {
383
// 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) {
1309
amtLms = new lme_heci();
1310
amtLms.on('error', function (e) { amtLmsState = 0; amtLms = null; });
1311
amtLms.on('connect', function () { amtLmsState = 2; });
1312
+ //amtLms.on('bind', function (map) { });
1313
amtLms.on('notify', function (data, options, str) {
1314
if (str != null) { sendConsoleText('Intel AMT LMS: ' + str); }
1315
handleAmtNotification(data);
@@ -1343,7 +1345,7 @@ function createMeshCore(agent) {
1345
return obj;
1346
}
1347
1346
-var xexports = null;
1348
+var xexports = null, mainMeshCore = null;
1349
try { xexports = module.exports; } catch (e) { }
1350
1351
if (xexports != null) {
@@ -1351,5 +1353,6 @@ if (xexports != null) {
1353
module.exports.createMeshCore = createMeshCore;
1354
} else {
1355
// If we are not running in NodeJS, launch the core
1354
- createMeshCore().start(null);
1356
+ mainMeshCore = createMeshCore();
1357
+ mainMeshCore.start(null);
1358
}
agents/modules_meshcmd/amt-lme.js
+9
-11
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
+
18
var MemoryStream = require('MemoryStream');
19
var lme_id = 0; // Our next channel identifier
20
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;
38
var APF_CHANNEL_CLOSE = 97;
39
var APF_PROTOCOLVERSION = 192;
40
40
-
41
function lme_object() {
42
this.ourId = ++lme_id;
43
this.amtId = -1;
@@ -379,16 +379,14 @@ function lme_heci(options) {
379
buffer.writeUInt32BE(0xFFFFFFFF, 13); // Reserved
380
this.write(buffer);
381
382
- /*
383
- var buffer = Buffer.alloc(17);
384
- buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0);
385
- buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel
386
- buffer.writeUInt32BE(2, 5); // Reason code
387
- buffer.writeUInt32BE(0, 9); // Reserved
388
- buffer.writeUInt32BE(0, 13); // Reserved
389
- this.write(buffer);
390
- console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender);
391
- */
382
+ //var buffer = Buffer.alloc(17);
383
+ //buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0);
384
+ //buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel
385
+ //buffer.writeUInt32BE(2, 5); // Reason code
386
+ //buffer.writeUInt32BE(0, 9); // Reserved
387
+ //buffer.writeUInt32BE(0, 13); // Reserved
388
+ //this.write(buffer);
389
+ //console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender);
390
391
break;
392
}
agents/modules_meshcmd/amt-xml.js
+1
-1
@@ -103,7 +103,7 @@ function _PutObjToBodyXml(resuri, putObj) {
103
}
104
105
// This is a drop-in replacement to _turnToXml() that works without xml parser dependency.
106
-Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } });
106
+try { Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); } catch (ex) { }
107
function _treeBuilder() {
108
this.tree = [];
109
this.push = function (element) { this.tree.push(element); };
agents/modules_meshcore/amt-lme.js
+20
-14
@@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16
17
+
18
var MemoryStream = require('MemoryStream');
19
var lme_id = 0; // Our next channel identifier
20
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;
38
var APF_CHANNEL_CLOSE = 97;
39
var APF_PROTOCOLVERSION = 192;
40
40
-
41
function lme_object() {
42
this.ourId = ++lme_id;
43
this.amtId = -1;
@@ -52,7 +52,7 @@ function stream_bufferedWrite() {
52
var emitterUtils = require('events').inherits(this);
53
this.buffer = [];
54
this._readCheckImmediate = undefined;
55
-
55
+ this._ObjectID = "bufferedWriteStream";
56
// Writable Events
57
emitterUtils.createEvent('close');
58
emitterUtils.createEvent('drain');
@@ -115,17 +115,19 @@ function lme_heci(options) {
115
emitterUtils.createEvent('error');
116
emitterUtils.createEvent('connect');
117
emitterUtils.createEvent('notify');
118
+ emitterUtils.createEvent('bind');
119
120
if ((options != null) && (options.debug == true)) { lme_port_offset = -100; } // LMS debug mode
121
122
var heci = require('heci');
123
this.INITIAL_RXWINDOW_SIZE = 4096;
124
125
+ this._ObjectID = "lme";
126
this._LME = heci.create();
127
+ this._LME._binded = {};
128
this._LME.LMS = this;
129
this._LME.on('error', function (e) { this.LMS.emit('error', e); });
130
this._LME.on('connect', function () {
128
- this.LMS.emit('connect');
131
this.on('data', function (chunk) {
132
// this = HECI
133
var cmd = chunk.readUInt8(0);
@@ -166,7 +168,8 @@ function lme_heci(options) {
168
if (channel.localPort == port) { this.sockets[i].end(); delete this.sockets[i]; } // Close this socket
169
}
170
}
169
- if (this[name][port] == null) { // Bind a new server socket if not already present
171
+ if (this[name][port] == null)
172
+ { // Bind a new server socket if not already present
173
this[name][port] = require('net').createServer();
174
this[name][port].HECI = this;
175
if (lme_port_offset == 0) {
@@ -178,6 +181,8 @@ function lme_heci(options) {
181
//console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort);
182
this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort - lme_port_offset);
183
});
184
+ this._binded[port] = true;
185
+ this.LMS.emit('bind', this._binded);
186
}
187
var outBuffer = Buffer.alloc(5);
188
outBuffer.writeUInt8(81, 0);
@@ -374,20 +379,21 @@ function lme_heci(options) {
379
buffer.writeUInt32BE(0xFFFFFFFF, 13); // Reserved
380
this.write(buffer);
381
377
- /*
378
- var buffer = Buffer.alloc(17);
379
- buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0);
380
- buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel
381
- buffer.writeUInt32BE(2, 5); // Reason code
382
- buffer.writeUInt32BE(0, 9); // Reserved
383
- buffer.writeUInt32BE(0, 13); // Reserved
384
- this.write(buffer);
385
- console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender);
386
- */
382
+ //var buffer = Buffer.alloc(17);
383
+ //buffer.writeUInt8(APF_CHANNEL_OPEN_FAILURE, 0);
384
+ //buffer.writeUInt32BE(channelSender, 1); // Intel AMT sender channel
385
+ //buffer.writeUInt32BE(2, 5); // Reason code
386
+ //buffer.writeUInt32BE(0, 9); // Reserved
387
+ //buffer.writeUInt32BE(0, 13); // Reserved
388
+ //this.write(buffer);
389
+ //console.log('Sent APF_CHANNEL_OPEN_FAILURE', channelSender);
390
391
break;
392
}
393
});
394
+ this.LMS.emit('connect');
395
+ this.resume();
396
+
397
});
398
399
this.bindDuplexStream = function (duplexStream, remoteFamily, localPort) {
agents/modules_meshcore/amt-mei.js
+2
-1
@@ -92,11 +92,12 @@ function amt_heci() {
92
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
93
this.sendCommand(26, null, function (header, fn, opt) {
94
if (header.Status == 0) {
95
- var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4);
95
+ var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen).toString(), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4);
96
for (i = 0; i < CodeVersion.readUInt32LE(this._amt.BiosVersionLen) ; ++i) {
97
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() };
98
v = v.slice(4 + (2 * this._amt.UnicodeStringLen));
99
}
100
+ if (val.BiosVersion.indexOf('\0') > 0) { val.BiosVersion = val.BiosVersion.substring(0, val.BiosVersion.indexOf('\0')); }
101
opt.unshift(val);
102
} else {
103
opt.unshift(null);
agents/modules_meshcore/amt-xml.js
+1
-1
@@ -103,7 +103,7 @@ function _PutObjToBodyXml(resuri, putObj) {
103
}
104
105
// This is a drop-in replacement to _turnToXml() that works without xml parser dependency.
106
-Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } });
106
+try { Object.defineProperty(Array.prototype, "peek", { value: function () { return (this.length > 0 ? this[this.length - 1] : null); } }); } catch (ex) { }
107
function _treeBuilder() {
108
this.tree = [];
109
this.push = function (element) { this.tree.push(element); };
meshagent.js
+19
@@ -48,6 +48,21 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
48
// Other clean up may be needed here
49
if (obj.unauth) { delete obj.unauth; }
50
if (obj.agentUpdate != null) { obj.fs.close(obj.agentUpdate.fd); obj.agentUpdate = null; }
51
+ if (obj.agentInfo.capabilities & 0x20) { // This is a temporary agent, remote it
52
+ // Delete this node including network interface information and events
53
+ obj.db.Remove(obj.dbNodeKey);
54
+ obj.db.Remove('if' + obj.dbNodeKey);
55
+
56
+ // Event node deletion
57
+ obj.parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, { etype: 'node', action: 'removenode', nodeid: obj.dbNodeKey, domain: obj.domain.id, nolog: 1 })
58
+
59
+ // Disconnect all connections if needed
60
+ var state = obj.parent.parent.GetConnectivityState(obj.dbNodeKey);
61
+ if ((state != null) && (state.connectivity != null)) {
62
+ if ((state.connectivity & 1) != 0) { obj.parent.wsagents[obj.dbNodeKey].close(); } // Disconnect mesh agent
63
+ if ((state.connectivity & 2) != 0) { obj.parent.parent.mpsserver.close(obj.parent.parent.mpsserver.ciraConnections[obj.dbNodeKey]); } // Disconnect CIRA connection
64
+ }
65
+ }
66
}
67
68
// When data is received from the mesh agent web socket
@@ -431,6 +446,10 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
446
delete command.userid; // Remove the userid, since we are sending to that userid, so it's implyed.
447
for (var i in sessions) { sessions[i].send(JSON.stringify(command)); }
448
}
449
+
450
+ if (obj.parent.parent.multiServer != null) {
451
+ // TODO: Add multi-server support
452
+ }
453
}
454
} else { // Route this command to the mesh
455
command.nodeid = obj.dbNodeKey;
meshcentral.js
+15
-13
@@ -746,22 +746,24 @@ function CreateMeshCentralServer(config, args) {
746
}
747
748
// Read meshcore.js and all .js files in the modules folder.
749
- var moduleAdditions = 'var addedModules = [];', moduleAdditionsNoMei = 'var addedModules = [];', modulesDir = null;
750
- var meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString();
751
- try { modulesDir = obj.fs.readdirSync(obj.path.join(meshcorePath, 'modules_meshcore')); } catch (e) { }
752
- if (modulesDir != null) {
753
- for (var i in modulesDir) {
754
- if (modulesDir[i].toLowerCase().endsWith('.js')) {
755
- // Merge this module
756
- var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3);
757
- var moduleDataB64 = obj.fs.readFileSync(obj.path.join(meshcorePath, 'modules_meshcore', modulesDir[i])).toString('base64');
758
- moduleAdditions += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n';
759
- 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')) {
760
- moduleAdditionsNoMei += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n';
749
+ var moduleAdditions = 'var addedModules = [];', moduleAdditionsNoMei = 'var addedModules = [];', meshCore = null, modulesDir = null;
750
+ try { meshCore = obj.fs.readFileSync(obj.path.join(meshcorePath, 'meshcore.js')).toString(); } catch (e) { }
751
+ if (meshCore != null) {
752
+ try { modulesDir = obj.fs.readdirSync(obj.path.join(meshcorePath, 'modules_meshcore')); } catch (e) { }
753
+ if (modulesDir != null) {
754
+ for (var i in modulesDir) {
755
+ if (modulesDir[i].toLowerCase().endsWith('.js')) {
756
+ // Merge this module
757
+ var moduleName = modulesDir[i].substring(0, modulesDir[i].length - 3);
758
+ var moduleDataB64 = obj.fs.readFileSync(obj.path.join(meshcorePath, 'modules_meshcore', modulesDir[i])).toString('base64');
759
+ moduleAdditions += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n';
760
+ 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')) {
761
+ moduleAdditionsNoMei += 'try { addModule("' + moduleName + '", Buffer.from("' + moduleDataB64 + '", "base64")); addedModules.push("' + moduleName + '"); } catch (e) { }\r\n';
762
+ }
763
}
764
}
765
}
764
- }
766
+ } else { meshCore = ''; } // No meshcore.js
767
768
// Set the new default meshcore.js with and without MEI support
769
obj.defaultMeshCore = obj.common.IntToStr(0) + moduleAdditions + meshCore;
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.1.6-c",
3
+ "version": "0.1.6-d",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",