Added Let's Encrypt logging.
Ylian Saint-Hilaire committed
Nov 18, 2019 at 11:42 UTC
22c55cfd145760cc8d58f68187bc15f01117fed4
2 files changed
+27
-12
letsEncrypt.js
+26
-11
@@ -16,7 +16,14 @@
16
17
module.exports.CreateLetsEncrypt = function (parent) {
18
try {
19
- parent.debug('cert', "Initializing Let's Encrypt support");
19
+ // Get the GreenLock version
20
+ var greenLockVersion = null;
21
+ try { greenLockVersion = require('greenlock/package.json').version; } catch (ex) { }
22
+ if (greenLockVersion == null) {
23
+ parent.debug('cert', "Initializing Let's Encrypt support");
24
+ } else {
25
+ parent.debug('cert', "Initializing Let's Encrypt support, using GreenLock v" + greenLockVersion);
26
+ }
27
28
// Check the current node version
29
if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) < 8) { return null; }
@@ -206,7 +213,8 @@ module.exports.CreateLetsEncrypt = function (parent) {
213
214
// Check if we need to renew the certificate, call this every day.
215
obj.checkRenewCertificate = function () {
209
- parent.debug('cert', "Checking certs (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
216
+ parent.debug('cert', "Checking certs for " + obj.leDomains[0] + " (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
217
+ obj.certCheckStart = Date.now();
218
219
// Setup renew options
220
var renewOptions = { servername: obj.leDomains[0] };
@@ -214,17 +222,24 @@ module.exports.CreateLetsEncrypt = function (parent) {
222
const xle = (obj.runAsProduction === true)? obj.le : obj.leStaging;
223
xle.renew(renewOptions)
224
.then(function (results) {
217
- parent.debug('cert', "Checks completed (" + (obj.runAsProduction ? "Production" : "Staging") + ")");
218
- if (obj.performRestart === true) { parent.debug('cert', "Certs changed, restarting..."); obj.parent.performServerCertUpdate(); } // Reset the server, TODO: Reset all peers
219
- else if (obj.performMoveToProduction == true) {
220
- parent.debug('cert', "Staging certificate received, moving to production...");
221
- obj.runAsProduction = true;
222
- obj.performMoveToProduction = false;
223
- obj.performRestart = true;
224
- setTimeout(obj.checkRenewCertificate, 10000); // Check the certificate in 10 seconds.
225
+ if ((results == null) || (typeof results != 'object') || (results.length == 0) || (results[0].error != null)) {
226
+ parent.debug('cert', "Unable to get a certificate (" + (obj.runAsProduction ? "Production" : "Staging") + ", " + (Date.now() - obj.certCheckStart) + "ms): " + JSON.stringify(results));
227
+ } else {
228
+ parent.debug('cert', "Checks completed (" + (obj.runAsProduction ? "Production" : "Staging") + ", " + (Date.now() - obj.certCheckStart) + "ms): " + JSON.stringify(results));
229
+ if (obj.performRestart === true) { parent.debug('cert', "Certs changed, restarting..."); obj.parent.performServerCertUpdate(); } // Reset the server, TODO: Reset all peers
230
+ else if (obj.performMoveToProduction == true) {
231
+ parent.debug('cert', "Staging certificate received, moving to production...");
232
+ obj.runAsProduction = true;
233
+ obj.performMoveToProduction = false;
234
+ obj.performRestart = true;
235
+ setTimeout(obj.checkRenewCertificate, 10000); // Check the certificate in 10 seconds.
236
+ }
237
}
238
})
227
- .catch(function (e) { console.log(e); });
239
+ .catch(function (ex) {
240
+ parent.debug('cert', "checkRenewCertificate exception: (" + JSON.stringify(ex) + ")");
241
+ console.log(ex);
242
+ });
243
}
244
245
return obj;
package.json
+1
-1
@@ -1,6 +1,6 @@
1
{
2
"name": "meshcentral",
3
- "version": "0.4.4-j",
3
+ "version": "0.4.4-k",
4
"keywords": [
5
"Remote Management",
6
"Intel AMT",