Added multi-interface mesh server scanner

Ylian Saint-Hilaire committed Sep 4, 2017 at 12:20 UTC 20c836db0d943ab299ea60fbe364effaf8ab22ad
3 files changed +21 -6
agents/meshinstall-linux.sh
+11 -1
@@ -9,6 +9,15 @@ CheckStartupType() {
9 return 0;
10 }
11
12 +# Add "StartupType=(type)" to .msh file
13 +UpdateMshFile() {
14 + # Remove all lines that start with "StartupType="
15 + sed '/^StartupType=/ d' < /usr/local/mesh/meshagent.msh >> /usr/local/mesh/meshagent2.msh
16 + # Add the startup type to the file
17 + echo "StartupType=$starttype" >> /usr/local/mesh/meshagent2.msh
18 + mv /usr/local/mesh/meshagent2.msh /usr/local/mesh/meshagent.msh
19 +}
20 +
21 CheckInstallAgent() {
22 # echo "Checking mesh identifier..."
23 if [ -e "/usr/local" ]
@@ -70,11 +79,12 @@ DownloadAgent() {
79 if [ $? -eq 0 ]
80 then
81 echo "Mesh agent download."
73 -# TODO: Check meshagent sha256 hash
82 +# TODO: We could check the meshagent sha256 hash, but best to authenticate the server.
83 chmod 755 /usr/local/mesh/meshagent
84 wget $url/meshsettings?id=$meshid -q --no-check-certificate -O /usr/local/mesh/meshagent.msh
85 if [ $? -eq 0 ]
86 then
87 + UpdateMshFile
88 if [ $starttype -eq 1 ]
89 then
90 echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\n[Install]\nWantedBy=multi-user.target\nAlias=meshcentral.service\n" > /lib/systemd/system/meshcentral.service
meshcentral.js
+9 -4
@@ -118,16 +118,21 @@ function CreateMeshCentralServer() {
118 obj.launchChildServer = function (startLine) {
119 var child_process = require('child_process');
120 var xprocess = child_process.exec(startLine + ' --launch', function (error, stdout, stderr) {
121 - if (xprocess.xrestart == true) {
122 - setTimeout(function () { obj.launchChildServer(startLine); }, 500); // If exit with restart requested, restart the server.
121 + console.log(xprocess.xrestart);
122 + if (xprocess.xrestart == 1) {
123 + setTimeout(function () { obj.launchChildServer(startLine); }, 500); // This is an expected restart.
124 + } else if (xprocess.xrestart == 2) {
125 + console.log('Expected exit...');
126 + process.exit(); // User CTRL-C exit.
127 } else {
128 if (error != null) {
129 + // This is an un-expected restart
130 console.log('ERROR: MeshCentral failed with critical error, restarting...');
131 setTimeout(function () { obj.launchChildServer(startLine); }, 1000);
132 }
133 }
134 });
130 - xprocess.stdout.on('data', function (data) { if (data[data.length - 1] == '\n') { data = data.substring(0, data.length - 1); } if (data.indexOf('Updating settings folder...') >= 0) { xprocess.xrestart = true; } console.log(data); });
135 + xprocess.stdout.on('data', function (data) { if (data[data.length - 1] == '\n') { data = data.substring(0, data.length - 1); } if (data.indexOf('Updating settings folder...') >= 0) { xprocess.xrestart = 1; } else if (data.indexOf('Server Ctrl-C exit...') >= 0) { xprocess.xrestart = 2; } console.log(data); });
136 xprocess.stderr.on('data', function (data) { if (data[data.length - 1] == '\n') { data = data.substring(0, data.length - 1); } obj.fs.appendFileSync('mesherrors.txt', '-------- ' + new Date().toLocaleString() + ' --------\r\n\r\n' + data + '\r\n\r\n\r\n'); });
137 xprocess.on('close', function (code) { if ((code != 0) && (code != 123)) { /* console.log("Exited with code " + code); */ } });
138 }
@@ -650,7 +655,7 @@ function InstallModule(modulename, func, tag1, tag2) {
655 }
656
657 // Detect CTRL-C on Linux and stop nicely
653 -process.on('SIGINT', function () { if (meshserver != null) { meshserver.Stop(); meshserver = null; } });
658 +process.on('SIGINT', function () { if (meshserver != null) { meshserver.Stop(); meshserver = null; } console.log('Server Ctrl-C exit...'); process.exit(); });
659
660 // Build the list of required modules
661 var modules = ['nedb', 'https', 'unzip', 'xmldom', 'express', 'mongojs', 'archiver', 'minimist', 'multiparty', 'node-forge', 'express-ws', 'compression', 'body-parser', 'connect-redis', 'express-session', 'express-handlebars'];
redirserver.js
+1 -1
@@ -22,7 +22,7 @@ module.exports.CreateRedirServer = function (parent, db, args, certificates) {
22 // Perform an HTTP to HTTPS redirection
23 function performRedirection(req, res) {
24 var host = certificates.CommonName;
25 - if (certificates.CommonName == 'sample.org') { host = req.headers.host; }
25 + if ((certificates.CommonName == 'sample.org') || (certificates.CommonName == 'un-configured')) { host = req.headers.host; }
26 if (req.headers && req.headers.host && (req.headers.host.split(':')[0].toLowerCase() == 'localhost')) { res.redirect('https://localhost:' + args.port + req.url); } else { res.redirect('https://' + host + ':' + args.port + req.url); }
27 }
28