Skip to content

Commit b81325d

Browse files
committed
Implements dns challenge provider selection in frontend
1 parent 28f7208 commit b81325d

File tree

12 files changed

+755
-155
lines changed

12 files changed

+755
-155
lines changed

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

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,92 @@
2121
</div>
2222
</div>
2323
24-
<!-- CloudFlare -->
24+
<!-- DNS challenge -->
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="meta[cloudflare_use]" value="1">
28+
<input
29+
type="checkbox"
30+
class="custom-switch-input"
31+
name="meta[dns_challenge]"
32+
value="1"
33+
<%- getUseDnsChallenge() ? 'checked' : '' %>
34+
>
2935
<span class="custom-switch-indicator"></span>
30-
<span class="custom-switch-description"><%= i18n('ssl', 'use-cloudflare') %></span>
36+
<span class="custom-switch-description"><%= i18n('ssl', 'dns-challenge') %></span>
3137
</label>
3238
</div>
3339
</div>
34-
<div class="col-sm-12 col-md-12 cloudflare">
35-
<div class="form-group">
36-
<label class="form-label">CloudFlare DNS API Token <span class="form-required">*</span></label>
37-
<input type="text" name="meta[cloudflare_token]" class="form-control" id="cloudflare_token">
38-
</div>
40+
<div class="col-sm-12 col-md-12">
41+
<fieldset class="form-fieldset dns-challenge">
42+
<div class="text-red mb-4"><i class="fe fe-alert-triangle"></i> <%= i18n('ssl', 'certbot-warning') %></div>
43+
44+
<!-- Certbot DNS plugin selection -->
45+
<div class="row">
46+
<div class="col-sm-12 col-md-12">
47+
<div class="form-group">
48+
<label class="form-label"><%- i18n('ssl', 'dns-provider') %> <span class="form-required">*</span></label>
49+
<select
50+
name="meta[dns_provider]"
51+
id="dns_provider"
52+
class="form-control custom-select"
53+
>
54+
<option
55+
value=""
56+
disabled
57+
hidden
58+
<%- getDnsProvider() === null ? 'selected' : '' %>
59+
>Please Choose...</option>
60+
<% _.each(dns_plugins, function(plugin_info, plugin_name){ %>
61+
<option
62+
value="<%- plugin_name %>"
63+
<%- getDnsProvider() === plugin_name ? 'selected' : '' %>
64+
><%- plugin_info.display_name %></option>
65+
<% }); %>
66+
</select>
67+
</div>
68+
</div>
69+
</div>
70+
71+
<!-- Certbot credentials file content -->
72+
<div class="row credentials-file-content">
73+
<div class="col-sm-12 col-md-12">
74+
<div class="form-group">
75+
<label class="form-label"><%- i18n('ssl', 'credentials-file-content') %> <span class="form-required">*</span></label>
76+
<textarea
77+
name="meta[dns_provider_credentials]"
78+
class="form-control text-monospace"
79+
id="dns_provider_credentials"
80+
><%- getDnsProviderCredentials() %></textarea>
81+
<div class="text-secondary small">
82+
<i class="fe fe-info"></i>
83+
<%= i18n('ssl', 'credentials-file-content-info') %>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
89+
<!-- DNS propagation delay -->
90+
<div class="row">
91+
<div class="col-sm-12 col-md-12">
92+
<div class="form-group mb-0">
93+
<label class="form-label"><%- i18n('ssl', 'propagation-seconds') %></label>
94+
<input
95+
type="number"
96+
min="0"
97+
name="meta[propagation_seconds]"
98+
class="form-control"
99+
id="propagation_seconds"
100+
value="<%- getPropagationSeconds() %>"
101+
>
102+
<div class="text-secondary small">
103+
<i class="fe fe-info"></i>
104+
<%= i18n('ssl', 'propagation-seconds-info') %>
105+
</div>
106+
</div>
107+
</div>
108+
</div>
109+
</fieldset>
39110
</div>
40111
41112
<div class="col-sm-12 col-md-12">

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

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const Mn = require('backbone.marionette');
33
const App = require('../../main');
44
const CertificateModel = require('../../../models/certificate');
55
const template = require('./form.ejs');
6+
const i18n = require('../../i18n');
7+
const dns_providers = require('../../../../../utils/certbot-dns-plugins');
68

79
require('jquery-serializejson');
810
require('selectize');
@@ -21,25 +23,46 @@ module.exports = Mn.View.extend({
2123
other_certificate: '#other_certificate',
2224
other_certificate_label: '#other_certificate_label',
2325
other_certificate_key: '#other_certificate_key',
24-
cloudflare_switch: 'input[name="meta[cloudflare_use]"]',
25-
cloudflare_token: 'input[name="meta[cloudflare_token]"',
26-
cloudflare: '.cloudflare',
26+
dns_challenge_switch: 'input[name="meta[dns_challenge]"]',
27+
dns_challenge_content: '.dns-challenge',
28+
dns_provider: 'select[name="meta[dns_provider]"]',
29+
credentials_file_content: '.credentials-file-content',
30+
dns_provider_credentials: 'textarea[name="meta[dns_provider_credentials]"]',
31+
propagation_seconds: 'input[name="meta[propagation_seconds]"]',
2732
other_certificate_key_label: '#other_certificate_key_label',
2833
other_intermediate_certificate: '#other_intermediate_certificate',
2934
other_intermediate_certificate_label: '#other_intermediate_certificate_label'
3035
},
3136

3237
events: {
33-
'change @ui.cloudflare_switch': function() {
34-
let checked = this.ui.cloudflare_switch.prop('checked');
35-
if (checked) {
36-
this.ui.cloudflare_token.prop('required', 'required');
37-
this.ui.cloudflare.show();
38-
} else {
39-
this.ui.cloudflare_token.prop('required', false);
40-
this.ui.cloudflare.hide();
38+
'change @ui.dns_challenge_switch': function () {
39+
const checked = this.ui.dns_challenge_switch.prop('checked');
40+
if (checked) {
41+
this.ui.dns_provider.prop('required', 'required');
42+
const selected_provider = this.ui.dns_provider[0].options[this.ui.dns_provider[0].selectedIndex].value;
43+
if(selected_provider != '' && dns_providers[selected_provider].credentials !== false){
44+
this.ui.dns_provider_credentials.prop('required', 'required');
45+
}
46+
this.ui.dns_challenge_content.show();
47+
} else {
48+
this.ui.dns_provider.prop('required', false);
49+
this.ui.dns_provider_credentials.prop('required', false);
50+
this.ui.dns_challenge_content.hide();
51+
}
52+
},
53+
54+
'change @ui.dns_provider': function () {
55+
const selected_provider = this.ui.dns_provider[0].options[this.ui.dns_provider[0].selectedIndex].value;
56+
if (selected_provider != '' && dns_providers[selected_provider].credentials !== false) {
57+
this.ui.dns_provider_credentials.prop('required', 'required');
58+
this.ui.dns_provider_credentials[0].value = dns_providers[selected_provider].credentials;
59+
this.ui.credentials_file_content.show();
60+
} else {
61+
this.ui.dns_provider_credentials.prop('required', false);
62+
this.ui.credentials_file_content.hide();
4163
}
4264
},
65+
4366
'click @ui.save': function (e) {
4467
e.preventDefault();
4568

@@ -56,7 +79,7 @@ module.exports = Mn.View.extend({
5679

5780

5881
let domain_err = false;
59-
if (!data.meta.cloudflare_use) {
82+
if (!data.meta.dns_challenge) {
6083
data.domain_names.split(',').map(function (name) {
6184
if (name.match(/\*/im)) {
6285
domain_err = true;
@@ -65,16 +88,17 @@ module.exports = Mn.View.extend({
6588
}
6689

6790
if (domain_err) {
68-
alert('Cannot request Let\'s Encrypt Certificate for wildcard domains when not using CloudFlare DNS');
91+
alert(i18n('ssl', 'no-wildcard-without-dns'));
6992
return;
7093
}
7194

7295
// Manipulate
7396
if (typeof data.meta !== 'undefined' && typeof data.meta.letsencrypt_agree !== 'undefined') {
7497
data.meta.letsencrypt_agree = !!data.meta.letsencrypt_agree;
7598
}
76-
if (typeof data.meta !== 'undefined' && typeof data.meta.cloudflare_use !== 'undefined') {
77-
data.meta.cloudflare_use = !!data.meta.cloudflare_use;
99+
100+
if (typeof data.meta !== 'undefined' && typeof data.meta.dns_challenge !== 'undefined') {
101+
data.meta.dns_challenge = !!data.meta.dns_challenge;
78102
}
79103

80104
if (typeof data.domain_names === 'string' && data.domain_names) {
@@ -176,14 +200,22 @@ module.exports = Mn.View.extend({
176200
getLetsencryptEmail: function () {
177201
return typeof this.meta.letsencrypt_email !== 'undefined' ? this.meta.letsencrypt_email : App.Cache.User.get('email');
178202
},
179-
180203
getLetsencryptAgree: function () {
181204
return typeof this.meta.letsencrypt_agree !== 'undefined' ? this.meta.letsencrypt_agree : false;
182205
},
183-
184-
getCloudflareUse: function () {
185-
return typeof this.meta.cloudflare_use !== 'undefined' ? this.meta.cloudflare_use : false;
186-
}
206+
getUseDnsChallenge: function () {
207+
return typeof this.meta.dns_challenge !== 'undefined' ? this.meta.dns_challenge : false;
208+
},
209+
getDnsProvider: function () {
210+
return typeof this.meta.dns_provider !== 'undefined' && this.meta.dns_provider != '' ? this.meta.dns_provider : null;
211+
},
212+
getDnsProviderCredentials: function () {
213+
return typeof this.meta.dns_provider_credentials !== 'undefined' ? this.meta.dns_provider_credentials : '';
214+
},
215+
getPropagationSeconds: function () {
216+
return typeof this.meta.propagation_seconds !== 'undefined' ? this.meta.propagation_seconds : '';
217+
},
218+
dns_plugins: dns_providers,
187219
},
188220

189221
onRender: function () {
@@ -199,7 +231,8 @@ module.exports = Mn.View.extend({
199231
},
200232
createFilter: /^(?:[^.]+\.?)+[^.]$/
201233
});
202-
this.ui.cloudflare.hide();
234+
this.ui.dns_challenge_content.hide();
235+
this.ui.credentials_file_content.hide();
203236
},
204237

205238
initialize: function (options) {

frontend/js/app/nginx/certificates/list/item.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</div>
2929
</td>
3030
<td>
31-
<%- i18n('ssl', provider) %><% if (meta.cloudflare_use) { %> - CloudFlare DNS<% } %>
31+
<%- i18n('ssl', provider) %><% if (meta.dns_provider) { %> - <% dns_providers[meta.dns_provider].display_name } %>
3232
</td>
3333
<td class="<%- isExpired() ? 'text-danger' : '' %>">
3434
<%- formatDbDate(expires_on, 'Do MMMM YYYY, h:mm a') %>

frontend/js/app/nginx/certificates/list/item.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
const Mn = require('backbone.marionette');
2-
const moment = require('moment');
3-
const App = require('../../../main');
4-
const template = require('./item.ejs');
1+
const Mn = require('backbone.marionette');
2+
const moment = require('moment');
3+
const App = require('../../../main');
4+
const template = require('./item.ejs');
5+
const dns_providers = require('../../../../../../utils/certbot-dns-plugins')
56

67
module.exports = Mn.View.extend({
78
template: template,
@@ -35,7 +36,8 @@ module.exports = Mn.View.extend({
3536
canManage: App.Cache.User.canManage('certificates'),
3637
isExpired: function () {
3738
return moment(this.expires_on).isBefore(moment());
38-
}
39+
},
40+
dns_providers: dns_providers
3941
},
4042

4143
initialize: function () {

0 commit comments

Comments
 (0)