From 6349cb6094d89a228e6317a992b57aaea3c81a1f Mon Sep 17 00:00:00 2001 From: plantysnake Date: Fri, 18 Nov 2022 15:06:19 +0300 Subject: [PATCH 1/2] Fix cerbot plugin installation issues --- backend/internal/certificate.js | 8 ++------ backend/setup.js | 15 +++------------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js index d6b72f57..adc9c399 100644 --- a/backend/internal/certificate.js +++ b/backend/internal/certificate.js @@ -874,12 +874,8 @@ const internalCertificate = { // Escape single quotes and backslashes const escapedCredentials = certificate.meta.dns_provider_credentials.replaceAll('\'', '\\\'').replaceAll('\\', '\\\\'); const credentialsCmd = 'mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + escapedCredentials + '\' > \'' + credentialsLocation + '\' && chmod 600 \'' + credentialsLocation + '\''; - let prepareCmd = 'pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies; - - // Special case for cloudflare - if (dns_plugin.package_name === 'certbot-dns-cloudflare') { - prepareCmd = 'pip install certbot-dns-cloudflare --index-url https://www.piwheels.org/simple --prefer-binary'; - } + // we call `. /opt/certbot/bin/activate` (`.` is alternative to `source` in dash) to access certbot venv + let prepareCmd = '. /opt/certbot/bin/activate && pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies + " && deactivate"; // Whether the plugin has a ---credentials argument const hasConfigArg = certificate.meta.dns_provider !== 'route53'; diff --git a/backend/setup.js b/backend/setup.js index 239c8c0b..c5b94b87 100644 --- a/backend/setup.js +++ b/backend/setup.js @@ -171,18 +171,13 @@ const setupCertbotPlugins = () => { if (certificates && certificates.length) { let plugins = []; let promises = []; - let install_cloudflare_plugin = false; certificates.map(function (certificate) { if (certificate.meta && certificate.meta.dns_challenge === true) { const dns_plugin = dns_plugins[certificate.meta.dns_provider]; - if (dns_plugin.package_name === 'certbot-dns-cloudflare') { - install_cloudflare_plugin = true; - } else { - const packages_to_install = `${dns_plugin.package_name}${dns_plugin.version_requirement || ''} ${dns_plugin.dependencies}`; - if (plugins.indexOf(packages_to_install) === -1) plugins.push(packages_to_install); - } + const packages_to_install = `${dns_plugin.package_name}${dns_plugin.version_requirement || ''} ${dns_plugin.dependencies}`; + if (plugins.indexOf(packages_to_install) === -1) plugins.push(packages_to_install); // Make sure credentials file exists const credentials_loc = '/etc/letsencrypt/credentials/credentials-' + certificate.id; @@ -194,14 +189,10 @@ const setupCertbotPlugins = () => { }); if (plugins.length) { - const install_cmd = 'pip install ' + plugins.join(' '); + const install_cmd = '. /opt/certbot/bin/activate && pip install ' + plugins.join(' ') + " && deactivate"; promises.push(utils.exec(install_cmd)); } - if (install_cloudflare_plugin) { - promises.push(utils.exec('pip install certbot-dns-cloudflare --index-url https://www.piwheels.org/simple --prefer-binary')); - } - if (promises.length) { return Promise.all(promises) .then(() => { From 8dee139810c06025fb1e712ebbb102d32255a0d7 Mon Sep 17 00:00:00 2001 From: plantysnake Date: Mon, 21 Nov 2022 01:46:42 +0300 Subject: [PATCH 2/2] Fix linter issues --- backend/internal/certificate.js | 2 +- backend/setup.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/internal/certificate.js b/backend/internal/certificate.js index adc9c399..780d73d2 100644 --- a/backend/internal/certificate.js +++ b/backend/internal/certificate.js @@ -875,7 +875,7 @@ const internalCertificate = { const escapedCredentials = certificate.meta.dns_provider_credentials.replaceAll('\'', '\\\'').replaceAll('\\', '\\\\'); const credentialsCmd = 'mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + escapedCredentials + '\' > \'' + credentialsLocation + '\' && chmod 600 \'' + credentialsLocation + '\''; // we call `. /opt/certbot/bin/activate` (`.` is alternative to `source` in dash) to access certbot venv - let prepareCmd = '. /opt/certbot/bin/activate && pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies + " && deactivate"; + let prepareCmd = '. /opt/certbot/bin/activate && pip install ' + dns_plugin.package_name + (dns_plugin.version_requirement || '') + ' ' + dns_plugin.dependencies + ' && deactivate'; // Whether the plugin has a ---credentials argument const hasConfigArg = certificate.meta.dns_provider !== 'route53'; diff --git a/backend/setup.js b/backend/setup.js index c5b94b87..a4b51c95 100644 --- a/backend/setup.js +++ b/backend/setup.js @@ -169,8 +169,8 @@ const setupCertbotPlugins = () => { .andWhere('provider', 'letsencrypt') .then((certificates) => { if (certificates && certificates.length) { - let plugins = []; - let promises = []; + let plugins = []; + let promises = []; certificates.map(function (certificate) { if (certificate.meta && certificate.meta.dns_challenge === true) { @@ -189,7 +189,7 @@ const setupCertbotPlugins = () => { }); if (plugins.length) { - const install_cmd = '. /opt/certbot/bin/activate && pip install ' + plugins.join(' ') + " && deactivate"; + const install_cmd = '. /opt/certbot/bin/activate && pip install ' + plugins.join(' ') + ' && deactivate'; promises.push(utils.exec(install_cmd)); }