mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-02-15 04:21:51 +00:00
Added Let's Encrypt logging.
This commit is contained in:
parent
4bb65bea4b
commit
bdbc755c35
2 changed files with 27 additions and 12 deletions
|
@ -16,7 +16,14 @@
|
||||||
|
|
||||||
module.exports.CreateLetsEncrypt = function (parent) {
|
module.exports.CreateLetsEncrypt = function (parent) {
|
||||||
try {
|
try {
|
||||||
parent.debug('cert', "Initializing Let's Encrypt support");
|
// Get the GreenLock version
|
||||||
|
var greenLockVersion = null;
|
||||||
|
try { greenLockVersion = require('greenlock/package.json').version; } catch (ex) { }
|
||||||
|
if (greenLockVersion == null) {
|
||||||
|
parent.debug('cert', "Initializing Let's Encrypt support");
|
||||||
|
} else {
|
||||||
|
parent.debug('cert', "Initializing Let's Encrypt support, using GreenLock v" + greenLockVersion);
|
||||||
|
}
|
||||||
|
|
||||||
// Check the current node version
|
// Check the current node version
|
||||||
if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 8) { return null; }
|
if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 8) { return null; }
|
||||||
|
@ -206,7 +213,8 @@ module.exports.CreateLetsEncrypt = function (parent) {
|
||||||
|
|
||||||
// Check if we need to renew the certificate, call this every day.
|
// Check if we need to renew the certificate, call this every day.
|
||||||
obj.checkRenewCertificate = function () {
|
obj.checkRenewCertificate = function () {
|
||||||
parent.debug('cert', "Checking certs (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
|
parent.debug('cert', "Checking certs for " + obj.leDomains[0] + " (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
|
||||||
|
obj.certCheckStart = Date.now();
|
||||||
|
|
||||||
// Setup renew options
|
// Setup renew options
|
||||||
var renewOptions = { servername: obj.leDomains[0] };
|
var renewOptions = { servername: obj.leDomains[0] };
|
||||||
|
@ -214,17 +222,24 @@ module.exports.CreateLetsEncrypt = function (parent) {
|
||||||
const xle = (obj.runAsProduction === true)? obj.le : obj.leStaging;
|
const xle = (obj.runAsProduction === true)? obj.le : obj.leStaging;
|
||||||
xle.renew(renewOptions)
|
xle.renew(renewOptions)
|
||||||
.then(function (results) {
|
.then(function (results) {
|
||||||
parent.debug('cert', "Checks completed (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
|
if ((results == null) || (typeof results != 'object') || (results.length == 0) || (results[0].error != null)) {
|
||||||
if (obj.performRestart === true) { parent.debug('cert', "Certs changed, restarting..."); obj.parent.performServerCertUpdate(); } // Reset the server, TODO: Reset all peers
|
parent.debug('cert', "Unable to get a certificate (" + (obj.runAsProduction ? "Production" : "Staging") + ", " + (Date.now() - obj.certCheckStart) + "ms): " + JSON.stringify(results));
|
||||||
else if (obj.performMoveToProduction == true) {
|
} else {
|
||||||
parent.debug('cert', "Staging certificate received, moving to production...");
|
parent.debug('cert', "Checks completed (" + (obj.runAsProduction ? "Production" : "Staging") + ", " + (Date.now() - obj.certCheckStart) + "ms): " + JSON.stringify(results));
|
||||||
obj.runAsProduction = true;
|
if (obj.performRestart === true) { parent.debug('cert', "Certs changed, restarting..."); obj.parent.performServerCertUpdate(); } // Reset the server, TODO: Reset all peers
|
||||||
obj.performMoveToProduction = false;
|
else if (obj.performMoveToProduction == true) {
|
||||||
obj.performRestart = true;
|
parent.debug('cert', "Staging certificate received, moving to production...");
|
||||||
setTimeout(obj.checkRenewCertificate, 10000); // Check the certificate in 10 seconds.
|
obj.runAsProduction = true;
|
||||||
|
obj.performMoveToProduction = false;
|
||||||
|
obj.performRestart = true;
|
||||||
|
setTimeout(obj.checkRenewCertificate, 10000); // Check the certificate in 10 seconds.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function (e) { console.log(e); });
|
.catch(function (ex) {
|
||||||
|
parent.debug('cert', "checkRenewCertificate exception: (" + JSON.stringify(ex) + ")");
|
||||||
|
console.log(ex);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "meshcentral",
|
"name": "meshcentral",
|
||||||
"version": "0.4.4-j",
|
"version": "0.4.4-k",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Remote Management",
|
"Remote Management",
|
||||||
"Intel AMT",
|
"Intel AMT",
|
||||||
|
|
Loading…
Reference in a new issue