Skip to content

Commit ff17702

Browse files
committed
request via cloudflare dns working
1 parent b9a9584 commit ff17702

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

backend/internal/certificate.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ const internalCertificate = {
146146
.then(internalNginx.reload)
147147
.then(() => {
148148
// 4. Request cert
149-
return internalCertificate.requestLetsEncryptSsl(certificate);
149+
if (data.meta.cloudflare_use) {
150+
return internalCertificate.requestLetsEncryptCloudFlareDnsSsl(certificate, data.meta.cloudflare_token);
151+
} else {
152+
return internalCertificate.requestLetsEncryptSsl(certificate);
153+
}
150154
})
151155
.then(() => {
152156
// 5. Remove LE config
@@ -748,6 +752,40 @@ const internalCertificate = {
748752
});
749753
},
750754

755+
/**
756+
* @param {Object} certificate the certificate row
757+
* @param {String} apiToken the cloudflare api token
758+
* @returns {Promise}
759+
*/
760+
requestLetsEncryptCloudFlareDnsSsl: (certificate, apiToken) => {
761+
logger.info('Requesting Let\'sEncrypt certificates via Cloudflare DNS for Cert #' + certificate.id + ': ' + certificate.domain_names.join(', '));
762+
763+
let tokenLoc = '~/cloudflare-token';
764+
let storeKey = 'echo "dns_cloudflare_api_token = ' + apiToken + '" > ' + tokenLoc;
765+
766+
let cmd = certbot_command + ' certonly --non-interactive ' +
767+
'--cert-name "npm-' + certificate.id + '" ' +
768+
'--agree-tos ' +
769+
'--email "' + certificate.meta.letsencrypt_email + '" ' +
770+
'--domains "' + certificate.domain_names.join(',') + '" ' +
771+
'--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc + ' ' +
772+
(le_staging ? '--staging' : '');
773+
774+
if (debug_mode) {
775+
logger.info('Command:', cmd);
776+
}
777+
778+
return utils.exec(storeKey).then((result) => {
779+
utils.exec(cmd).then((result) => {
780+
utils.exec('rm ' + tokenLoc).then(result => {
781+
logger.success(result);
782+
return result;
783+
});
784+
});
785+
});
786+
},
787+
788+
751789
/**
752790
* @param {Access} access
753791
* @param {Object} data

backend/schema/endpoints/certificates.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
},
4242
"letsencrypt_agree": {
4343
"type": "boolean"
44+
},
45+
"cloudflare_use": {
46+
"type": "boolean"
47+
},
48+
"cloudflare_token": {
49+
"type": "string"
4450
}
4551
}
4652
}

frontend/js/app/nginx/certificates/form.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<div class="col-sm-12 col-md-12">
2626
<div class="form-group">
2727
<label class="custom-switch">
28-
<input type="checkbox" class="custom-switch-input" name="use_cloudflare" value="1">
28+
<input type="checkbox" class="custom-switch-input" name="meta[cloudflare_use]" value="1">
2929
<span class="custom-switch-indicator"></span>
3030
<span class="custom-switch-description"><%= i18n('ssl', 'use-cloudflare') %></span>
3131
</label>
@@ -34,7 +34,7 @@
3434
<div class="col-sm-12 col-md-12 cloudflare">
3535
<div class="form-group">
3636
<label class="form-label">CloudFlare DNS API Token <span class="form-required">*</span></label>
37-
<input type="text" name="cloudflare_dns_api_token" class="form-control" id="input-domains" required>
37+
<input type="text" name="meta[cloudflare_token]" class="form-control" id="cloudflare_token" required>
3838
</div>
3939
</div>
4040

frontend/js/app/nginx/certificates/form.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = Mn.View.extend({
2121
other_certificate: '#other_certificate',
2222
other_certificate_key: '#other_certificate_key',
2323
other_intermediate_certificate: '#other_intermediate_certificate',
24-
cloudflare_switch: 'input[name="use_cloudflare"]',
24+
cloudflare_switch: 'input[name="meta[cloudflare_use]"]',
2525
cloudflare: '.cloudflare'
2626
},
2727

@@ -50,6 +50,9 @@ module.exports = Mn.View.extend({
5050
if (typeof data.meta !== 'undefined' && typeof data.meta.letsencrypt_agree !== 'undefined') {
5151
data.meta.letsencrypt_agree = !!data.meta.letsencrypt_agree;
5252
}
53+
if (typeof data.meta !== 'undefined' && typeof data.meta.cloudflare_use !== 'undefined') {
54+
data.meta.cloudflare_use = !!data.meta.cloudflare_use;
55+
}
5356

5457
if (typeof data.domain_names === 'string' && data.domain_names) {
5558
data.domain_names = data.domain_names.split(',');
@@ -140,6 +143,10 @@ module.exports = Mn.View.extend({
140143

141144
getLetsencryptAgree: function () {
142145
return typeof this.meta.letsencrypt_agree !== 'undefined' ? this.meta.letsencrypt_agree : false;
146+
},
147+
148+
getCloudflareUse: function () {
149+
return typeof this.meta.cloudflare_use !== 'undefined' ? this.meta.cloudflare_use : false;
143150
}
144151
},
145152

0 commit comments

Comments
 (0)