From c5aa2b9f771cbd4c78c239ed0791aeb8d9e4d2e4 Mon Sep 17 00:00:00 2001 From: Jaap-Jan de Wit Date: Sun, 23 Aug 2020 18:29:16 +0000 Subject: [PATCH] add cloudflare renew and make revoke working for both by deleting unnecessary config command --- backend/internal/certificate.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js index c5e6a466..2dadb343 100644 --- a/backend/internal/certificate.js +++ b/backend/internal/certificate.js @@ -818,7 +818,9 @@ const internalCertificate = { }) .then((certificate) => { if (certificate.provider === 'letsencrypt') { - return internalCertificate.renewLetsEncryptSsl(certificate) + let renewMethod = certificate.meta.cloudflare_use ? internalCertificate.renewLetsEncryptCloudFlareSsl : internalCertificate.renewLetsEncryptSsl; + + return renewMethod(certificate) .then(() => { return internalCertificate.getCertificateInfoFromFile('/etc/letsencrypt/live/npm-' + certificate.id + '/fullchain.pem'); }) @@ -872,6 +874,29 @@ const internalCertificate = { }); }, + /** + * @param {Object} certificate the certificate row + * @returns {Promise} + */ + renewLetsEncryptCloudFlareSsl: (certificate) => { + logger.info('Renewing Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', ')); + + let cmd = certbot_command + ' renew --non-interactive ' + + '--cert-name "npm-' + certificate.id + '" ' + + '--disable-hook-validation ' + + (le_staging ? '--staging' : ''); + + if (debug_mode) { + logger.info('Command:', cmd); + } + + return utils.exec(cmd) + .then((result) => { + logger.info(result); + return result; + }); + }, + /** * @param {Object} certificate the certificate row * @param {Boolean} [throw_errors] @@ -881,7 +906,6 @@ const internalCertificate = { logger.info('Revoking Let\'sEncrypt certificates for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', ')); let cmd = certbot_command + ' revoke --non-interactive ' + - '--config "' + le_config + '" ' + '--cert-path "/etc/letsencrypt/live/npm-' + certificate.id + '/fullchain.pem" ' + '--delete-after-revoke ' + (le_staging ? '--staging' : '');