From d30b5f348e800b7d1cc981106ff3a5706d32b58b Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 29 Nov 2018 17:59:29 -0800 Subject: [PATCH] Added messenger web application. --- letsEncrypt.js | 2 +- meshcentral.js | 6 +++ package.json | 6 ++- public/messenger.htm | 106 +++++++++++++++++++++++++++++++++++++++++++ redirserver.js | 19 +++++--- 5 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 public/messenger.htm diff --git a/letsEncrypt.js b/letsEncrypt.js index d1149c25..789ad12c 100644 --- a/letsEncrypt.js +++ b/letsEncrypt.js @@ -125,6 +125,6 @@ module.exports.CreateLetsEncrypt = function (parent) { }; return obj; - } catch (e) { console.error(e); } // Unable to start Let's Encrypt + } catch (ex) { console.log(ex); } // Unable to start Let's Encrypt return null; }; \ No newline at end of file diff --git a/meshcentral.js b/meshcentral.js index ff047a30..d72d71d2 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -14,6 +14,9 @@ /*jshint esversion: 6 */ "use strict"; +// If running NodeJS less than version 8, try to polyfill promisify +try { if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 8) { require('util.promisify').shim(); } } catch (ex) { } + // If app metrics is available if (process.argv[2] == '--launch') { try { require('appmetrics-dash').monitor({ url: '/', title: 'MeshCentral', port: 88, host: '127.0.0.1' }); } catch (e) { } } @@ -1277,6 +1280,9 @@ function mainStart(args) { if (config.settings.mongodb != null) { modules.push('mongojs'); } // Add MongoDB if (config.smtp != null) { modules.push('nodemailer'); } // Add SMTP support + // If running NodeJS < 8, install "util.promisify" + if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 8) { modules.push('util.promisify'); } + // Install any missing modules and launch the server InstallModules(modules, function () { meshserver = CreateMeshCentralServer(config, args); meshserver.Start(); }); }); diff --git a/package.json b/package.json index 2b99bd2a..5a34ac1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.2.3-o", + "version": "0.2.3-r", "keywords": [ "Remote Management", "Intel AMT", @@ -35,12 +35,16 @@ "express-handlebars": "^3.0.0", "express-session": "^1.15.6", "express-ws": "^3.0.0", + "greenlock": "^2.4.10", + "le-acme-core": "^2.1.4", + "le-store-certbot": "^2.2.1", "meshcentral": "*", "minimist": "^1.2.0", "multiparty": "^4.2.1", "nedb": "^1.8.0", "node-forge": "^0.7.6", "nodemailer": "^4.7.0", + "util.promisify": "^1.0.0", "ws": "^6.1.2", "xmldom": "^0.1.27", "yauzl": "^2.9.1" diff --git a/public/messenger.htm b/public/messenger.htm new file mode 100644 index 00000000..28401d82 --- /dev/null +++ b/public/messenger.htm @@ -0,0 +1,106 @@ + + + + + + + + + + +
Messenger
+
+
+
+
+
+ + +
+ + + diff --git a/redirserver.js b/redirserver.js index d68becf7..523a5d06 100644 --- a/redirserver.js +++ b/redirserver.js @@ -52,13 +52,18 @@ module.exports.CreateRedirServer = function (parent, db, args, func) { // Renter the terms of service. obj.app.get("/MeshServerRootCert.cer", function (req, res) { - res.set({ "Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0", "Content-Type": "application/octet-stream", "Content-Disposition": "attachment; filename=" + obj.certificates.RootName + ".cer" }); - var rootcert = obj.certificates.root.cert; - var i = rootcert.indexOf("-----BEGIN CERTIFICATE-----\r\n"); - if (i >= 0) { rootcert = rootcert.substring(i + 29); } - i = rootcert.indexOf("-----END CERTIFICATE-----"); - if (i >= 0) { rootcert = rootcert.substring(i, 0); } - res.send(new Buffer(rootcert, "base64")); + // The redirection server starts before certificates are loaded, make sure to handle the case where no certificate is loaded now. + if (obj.certificates != null) { + res.set({ "Cache-Control": "no-cache, no-store, must-revalidate", "Pragma": "no-cache", "Expires": "0", "Content-Type": "application/octet-stream", "Content-Disposition": "attachment; filename=" + obj.certificates.RootName + ".cer" }); + var rootcert = obj.certificates.root.cert; + var i = rootcert.indexOf("-----BEGIN CERTIFICATE-----\r\n"); + if (i >= 0) { rootcert = rootcert.substring(i + 29); } + i = rootcert.indexOf("-----END CERTIFICATE-----"); + if (i >= 0) { rootcert = rootcert.substring(i, 0); } + res.send(new Buffer(rootcert, "base64")); + } else { + res.sendStatus(404); + } }); // Add HTTP security headers to all responses