Fixed multi-tenancy DNS support

Ylian Saint-Hilaire committed Jan 4, 2018 at 12:15 UTC d455e35658dd05e032043ca29288385f8d119d03
24 files changed +167 -110
agents/MeshService.exe
Binary files a/agents/MeshService.exe and b/agents/MeshService.exe differ
agents/MeshService64.exe
Binary files a/agents/MeshService64.exe and b/agents/MeshService64.exe differ
agents/meshcore.js
+96 -90
@@ -1,11 +1,11 @@
1 /*
2 -Copyright 2017 Intel Corporation
2 +Copyright 2018 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 - http://www.apache.org/licenses/LICENSE-2.0
8 + http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
@@ -16,7 +16,7 @@ limitations under the License.
16
17 function createMeshCore(agent) {
18 var obj = {};
19 -
19 +
20 // MeshAgent JavaScript Core Module. This code is sent to and running on the mesh agent.
21 obj.meshCoreInfo = "MeshCore v4";
22 obj.meshCoreCapabilities = 14; // Capability bitmask: 1 = Desktop, 2 = Terminal, 4 = Files, 8 = Console, 16 = JavaScript
@@ -36,7 +36,7 @@ function createMeshCore(agent) {
36 var wifiScannerLib = null;
37 var wifiScanner = null;
38 var networkMonitor = null;
39 -
39 +
40 // Try to load up the network monitor
41 try {
42 networkMonitor = require('NetworkMonitor');
@@ -44,7 +44,7 @@ function createMeshCore(agent) {
44 networkMonitor.on('add', function (addr) { sendNetworkUpdateNagle(); });
45 networkMonitor.on('remove', function (addr) { sendNetworkUpdateNagle(); });
46 } catch (e) { networkMonitor = null; }
47 -
47 +
48 // Try to load up the MEI module
49 try {
50 var amtMeiLib = require('amt_heci');
@@ -53,21 +53,21 @@ function createMeshCore(agent) {
53 amtMei.on('error', function (e) { amtMeiLib = null; amtMei = null; sendPeriodicServerUpdate(); });
54 amtMei.on('connect', function () { amtMeiConnected = 2; getAmtInfo(); });
55 } catch (e) { amtMeiLib = null; amtMei = null; amtMeiConnected = -1; }
56 -
56 +
57 // Try to load up the WIFI scanner
58 try {
59 var wifiScannerLib = require('WifiScanner');
60 wifiScanner = new wifiScannerLib();
61 wifiScanner.on('accessPoint', function (data) { sendConsoleText(JSON.stringify(data)); });
62 } catch (e) { wifiScannerLib = null; wifiScanner = null; }
63 -
63 +
64 // If we are running in Duktape, agent will be null
65 if (agent == null) {
66 // Running in native agent, Import libraries
67 db = require('SimpleDataStore').Shared();
68 sha = require('SHA256Stream');
69 mesh = require('MeshAgent');
70 - processManager = require('ILibProcessPipe');
70 + childProcess = require('child_process');
71 if (mesh.hasKVM == 1) { obj.meshCoreCapabilities |= 1; }
72 } else {
73 // Running in nodejs
@@ -75,7 +75,7 @@ function createMeshCore(agent) {
75 obj.meshCoreCapabilities = 8;
76 mesh = agent.getMeshApi();
77 }
78 -
78 +
79 // Get our location (lat/long) using our public IP address
80 var getIpLocationDataExInProgress = false;
81 var getIpLocationDataExCounts = [0, 0];
@@ -91,27 +91,27 @@ function createMeshCore(agent) {
91 headers: { Host: "ipinfo.io" }
92 },
93 function (resp) {
94 - if (resp.statusCode == 200) {
95 - var geoData = '';
96 - resp.data = function (geoipdata) { geoData += geoipdata; };
97 - resp.end = function () {
98 - var location = null;
99 - try {
100 - if (typeof geoData == 'string') {
101 - var result = JSON.parse(geoData);
102 - if (result.ip && result.loc) { location = result; }
103 - }
104 - } catch (e) { }
105 - if (func) { getIpLocationDataExCounts[1]++; func(location); }
106 - }
107 - } else { func(null); }
108 - getIpLocationDataExInProgress = false;
109 - }).end();
94 + if (resp.statusCode == 200) {
95 + var geoData = '';
96 + resp.data = function (geoipdata) { geoData += geoipdata; };
97 + resp.end = function () {
98 + var location = null;
99 + try {
100 + if (typeof geoData == 'string') {
101 + var result = JSON.parse(geoData);
102 + if (result.ip && result.loc) { location = result; }
103 + }
104 + } catch (e) { }
105 + if (func) { getIpLocationDataExCounts[1]++; func(location); }
106 + }
107 + } else { func(null); }
108 + getIpLocationDataExInProgress = false;
109 + }).end();
110 return true;
111 }
112 catch (e) { return false; }
113 }
114 -
114 +
115 // Remove all Gateway MAC addresses for interface list. This is useful because the gateway MAC is not always populated reliably.
116 function clearGatewayMac(str) {
117 if (str == null) return null;
@@ -119,7 +119,7 @@ function createMeshCore(agent) {
119 for (var i in x.netif) { if (x.netif[i].gatewaymac) { delete x.netif[i].gatewaymac } }
120 return JSON.stringify(x);
121 }
122 -
122 +
123 function getIpLocationData(func) {
124 // Get the location information for the cache if possible
125 var publicLocationInfo = db.Get('publicLocationInfo');
@@ -158,7 +158,7 @@ function createMeshCore(agent) {
158 }
159 }
160 }
161 -
161 +
162 // Polyfill String.endsWith
163 if (!String.prototype.endsWith) {
164 String.prototype.endsWith = function (searchString, position) {
@@ -169,7 +169,7 @@ function createMeshCore(agent) {
169 return lastIndex !== -1 && lastIndex === position;
170 };
171 }
172 -
172 +
173 // Polyfill path.join
174 obj.path = {
175 join: function () {
@@ -188,19 +188,19 @@ function createMeshCore(agent) {
188 return x.join('/');
189 }
190 };
191 -
191 +
192 // Replace a string with a number if the string is an exact number
193 function toNumberIfNumber(x) { if ((typeof x == 'string') && (+parseInt(x) === x)) { x = parseInt(x); } return x; }
194 -
194 +
195 // Convert decimal to hex
196 function char2hex(i) { return (i + 0x100).toString(16).substr(-2).toUpperCase(); }
197 -
197 +
198 // Convert a raw string to a hex string
199 function rstr2hex(input) { var r = '', i; for (i = 0; i < input.length; i++) { r += char2hex(input.charCodeAt(i)); } return r; }
200 -
200 +
201 // Convert a buffer into a string
202 function buf2rstr(buf) { var r = ''; for (var i = 0; i < buf.length; i++) { r += String.fromCharCode(buf[i]); } return r; }
203 -
203 +
204 // Convert a hex string to a raw string // TODO: Do this using Buffer(), will be MUCH faster
205 function hex2rstr(d) {
206 if (typeof d != "string" || d.length == 0) return '';
@@ -208,7 +208,7 @@ function createMeshCore(agent) {
208 while (t = m.shift()) r += String.fromCharCode('0x' + t);
209 return r
210 }
211 -
211 +
212 // Convert an object to string with all functions
213 function objToString(x, p, ret) {
214 if (ret == undefined) ret = '';
@@ -223,17 +223,17 @@ function createMeshCore(agent) {
223 for (var i in x) { r += (addPad(p + 2, ret) + i + ': ' + objToString(x[i], p + 2, ret) + (ret ? '\r\n' : ' ')); }
224 return r + addPad(p, ret) + '}';
225 }
226 -
226 +
227 // Return p number of spaces
228 function addPad(p, ret) { var r = ''; for (var i = 0; i < p; i++) { r += ret; } return r; }
229 -
229 +
230 // Split a string taking into account the quoats. Used for command line parsing
231 function splitArgs(str) {
232 var myArray = [], myRegexp = /[^\s"]+|"([^"]*)"/gi;
233 do { var match = myRegexp.exec(str); if (match != null) { myArray.push(match[1] ? match[1] : match[0]); } } while (match != null);
234 return myArray;
235 }
236 -
236 +
237 // Parse arguments string array into an object
238 function parseArgs(argv) {
239 var results = { '_': [] }, current = null;
@@ -249,7 +249,7 @@ function createMeshCore(agent) {
249 if (current != null) { results[current] = true; }
250 return results;
251 }
252 -
252 +
253 // Get server target url with a custom path
254 function getServerTargetUrl(path) {
255 var x = mesh.ServerUrl;
@@ -260,13 +260,13 @@ function createMeshCore(agent) {
260 if (x == null) return null;
261 return x.protocol + '//' + x.host + ':' + x.port + '/' + path;
262 }
263 -
263 +
264 // Get server url. If the url starts with "*/..." change it, it not use the url as is.
265 function getServerTargetUrlEx(url) {
266 if (url.substring(0, 2) == '*/') { return getServerTargetUrl(url.substring(2)); }
267 return url;
268 }
269 -
269 +
270 // Send a wake-on-lan packet
271 function sendWakeOnLan(hexMac) {
272 var count = 0;
@@ -275,7 +275,7 @@ function createMeshCore(agent) {
275 var magic = 'FFFFFFFFFFFF';
276 for (var x = 1; x <= 16; ++x) { magic += hexMac; }
277 var magicbin = Buffer.from(magic, 'hex');
278 -
278 +
279 for (var adapter in interfaces) {
280 if (interfaces.hasOwnProperty(adapter)) {
281 for (var i = 0; i < interfaces[adapter].length; ++i) {
@@ -293,7 +293,7 @@ function createMeshCore(agent) {
293 } catch (e) { }
294 return count;
295 }
296 -
296 +
297 // Handle a mesh agent command
298 function handleServerCommand(data) {
299 if (typeof data == 'object') {
@@ -311,6 +311,7 @@ function createMeshCore(agent) {
311 var xurl = getServerTargetUrlEx(data.value);
312 if (xurl != null) {
313 var woptions = http.parseUri(xurl);
314 + woptions.rejectUnauthorized = 0;
315 sendConsoleText(JSON.stringify(woptions));
316 var tunnel = http.request(woptions);
317 tunnel.upgrade = onTunnelUpgrade;
@@ -322,13 +323,14 @@ function createMeshCore(agent) {
323 tunnel.protocol = 0;
324 tunnel.tcpaddr = data.tcpaddr;
325 tunnel.tcpport = data.tcpport;
325 -
326 + tunnel.end();
327 + sendConsoleText('tunnel.end() called');
328 // Put the tunnel in the tunnels list
329 var index = 1;
330 while (tunnels[index]) { index++; }
331 tunnel.index = index;
332 tunnels[index] = tunnel;
331 -
333 +
334 sendConsoleText('New tunnel connection #' + index + ': ' + tunnel.url + ', rights: ' + tunnel.rights, data.sessionid);
335 }
336 }
@@ -360,7 +362,7 @@ function createMeshCore(agent) {
362 }
363 }
364 }
363 -
365 +
366 // Called when a file changed in the file system
367 /*
368 function onFileWatcher(a, b) {
@@ -390,7 +392,7 @@ function createMeshCore(agent) {
392 if (reqpath == '') { reqpath = '/'; }
393 var xpath = obj.path.join(reqpath, '*');
394 var results = null;
393 -
395 +
396 try { results = fs.readdirSync(xpath); } catch (e) { }
397 if (results != null) {
398 for (var i = 0; i < results.length; ++i) {
@@ -410,13 +412,13 @@ function createMeshCore(agent) {
412 }
413 return response;
414 }
413 -
415 +
416 // Tunnel callback operations
417 function onTunnelUpgrade(response, s, head) {
418 this.s = s;
419 s.httprequest = this;
420 s.end = onTunnelClosed;
419 -
421 +
422 if (this.tcpport != null) {
423 // This is a TCP relay connection, pause now and try to connect to the target.
424 s.pause();
@@ -430,7 +432,7 @@ function createMeshCore(agent) {
432 s.data = onTunnelData;
433 }
434 }
433 -
435 +
436 // Called when the TCP relay target is connected
437 function onTcpRelayTargetTunnelConnect() {
438 var peerTunnel = tunnels[this.peerindex];
@@ -438,17 +440,17 @@ function createMeshCore(agent) {
440 peerTunnel.s.first = true;
441 peerTunnel.s.resume();
442 }
441 -
443 +
444 // Called when we get data from the server for a TCP relay (We have to skip the first received 'c' and pipe the rest)
445 function onTcpRelayServerTunnelData(data) {
446 if (this.first == true) { this.first = false; this.pipe(this.tcprelay); } // Pipe Server --> Target
447 }
446 -
448 +
449 function onTunnelClosed() {
450 sendConsoleText("Tunnel #" + this.httprequest.index + " closed.", this.httprequest.sessionid);
451 if (this.httprequest.protocol == 1) { this.httprequest.process.end(); delete this.httprequest.process; }
452 delete tunnels[this.httprequest.index];
451 -
453 +
454 /*
455 // Close the watcher if required
456 if (this.httprequest.watcher != undefined) {
@@ -466,7 +468,7 @@ function createMeshCore(agent) {
468 function onTunnelData(data) {
469 //console.log("OnTunnelData");
470 //sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data);
469 -
471 +
472 // If this is upload data, save it to file
473 if (this.httprequest.uploadFile) {
474 try { fs.writeSync(this.httprequest.uploadFile, data); } catch (e) { this.write(new Buffer(JSON.stringify({ action: 'uploaderror' }))); return; } // Write to the file, if there is a problem, error out.
@@ -481,7 +483,7 @@ function createMeshCore(agent) {
483 if (len > 0) { this.write(buf.slice(0, len)); } else { fs.closeSync(this.httprequest.downloadFile); this.httprequest.downloadFile = undefined; this.end(); }
484 return;
485 }
484 -
486 +
487 // Setup remote desktop & terminal without using native pipes
488 if ((this.httprequest.desktop) && (obj.useNativePipes == false)) {
489 if (data.length > 21 && data.toString().startsWith('**********%%%%%%###**')) {
@@ -502,7 +504,7 @@ function createMeshCore(agent) {
504 return;
505 }
506 if ((this.httprequest.terminal) && (obj.useNativePipes == false)) { this.httprequest.terminal.write(data); return; }
505 -
507 +
508 if (this.httprequest.state == 0) {
509 // Check if this is a relay connection
510 if (data == 'c') { this.httprequest.state = 1; sendConsoleText("Tunnel #" + this.httprequest.index + " now active", this.httprequest.sessionid); }
@@ -516,24 +518,26 @@ function createMeshCore(agent) {
518 if (obj.useNativePipes == false) {
519 // Remote Terminal without using native pipes
520 if (process.platform == "win32") {
519 - this.httprequest.terminal = processManager.CreateProcess("%windir%\\system32\\cmd.exe");
521 + this.httprequest.terminal = childProcess.execFile("%windir%\\system32\\cmd.exe");
522 } else {
521 - this.httprequest.terminal = processManager.CreateProcess("/bin/sh", "sh", ILibProcessPipe_SpawnTypes.TERM);
523 + this.httprequest.terminal = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
524 }
525 this.httprequest.terminal.tunnel = this;
524 - this.httprequest.terminal.on('data', function (chunk) { this.tunnel.write(chunk); });
525 - this.httprequest.terminal.error.data = function (chunk) { this.parent.tunnel.write(chunk); }
526 + this.httprequest.terminal.on('exit', function (ecode, sig) { this.tunnel.end(); });
527 + this.httprequest.terminal.stdout.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
528 + this.httprequest.terminal.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
529 } else {
530 // Remote terminal using native pipes
531 if (process.platform == "win32") {
529 - this.httprequest.process = processManager.CreateProcess("%windir%\\system32\\cmd.exe");
532 + this.httprequest.process = childProcess.execFile("%windir%\\system32\\cmd.exe");
533 } else {
531 - this.httprequest.process = processManager.CreateProcess("/bin/sh", "sh", ILibProcessPipe_SpawnTypes.TERM);
534 + this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM });
535 }
536 this.httprequest.process.tunnel = this;
534 - this.httprequest.process.error.data = function (chunk) { this.parent.tunnel.write(chunk); }
535 - this.httprequest.process.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
536 - this.pipe(this.httprequest.process, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
537 + this.httprequest.process.on('exit', function (ecode, sig) { this.tunnel.end(); });
538 + this.httprequest.process.stderr.on('data', function (chunk) { this.parent.tunnel.write(chunk); });
539 + this.httprequest.process.stdout.pipe(this, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
540 + this.pipe(this.httprequest.process.stdin, { dataTypeSkip: 1 }); // 0 = Binary, 1 = Text.
541 }
542 }
543 if (this.httprequest.protocol == 2) {
@@ -604,7 +608,7 @@ function createMeshCore(agent) {
608 var response = getDirectoryInfo(cmd.path);
609 if (cmd.reqid != undefined) { response.reqid = cmd.reqid; }
610 this.write(new Buffer(JSON.stringify(response)));
607 -
611 +
612 /*
613 // Start the directory watcher
614 if ((cmd.path != '') && (samepath == false)) {
@@ -672,17 +676,17 @@ function createMeshCore(agent) {
676 //sendConsoleText("Got tunnel #" + this.httprequest.index + " data: " + data, this.httprequest.sessionid);
677 }
678 }
675 -
679 +
680 // Console state
681 var consoleWebSockets = {};
682 var consoleHttpRequest = null;
679 -
683 +
684 // Console HTTP response
685 function consoleHttpResponse(response) {
686 response.data = function (data) { sendConsoleText(rstr2hex(buf2rstr(data)), this.sessionid); consoleHttpRequest = null; }
687 response.close = function () { sendConsoleText('httprequest.response.close', this.sessionid); consoleHttpRequest = null; }
688 };
685 -
689 +
690 // Process a mesh agent console command
691 function processConsoleCommand(cmd, args, rights, sessionid) {
692 try {
@@ -810,12 +814,14 @@ function createMeshCore(agent) {
814 } else {
815 var httprequest = null;
816 try {
813 - httprequest = http.request(http.parseUri(args['_'][0]));
817 + var options = http.parseUri(args['_'][0]);
818 + options.rejectUnauthorized = 0;
819 + httprequest = http.request(options);
820 } catch (e) { response = 'Invalid HTTP websocket request'; }
821 if (httprequest != null) {
822 httprequest.upgrade = onWebSocketUpgrade;
823 httprequest.onerror = function (e) { sendConsoleText('ERROR: ' + JSON.stringify(e)); }
818 -
824 +
825 var index = 1;
826 while (consoleWebSockets[index]) { index++; }
827 httprequest.sessionid = sessionid;
@@ -949,16 +955,16 @@ function createMeshCore(agent) {
955 } catch (e) { response = 'Command returned an exception error: ' + e; console.log(e); }
956 if (response != null) { sendConsoleText(response, sessionid); }
957 }
952 -
958 +
959 // Send a mesh agent console command
960 function sendConsoleText(text, sessionid) {
961 if (typeof text == 'object') { text = JSON.stringify(text); }
962 mesh.SendCommand({ "action": "msg", "type": "console", "value": text, "sessionid": sessionid });
963 }
958 -
964 +
965 // Called before the process exits
966 //process.exit = function (code) { console.log("Exit with code: " + code.toString()); }
961 -
967 +
968 // Called when the server connection state changes
969 function handleServerConnection(state) {
970 meshServerConnectionState = state;
@@ -974,7 +980,7 @@ function createMeshCore(agent) {
980 //if (selfInfoUpdateTimer == null) { selfInfoUpdateTimer = setInterval(sendPeriodicServerUpdate, 60000); } // Should be a long time, like 20 minutes. For now, 1 minute.
981 }
982 }
977 -
983 +
984 // Build a bunch a self information data that will be sent to the server
985 // We need to do this periodically and if anything changes, send the update to the server.
986 function buildSelfInfo() {
@@ -992,20 +998,20 @@ function createMeshCore(agent) {
998 }
999 return JSON.stringify(r);
1000 }
995 -
1001 +
1002 // Update the server with the latest network interface information
1003 var sendNetworkUpdateNagleTimer = null;
1004 function sendNetworkUpdateNagle() { if (sendNetworkUpdateNagleTimer != null) { clearTimeout(sendNetworkUpdateNagleTimer); sendNetworkUpdateNagleTimer = null; } sendNetworkUpdateNagleTimer = setTimeout(sendNetworkUpdate, 5000); }
1005 function sendNetworkUpdate(force) {
1006 sendNetworkUpdateNagleTimer = null;
1001 -
1007 +
1008 // Update the network interfaces information data
1009 var netInfo = mesh.NetInfo;
1010 netInfo.action = 'netinfo';
1011 var netInfoStr = JSON.stringify(netInfo);
1012 if ((force == true) || (clearGatewayMac(netInfoStr) != clearGatewayMac(lastNetworkInfo))) { mesh.SendCommand(netInfo); lastNetworkInfo = netInfoStr; }
1013 }
1008 -
1014 +
1015 // Called periodically to check if we need to send updates to the server
1016 function sendPeriodicServerUpdate(force) {
1017 if ((amtMeiConnected != 1) || (force == true)) { // If we are pending MEI connection, hold off on updating the server on self-info
@@ -1017,7 +1023,7 @@ function createMeshCore(agent) {
1023 // Update network information
1024 sendNetworkUpdateNagle(force);
1025 }
1020 -
1026 +
1027 // Get Intel AMT information using MEI
1028 function getAmtInfo(func) {
1029 if (amtMei == null || amtMeiConnected != 2) { if (func != null) { func(null); } return; }
@@ -1031,13 +1037,13 @@ function createMeshCore(agent) {
1037 //amtMei.getMACAddresses(function (result) { amtMeiTmpState.mac = result; });
1038 amtMei.getDnsSuffix(function (result) { if (result != null) { amtMeiTmpState.dns = result; } amtMeiState = amtMeiTmpState; sendPeriodicServerUpdate(); if (func != null) { func(amtMeiState); } });
1039 }
1034 -
1040 +
1041 // Called on MicroLMS Intel AMT user notification
1042 function handleAmtNotification(notification) {
1043 var amtMessage = notification.messageId;
1044 var amtMessageArg = notification.messageArguments;
1045 var notify = null;
1040 -
1046 +
1047 switch (amtMessage) {
1048 case 'iAMT0050': {
1049 // Serial over lan
@@ -1063,14 +1069,14 @@ function createMeshCore(agent) {
1069 break;
1070 }
1071 }
1066 -
1072 +
1073 if (notify != null) {
1074 var notification = { "action": "msg", "type": "notify", "value": notify, "tag": "general" };
1075 //mesh.SendCommand(notification); // no sessionid or userid specified, notification will go to the entire mesh
1076 //console.log("handleAmtNotification", JSON.stringify(notification));
1077 }
1078 }
1073 -
1079 +
1080 // Starting function
1081 obj.start = function () {
1082 // Setup the mesh agent event handlers
@@ -1078,14 +1084,14 @@ function createMeshCore(agent) {
1084 mesh.AddConnectHandler(handleServerConnection);
1085 //mesh.lmsNotification = handleAmtNotification; // TODO
1086 sendPeriodicServerUpdate(true); // TODO: Check if connected before sending
1081 -
1087 +
1088 // Parse input arguments
1089 //var args = parseArgs(process.argv);
1090 //console.log(args);
1085 -
1091 +
1092 //console.log('Stopping.');
1093 //process.exit();
1088 -
1094 +
1095 // Launch LMS
1096 try {
1097 var lme_heci = require('lme_heci');
@@ -1095,16 +1101,16 @@ function createMeshCore(agent) {
1101 amtLms.on('connect', function () { amtLmsState = 2; });
1102 } catch (e) { amtLmsState = -1; amtLms = null; }
1103 }
1098 -
1104 +
1105 obj.stop = function () {
1106 mesh.AddCommandHandler(null);
1107 mesh.AddConnectHandler(null);
1108 }
1103 -
1109 +
1110 function onWebSocketClosed() { sendConsoleText("WebSocket #" + this.httprequest.index + " closed.", this.httprequest.sessionid); delete consoleWebSockets[this.httprequest.index]; }
1111 function onWebSocketData(data) { sendConsoleText("Got WebSocket #" + this.httprequest.index + " data: " + data, this.httprequest.sessionid); }
1112 function onWebSocketSendOk() { sendConsoleText("WebSocket #" + this.index + " SendOK.", this.sessionid); }
1107 -
1113 +
1114 function onWebSocketUpgrade(response, s, head) {
1115 sendConsoleText("WebSocket #" + this.index + " connected.", this.sessionid);
1116 this.s = s;
@@ -1112,7 +1118,7 @@ function createMeshCore(agent) {
1118 s.end = onWebSocketClosed;
1119 s.data = onWebSocketData;
1120 }
1115 -
1121 +
1122 return obj;
1123 }
1124
agents/tinycore.js
+1 -1
@@ -1,5 +1,5 @@
1 /*
2 -Copyright 2017 Intel Corporation
2 +Copyright 2018 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
amtevents.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral Intel AMT Event Parser
2 +* @description MeshCentral Intel(R) AMT Event Parser
3 * @author Ylian Saint-Hilaire & Bryan Roe
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
amtscanner.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral Intel AMT Local Scanner
2 +* @description MeshCentral Intel(R) AMT Local Scanner
3 * @author Ylian Saint-Hilaire & Joko Sastriawan
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
amtscript.js
+2
@@ -1,6 +1,8 @@
1 /**
2 * @fileoverview Script Compiler / Decompiler / Runner
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.1.0e
7 */
8
certoperations.js
+3
@@ -1,8 +1,11 @@
1 /**
2 * @description Certificate generator
3 * @author Joko Sastriawan / Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8 +
9 module.exports.CertificateOperations = function () {
10 var obj = {};
11
common.js
+8 -1
@@ -1,4 +1,11 @@
1 -
1 +/**
2 +* @description MeshCentral Common Library
3 +* @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 +* @version v0.0.1
7 +*/
8 +
9 var crypto = require('crypto');
10
11 // Binary encoding and decoding functions
db.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral database
2 +* @description MeshCentral database module
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.2
7 */
8
interceptor.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Intel AMT Interceptor
2 +* @description MeshCentral Intel(R) AMT Interceptor
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.3
7 */
8
meshagent.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral MeshAgent
2 +* @description MeshCentral MeshAgent communication module
3 * @author Ylian Saint-Hilaire & Bryan Roe
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
meshcentral.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral
2 +* @description MeshCentral main module
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
meshmail.js
+11 -2
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral MeshMail
2 +* @description MeshCentral e-mail server communication modules
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
@@ -32,7 +34,14 @@ module.exports.CreateMeshMain = function (parent) {
34
35 // Perform all e-mail substitution
36 function mailReplacements(text, domain, username, email, cookie) {
35 - var url = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + parent.certificates.CommonName + ':' + obj.parent.args.port + domain.url;
37 + var url;
38 + if (domain.dns == null) {
39 + // Default domain or subdomain of the default.
40 + url = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + parent.certificates.CommonName + ':' + obj.parent.args.port + domain.url;
41 + } else {
42 + // Domain with a DNS name.
43 + url = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + domain.dns + ':' + obj.parent.args.port + domain.url;
44 + }
45 if (cookie != null) { text = text.split('[[[CALLBACKURL]]]').join(url + 'checkmail?c=' + cookie) }
46 return text.split('[[[USERNAME]]]').join(username).split('[[[SERVERURL]]]').join(url).split('[[[SERVERNAME]]]').join(domain.title);
47 }
meshrelay.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral MeshRelay
2 +* @description MeshCentral connection relay module
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
meshscanner.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral Mesh Agent Local Scanner
2 +* @description MeshCentral Mesh Agent Local Scanner
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
meshuser.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral MeshAgent
2 +* @description MeshCentral MeshAgent
3 * @author Ylian Saint-Hilaire & Bryan Roe
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
mpsserver.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral Intel AMT MPS server
2 +* @description MeshCentral Intel(R) AMT MPS server
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
multiserver.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral Multi-Server Support
2 +* @description MeshCentral Multi-Server Support
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.1.1-r",
3 + "version": "0.1.1-u",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
readme.txt
+1
@@ -2,6 +2,7 @@ MeshCentral
2 ===========
3
4 For more information, [visit MeshCommander.com/MeshCentral2](http://www.meshcommander.com/meshcentral2).
5 +
6 Download the [full PDF user's guide](http://info.meshcentral.com/downloads/meshcentral2/MeshCentral2UserGuide.pdf) with more information on installing, configuring and running MeshCentral2.
7
8 This is a full computer management web site. With MeshCentral, you can run your own web server and it to remotely manage and control computers on a local network or anywhere on the internet. Once you get the server started, will create a mesh (a group of computers) and then download and install a mesh agent on each computer you want to manage. A minute later, the new computer will show up on the web site and you can take control of it, etc. MeshCentral includes full web-based remote desktop, terminal and file management capability.
redirserver.js
+2
@@ -1,6 +1,8 @@
1 /**
2 * @description Meshcentral web server
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
swarmserver.js
+3 -1
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral1 legacy swarm server, used to update agents and get them on MeshCentral2
2 +* @description MeshCentral v1 legacy Swarm Server, used to update agents and get them on MeshCentral2
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
webserver.js
+6 -3
@@ -1,6 +1,8 @@
1 /**
2 -* @description Meshcentral web server
2 +* @description MeshCentral web server
3 * @author Ylian Saint-Hilaire
4 +* @copyright Intel Corporation 2018
5 +* @license Apache-2.0
6 * @version v0.0.1
7 */
8
@@ -126,8 +128,8 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
128 {
129 var dnscount = 0;
130 obj.tlsSniCredentials = {};
129 - for (var i in obj.certificates.dns) { if (obj.parent.config.domains[i].dns != null) { obj.dnsDomains[obj.parent.config.domains[i].dns.toLowerCase()] = obj.parent.config.domains[i]; obj.tlsSniCredentials[obj.parent.config.domains[i].dns] = obj.crypto.createCredentials(obj.certificates.dns[i]).context; dnscount++; } }
130 - if (dnscount > 0) { obj.tlsSniCredentials[''] = obj.crypto.createCredentials({ cert: obj.certificates.web.cert, key: obj.certificates.web.key, ca: obj.certificates.ca }).context; } else { obj.tlsSniCredentials = null; }
131 + for (var i in obj.certificates.dns) { if (obj.parent.config.domains[i].dns != null) { obj.dnsDomains[obj.parent.config.domains[i].dns.toLowerCase()] = obj.parent.config.domains[i]; obj.tlsSniCredentials[obj.parent.config.domains[i].dns] = obj.tls.createSecureContext(obj.certificates.dns[i]).context; dnscount++; } }
132 + if (dnscount > 0) { obj.tlsSniCredentials[''] = obj.tls.createSecureContext({ cert: obj.certificates.web.cert, key: obj.certificates.web.key, ca: obj.certificates.ca }).context; } else { obj.tlsSniCredentials = null; }
133 }
134 function TlsSniCallback(name, cb) { var c = obj.tlsSniCredentials[name]; if (c != null) { cb(null, c); } else { cb(null, obj.tlsSniCredentials['']); } }
135
@@ -1535,6 +1537,7 @@ module.exports.CreateWebServer = function (parent, db, args, secret, certificate
1537 obj.app.post('/restoreserver.ashx', handleRestoreRequest);
1538 if (parent.multiServer != null) { obj.app.ws('/meshserver.ashx', function (ws, req) { parent.multiServer.CreatePeerInServer(parent.multiServer, ws, req); } ); }
1539 for (var i in parent.config.domains) {
1540 + if (parent.config.domains[i].dns != null) { continue; } // This is a subdomain with a DNS name, no added HTTP bindings needed.
1541 var url = parent.config.domains[i].url;
1542 obj.app.get(url, handleRootRequest);
1543 obj.app.get(url + 'terms', handleTermsRequest);