@@ -9,10 +9,11 @@ const error = require('../lib/error');
99const utils = require ( '../lib/utils' ) ;
1010const certificateModel = require ( '../models/certificate' ) ;
1111const tokenModel = require ( '../models/token' ) ;
12- const dnsPlugins = require ( '../global/certbot-dns-plugins' ) ;
12+ const dnsPlugins = require ( '../global/certbot-dns-plugins.json ' ) ;
1313const internalAuditLog = require ( './audit-log' ) ;
1414const internalNginx = require ( './nginx' ) ;
1515const internalHost = require ( './host' ) ;
16+ const certbot = require ( '../lib/certbot' ) ;
1617const archiver = require ( 'archiver' ) ;
1718const path = require ( 'path' ) ;
1819const { isArray } = require ( 'lodash' ) ;
@@ -849,26 +850,20 @@ const internalCertificate = {
849850
850851 /**
851852 * @param {Object } certificate the certificate row
852- * @param {String } dns_provider the dns provider name (key used in `certbot-dns-plugins.js `)
853+ * @param {String } dns_provider the dns provider name (key used in `certbot-dns-plugins.json `)
853854 * @param {String | null } credentials the content of this providers credentials file
854- * @param {String } propagation_seconds the cloudflare api token
855+ * @param {String } propagation_seconds
855856 * @returns {Promise }
856857 */
857- requestLetsEncryptSslWithDnsChallenge : ( certificate ) => {
858- const dns_plugin = dnsPlugins [ certificate . meta . dns_provider ] ;
859-
860- if ( ! dns_plugin ) {
861- throw Error ( `Unknown DNS provider '${ certificate . meta . dns_provider } '` ) ;
862- }
863-
864- logger . info ( `Requesting Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
858+ requestLetsEncryptSslWithDnsChallenge : async ( certificate ) => {
859+ await certbot . installPlugin ( certificate . meta . dns_provider ) ;
860+ const dnsPlugin = dnsPlugins [ certificate . meta . dns_provider ] ;
861+ logger . info ( `Requesting Let'sEncrypt certificates via ${ dnsPlugin . name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
865862
866863 const credentialsLocation = '/etc/letsencrypt/credentials/credentials-' + certificate . id ;
867864 // Escape single quotes and backslashes
868865 const escapedCredentials = certificate . meta . dns_provider_credentials . replaceAll ( '\'' , '\\\'' ) . replaceAll ( '\\' , '\\\\' ) ;
869866 const credentialsCmd = 'mkdir -p /etc/letsencrypt/credentials 2> /dev/null; echo \'' + escapedCredentials + '\' > \'' + credentialsLocation + '\' && chmod 600 \'' + credentialsLocation + '\'' ;
870- // we call `. /opt/certbot/bin/activate` (`.` is alternative to `source` in dash) to access certbot venv
871- const prepareCmd = '. /opt/certbot/bin/activate && pip install --no-cache-dir ' + dns_plugin . package_name + ( dns_plugin . version_requirement || '' ) + ' ' + dns_plugin . dependencies + ' && deactivate' ;
872867
873868 // Whether the plugin has a --<name>-credentials argument
874869 const hasConfigArg = certificate . meta . dns_provider !== 'route53' ;
@@ -881,15 +876,15 @@ const internalCertificate = {
881876 '--agree-tos ' +
882877 '--email "' + certificate . meta . letsencrypt_email + '" ' +
883878 '--domains "' + certificate . domain_names . join ( ',' ) + '" ' +
884- '--authenticator ' + dns_plugin . full_plugin_name + ' ' +
879+ '--authenticator ' + dnsPlugin . full_plugin_name + ' ' +
885880 (
886881 hasConfigArg
887- ? '--' + dns_plugin . full_plugin_name + '-credentials "' + credentialsLocation + '"'
882+ ? '--' + dnsPlugin . full_plugin_name + '-credentials "' + credentialsLocation + '"'
888883 : ''
889884 ) +
890885 (
891886 certificate . meta . propagation_seconds !== undefined
892- ? ' --' + dns_plugin . full_plugin_name + '-propagation-seconds ' + certificate . meta . propagation_seconds
887+ ? ' --' + dnsPlugin . full_plugin_name + '-propagation-seconds ' + certificate . meta . propagation_seconds
893888 : ''
894889 ) +
895890 ( letsencryptStaging ? ' --staging' : '' ) ;
@@ -903,24 +898,19 @@ const internalCertificate = {
903898 mainCmd = mainCmd + ' --dns-duckdns-no-txt-restore' ;
904899 }
905900
906- logger . info ( 'Command:' , `${ credentialsCmd } && ${ prepareCmd } && ${ mainCmd } ` ) ;
907-
908- return utils . exec ( credentialsCmd )
909- . then ( ( ) => {
910- return utils . exec ( prepareCmd )
911- . then ( ( ) => {
912- return utils . exec ( mainCmd )
913- . then ( async ( result ) => {
914- logger . info ( result ) ;
915- return result ;
916- } ) ;
917- } ) ;
918- } ) . catch ( async ( err ) => {
919- // Don't fail if file does not exist
920- const delete_credentialsCmd = `rm -f '${ credentialsLocation } ' || true` ;
921- await utils . exec ( delete_credentialsCmd ) ;
922- throw err ;
923- } ) ;
901+ logger . info ( 'Command:' , `${ credentialsCmd } && && ${ mainCmd } ` ) ;
902+
903+ try {
904+ await utils . exec ( credentialsCmd ) ;
905+ const result = await utils . exec ( mainCmd ) ;
906+ logger . info ( result ) ;
907+ return result ;
908+ } catch ( err ) {
909+ // Don't fail if file does not exist
910+ const delete_credentialsCmd = `rm -f '${ credentialsLocation } ' || true` ;
911+ await utils . exec ( delete_credentialsCmd ) ;
912+ throw err ;
913+ }
924914 } ,
925915
926916
@@ -999,13 +989,13 @@ const internalCertificate = {
999989 * @returns {Promise }
1000990 */
1001991 renewLetsEncryptSslWithDnsChallenge : ( certificate ) => {
1002- const dns_plugin = dnsPlugins [ certificate . meta . dns_provider ] ;
992+ const dnsPlugin = dnsPlugins [ certificate . meta . dns_provider ] ;
1003993
1004- if ( ! dns_plugin ) {
994+ if ( ! dnsPlugin ) {
1005995 throw Error ( `Unknown DNS provider '${ certificate . meta . dns_provider } '` ) ;
1006996 }
1007997
1008- logger . info ( `Renewing Let'sEncrypt certificates via ${ dns_plugin . display_name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
998+ logger . info ( `Renewing Let'sEncrypt certificates via ${ dnsPlugin . name } for Cert #${ certificate . id } : ${ certificate . domain_names . join ( ', ' ) } ` ) ;
1009999
10101000 let mainCmd = certbotCommand + ' renew --force-renewal ' +
10111001 '--config "' + letsencryptConfig + '" ' +
0 commit comments