Fixed GreenLock v4

Ylian Saint-Hilaire committed Jan 25, 2020 at 12:14 UTC 5d4cf20e49eccff4f049a6a8a3490fa80ef1c95d
6 files changed +17 -26
agents/meshcore.js
+8 -21
@@ -39,7 +39,8 @@ var MESHRIGHT_LIMITEDINPUT = 4096;
39
40 function createMeshCore(agent) {
41 var obj = {};
42 - if (process.platform == 'win32' && require('user-sessions').isRoot()) {
42 + if (process.platform == 'win32' && require('user-sessions').isRoot())
43 + {
44 // Check the Agent Uninstall MetaData for correctness, as the installer may have written an incorrect value
45 try {
46 var writtenSize = 0, actualSize = Math.floor(require('fs').statSync(process.execPath).size / 1024);
@@ -1198,8 +1199,7 @@ function createMeshCore(agent) {
1199 this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false });
1200 this.prependListener('end', function () { this.httprequest._term.end(function () { console.log("Terminal was closed"); }); });
1201 }
1201 - }
1202 - else {
1202 + } else {
1203 try {
1204 var bash = fs.existsSync('/bin/bash') ? '/bin/bash' : false;
1205 var sh = fs.existsSync('/bin/sh') ? '/bin/sh' : false;
@@ -1223,28 +1223,21 @@ function createMeshCore(agent) {
1223 var options = { uid: (this.httprequest.protocol == 8) ? require('user-sessions').consoleUid() : null, env: env };
1224 var setupcommands = ' alias ls=\'ls --color=auto\'\n';
1225 if (shell == sh) setupcommands += ' stty erase ^H\n';
1226 + setupcommands += ' clear\n';
1227
1228 if (script && shell && process.platform == 'linux') {
1229 this.httprequest.process = childProcess.execFile(script, ['script', '--return', '--quiet', '-c', '"' + shell + '"', '/dev/null'], options); // Start as active user
1229 - // Is child process the shell? Needed for resizing.
1230 - this.httprequest.process.isChildShell = true;
1230 this.httprequest.process.stdin.write(setupcommands);
1231 } else if (python && shell) {
1232 this.httprequest.process = childProcess.execFile(python, ['python', '-c', 'import pty; pty.spawn(["' + shell + '"])'], options); // Start as active user
1234 - // Is child process the shell? Needed for resizing.
1235 - this.httprequest.process.isChildShell = true;
1233 if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
1234 } else if (bash) {
1235 options.type = childProcess.SpawnTypes.TERM;
1236 this.httprequest.process = childProcess.execFile(bash, ['bash', '-i'], options); // Start as active user
1240 - // Is child process the shell? Needed for resizing.
1241 - this.httprequest.process.isChildShell = false;
1237 if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands); }
1238 } else if (sh) {
1239 options.type = childProcess.SpawnTypes.TERM;
1240 this.httprequest.process = childProcess.execFile(sh, ['sh'], options); // Start as active user
1246 - // Is child process the shell? Needed for resizing.
1247 - this.httprequest.process.isChildShell = false;
1241 if (process.platform == 'linux') { this.httprequest.process.stdin.write(setupcommands + "PS1='$ '\n"); }
1242 } else {
1243 MeshServerLog("Failed to start remote terminal session, no shell found");
@@ -1797,15 +1790,8 @@ function createMeshCore(agent) {
1790 // TODO
1791 } else {
1792 if (ws.httprequest.process == null) return;
1800 - // ILibDuktape_ChildProcess kill doesn't support sending signals
1801 - if (fs.existsSync("/bin/kill"))
1802 - {
1803 - if (ws.httprequest.process.isChildShell)
1804 - // We need to send signal to the child of the process, since the child is the shell
1805 - childProcess.execFile('/bin/bash', ['bash', "-c", "kill -SIGWINCH $(pgrep -P " + ws.httprequest.process.pid + ")"]);
1806 - else
1807 - childProcess.execFile('/bin/bash', ['bash', "-c", "kill -SIGWINCH " + ws.httprequest.process.pid]);
1808 - }
1793 + //sendConsoleText('Linux-TermSize: ' + obj.cols + 'x' + obj.rows);
1794 + // TODO
1795 }
1796 }
1797 break;
@@ -2239,7 +2225,8 @@ function createMeshCore(agent) {
2225 break;
2226 }
2227 case 'ps': {
2242 - processManager.getProcesses(function (plist) {
2228 + processManager.getProcesses(function (plist)
2229 + {
2230 var x = '';
2231 for (var i in plist) { x += i + ((plist[i].user) ? (', ' + plist[i].user) : '') + ', ' + plist[i].cmd + '\r\n'; }
2232 sendConsoleText(x, sessionid);
letsEncrypt.js
+4 -1
@@ -14,6 +14,8 @@
14 /*jshint esversion: 6 */
15 'use strict';
16
17 +var globalLetsEncrypt = null;
18 +
19 module.exports.CreateLetsEncrypt = function (parent) {
20 try {
21 // Get the GreenLock version
@@ -40,6 +42,7 @@ module.exports.CreateLetsEncrypt = function (parent) {
42 // Get GreenLock setup and running.
43 const greenlock = require('greenlock');
44 var obj = {};
45 + globalLetsEncrypt = obj;
46 obj.parent = parent;
47 obj.path = require('path');
48 obj.redirWebServerHooked = false;
@@ -258,7 +261,7 @@ module.exports.CreateLetsEncrypt = function (parent) {
261
262 // GreenLock v3 Manager
263 module.exports.create = function (options) {
261 - var manager = { parent: options.parent };
264 + var manager = { parent: globalLetsEncrypt };
265 manager.find = async function (options) {
266 //console.log('LE-FIND', options);
267 return Promise.resolve([{ subject: options.servername, altnames: options.altnames }]);
meshcentral.js
+1 -1
@@ -2256,7 +2256,7 @@ function mainStart() {
2256 var modules = ['ws', 'cbor', 'nedb', 'https', 'yauzl', 'xmldom', 'ipcheck', 'express', 'archiver', 'multiparty', 'node-forge', 'express-ws', 'compression', 'body-parser', 'connect-redis', 'cookie-session', 'express-handlebars'];
2257 if (require('os').platform() == 'win32') { modules.push('node-windows'); if (sspi == true) { modules.push('node-sspi'); } } // Add Windows modules
2258 if (ldap == true) { modules.push('ldapauth-fork'); }
2259 - if (config.letsencrypt != null) { if ((nodeVersion < 10) || (require('crypto').generateKeyPair == null)) { addServerWarning("Let's Encrypt support requires Node v10.12 or higher.", !args.launch); } else { modules.push('greenlock@3.1.5'); } } // Add Greenlock Module
2259 + if (config.letsencrypt != null) { if ((nodeVersion < 10) || (require('crypto').generateKeyPair == null)) { addServerWarning("Let's Encrypt support requires Node v10.12 or higher.", !args.launch); } else { modules.push('greenlock'); } } // Add Greenlock Module
2260 if (config.settings.mqtt != null) { modules.push('aedes'); } // Add MQTT Modules
2261 if (config.settings.mongodb != null) { modules.push('mongodb'); } // Add MongoDB, official driver.
2262 if (config.settings.vault != null) { modules.push('node-vault'); } // Add official HashiCorp's Vault module.
package.json
+2 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.4.7-u",
3 + "version": "0.4.7-v",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
@@ -37,6 +37,7 @@
37 "express": "^4.17.0",
38 "express-handlebars": "^3.1.0",
39 "express-ws": "^4.0.0",
40 + "greenlock": "^4.0.4",
41 "ipcheck": "^0.1.0",
42 "meshcentral": "*",
43 "minimist": "^1.2.0",
views/xterm.handlebars
-1
@@ -180,7 +180,6 @@
180 break;
181 case 3:
182 // Connected
183 - tunnel.sendText(`mcresize() { old=$(stty -g);stty raw -echo min 0 time 5;printf '\\0337\\033[r\\033[999;999H\\033[6n\\0338' > /dev/tty;IFS='[;R' read -r _ rows cols _ < /dev/tty;stty "$old";stty cols "$cols" rows "$rows"; };trap mcresize SIGWINCH;clear\n`);
183 term.focus();
184 break;
185 default:
webserver.js
+2 -1
@@ -3403,7 +3403,8 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
3403 if (obj.tlsSniCredentials != null) { tlsOptions.SNICallback = TlsSniCallback; } // We have multiple web server certificate used depending on the domain name
3404 obj.tlsServer = require('https').createServer(tlsOptions, obj.app);
3405 obj.tlsServer.on('secureConnection', function () { /*console.log('tlsServer secureConnection');*/ });
3406 - obj.tlsServer.on('error', function () { console.log('tlsServer error'); });
3406 + obj.tlsServer.on('error', function (err) { console.log('tlsServer error', err); });
3407 + //obj.tlsServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
3408 obj.tlsServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
3409 obj.tlsServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
3410 obj.expressWs = require('express-ws')(obj.app, obj.tlsServer);