Skip to content

Commit 077cf75

Browse files
committed
wildcard support
1 parent ff17702 commit 077cf75

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

backend/internal/certificate.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,11 @@ const internalCertificate = {
141141
});
142142
})
143143
.then((in_use_result) => {
144-
// 3. Generate the LE config
145-
return internalNginx.generateLetsEncryptRequestConfig(certificate)
146-
.then(internalNginx.reload)
147-
.then(() => {
144+
// Is CloudFlare, no config needed, so skip 3 and 5.
145+
if (data.meta.cloudflare_use) {
146+
return internalNginx.reload().then(() => {
148147
// 4. Request cert
149-
if (data.meta.cloudflare_use) {
150-
return internalCertificate.requestLetsEncryptCloudFlareDnsSsl(certificate, data.meta.cloudflare_token);
151-
} else {
152-
return internalCertificate.requestLetsEncryptSsl(certificate);
153-
}
154-
})
155-
.then(() => {
156-
// 5. Remove LE config
157-
return internalNginx.deleteLetsEncryptRequestConfig(certificate);
148+
return internalCertificate.requestLetsEncryptCloudFlareDnsSsl(certificate, data.meta.cloudflare_token);
158149
})
159150
.then(internalNginx.reload)
160151
.then(() => {
@@ -166,15 +157,44 @@ const internalCertificate = {
166157
})
167158
.catch((err) => {
168159
// In the event of failure, revert things and throw err back
169-
return internalNginx.deleteLetsEncryptRequestConfig(certificate)
170-
.then(() => {
171-
return internalCertificate.enableInUseHosts(in_use_result);
172-
})
160+
return internalCertificate.enableInUseHosts(in_use_result)
173161
.then(internalNginx.reload)
174162
.then(() => {
175163
throw err;
176164
});
177165
});
166+
} else {
167+
// 3. Generate the LE config
168+
return internalNginx.generateLetsEncryptRequestConfig(certificate)
169+
.then(internalNginx.reload)
170+
.then(() => {
171+
// 4. Request cert
172+
return internalCertificate.requestLetsEncryptSsl(certificate);
173+
})
174+
.then(() => {
175+
// 5. Remove LE config
176+
return internalNginx.deleteLetsEncryptRequestConfig(certificate);
177+
})
178+
.then(internalNginx.reload)
179+
.then(() => {
180+
// 6. Re-instate previously disabled hosts
181+
return internalCertificate.enableInUseHosts(in_use_result);
182+
})
183+
.then(() => {
184+
return certificate;
185+
})
186+
.catch((err) => {
187+
// In the event of failure, revert things and throw err back
188+
return internalNginx.deleteLetsEncryptRequestConfig(certificate)
189+
.then(() => {
190+
return internalCertificate.enableInUseHosts(in_use_result);
191+
})
192+
.then(internalNginx.reload)
193+
.then(() => {
194+
throw err;
195+
});
196+
});
197+
}
178198
})
179199
.then(() => {
180200
// At this point, the letsencrypt cert should exist on disk.
@@ -763,26 +783,25 @@ const internalCertificate = {
763783
let tokenLoc = '~/cloudflare-token';
764784
let storeKey = 'echo "dns_cloudflare_api_token = ' + apiToken + '" > ' + tokenLoc;
765785

766-
let cmd = certbot_command + ' certonly --non-interactive ' +
786+
let cmd =
787+
storeKey + " && " +
788+
certbot_command + ' certonly --non-interactive ' +
767789
'--cert-name "npm-' + certificate.id + '" ' +
768790
'--agree-tos ' +
769791
'--email "' + certificate.meta.letsencrypt_email + '" ' +
770792
'--domains "' + certificate.domain_names.join(',') + '" ' +
771-
'--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc + ' ' +
772-
(le_staging ? '--staging' : '');
793+
'--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc +
794+
(le_staging ? ' --staging' : '')
795+
+ ' && rm ' + tokenLoc;
773796

774797
if (debug_mode) {
775798
logger.info('Command:', cmd);
776799
}
777800

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-
});
801+
return utils.exec(cmd).then((result) => {
802+
logger.info(result);
803+
return result;
784804
});
785-
});
786805
},
787806

788807

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = Mn.View.extend({
3939

4040
if (!this.ui.form[0].checkValidity()) {
4141
$('<input type="submit">').hide().appendTo(this.ui.form).click().remove();
42+
$(this).addClass('btn-loading');
4243
return;
4344
}
4445

@@ -94,6 +95,7 @@ module.exports = Mn.View.extend({
9495
}
9596

9697
this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
98+
this.ui.save.addClass('btn-loading');
9799

98100
// compile file data
99101
let form_data = new FormData();
@@ -132,6 +134,7 @@ module.exports = Mn.View.extend({
132134
.catch(err => {
133135
alert(err.message);
134136
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
137+
this.ui.save.removeClass('btn-loading');
135138
});
136139
}
137140
},
@@ -161,7 +164,7 @@ module.exports = Mn.View.extend({
161164
text: input
162165
};
163166
},
164-
createFilter: /^(?:[^.*]+\.?)+[^.]$/
167+
createFilter: /^(?:[^.]+\.?)+[^.]$/
165168
});
166169
this.ui.cloudflare.hide();
167170
},

0 commit comments

Comments
 (0)