From f4009a1b6eb8fe62eb8db269ea3be682ce7d7a72 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 10 Mar 2019 11:00:14 -0700 Subject: [PATCH] Fixed server exceptions, email alias port. --- meshagent.js | 9 ++++++++- meshcentral.js | 2 +- meshmail.js | 5 +++-- package.json | 3 ++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/meshagent.js b/meshagent.js index 4d0b68ec..539a9fc7 100644 --- a/meshagent.js +++ b/meshagent.js @@ -84,6 +84,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if (obj.agentUpdate != null) { if (obj.agentUpdate.fd) { try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { } } parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } @@ -241,6 +242,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Error reading the agent file, stop here. try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { } parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } else { // Send the first block to the agent @@ -276,6 +278,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { } else { // Error parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } } @@ -301,6 +304,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Error reading the agent file, stop here. try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { } parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } else { // Send the next block to the agent @@ -312,6 +316,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { obj.send(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash try { parent.fs.close(obj.agentUpdate.fd); } catch (ex) { } parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } } @@ -329,6 +334,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { //console.log("Agent update sent from RAM."); obj.send(common.ShortToStr(13) + common.ShortToStr(0) + obj.agentExeInfo.hash); // Command 13, end mesh agent download, send agent SHA384 hash parent.parent.taskLimiter.completed(obj.agentUpdate.taskid); // Indicate this task complete + delete obj.agentUpdate.buf; delete obj.agentUpdate; } } @@ -513,7 +519,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Once we get all the information about an agent, run this to hook everything up to the server function completeAgentConnection() { - if ((obj.authenticated != 1) || (obj.meshid == null) || obj.pendingCompleteAgentConnection) return; + if ((obj.authenticated != 1) || (obj.meshid == null) || obj.pendingCompleteAgentConnection || (obj.agentExeInfo == null)) return; obj.pendingCompleteAgentConnection = true; // Check if we have too many agent sessions @@ -562,6 +568,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { // Check that the node exists db.Get(obj.dbNodeKey, function (err, nodes) { + if (obj.agentExeInfo == null) { return; } // Agent has disconnected var device; // See if this node exists in the database diff --git a/meshcentral.js b/meshcentral.js index a6d9f51b..0d562139 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -1607,7 +1607,7 @@ function InstallModule(modulename, func, tag1, tag2) { console.log('Installing ' + modulename + '...'); var child_process = require('child_process'); child_process.exec('npm install ' + modulename + ' --no-optional --save', { maxBuffer: 512000 }, function (error, stdout, stderr) { - if (error != null) { console.log('ERROR: Unable to install missing package \'' + modulename + '\', make sure npm is installed.'); process.exit(); return; } + if (error != null) { console.log('ERROR: Unable to install missing package \'' + modulename + '\', make sure npm is installed: ' + error); process.exit(); return; } func(tag1, tag2); return; }); diff --git a/meshmail.js b/meshmail.js index 67486af9..d54ff90a 100644 --- a/meshmail.js +++ b/meshmail.js @@ -102,12 +102,13 @@ module.exports.CreateMeshMail = function (parent) { // Perform all e-mail substitution function mailReplacements(text, domain, options) { + var httpsport = (typeof obj.parent.args.aliasport == 'number') ? obj.parent.args.aliasport : obj.parent.args.port; if (domain.dns == null) { // Default domain or subdomain of the default. - options.serverurl = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + obj.parent.certificates.CommonName + ':' + obj.parent.args.port + domain.url; + options.serverurl = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + obj.parent.certificates.CommonName + ':' + httpsport + domain.url; } else { // Domain with a DNS name. - options.serverurl = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + domain.dns + ':' + obj.parent.args.port + domain.url; + options.serverurl = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + domain.dns + ':' + httpsport + domain.url; } if (options.serverurl.endsWith('/')) { options.serverurl = options.serverurl.substring(0, options.serverurl.length - 1); } // Remove the ending / if present for (var i in options) { diff --git a/package.json b/package.json index d7a2b43b..8e8fe9cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.0-b", + "version": "0.3.0-c", "keywords": [ "Remote Management", "Intel AMT", @@ -41,6 +41,7 @@ "multiparty": "^4.2.1", "nedb": "^1.8.0", "node-forge": "^0.7.6", + "nodemailer": "^5.1.1", "otplib": "^10.0.1", "util.promisify": "^1.0.0", "ws": "^6.1.2",