wildcard support

This commit is contained in:
Jaap-Jan de Wit 2020-08-23 13:24:20 +00:00
parent ff1770204c
commit 077cf75ef2
2 changed files with 50 additions and 28 deletions

View File

@ -141,20 +141,11 @@ const internalCertificate = {
}); });
}) })
.then((in_use_result) => { .then((in_use_result) => {
// 3. Generate the LE config // Is CloudFlare, no config needed, so skip 3 and 5.
return internalNginx.generateLetsEncryptRequestConfig(certificate) if (data.meta.cloudflare_use) {
.then(internalNginx.reload) return internalNginx.reload().then(() => {
.then(() => {
// 4. Request cert // 4. Request cert
if (data.meta.cloudflare_use) { return internalCertificate.requestLetsEncryptCloudFlareDnsSsl(certificate, data.meta.cloudflare_token);
return internalCertificate.requestLetsEncryptCloudFlareDnsSsl(certificate, data.meta.cloudflare_token);
} else {
return internalCertificate.requestLetsEncryptSsl(certificate);
}
})
.then(() => {
// 5. Remove LE config
return internalNginx.deleteLetsEncryptRequestConfig(certificate);
}) })
.then(internalNginx.reload) .then(internalNginx.reload)
.then(() => { .then(() => {
@ -166,15 +157,44 @@ const internalCertificate = {
}) })
.catch((err) => { .catch((err) => {
// In the event of failure, revert things and throw err back // In the event of failure, revert things and throw err back
return internalNginx.deleteLetsEncryptRequestConfig(certificate) return internalCertificate.enableInUseHosts(in_use_result)
.then(() => {
return internalCertificate.enableInUseHosts(in_use_result);
})
.then(internalNginx.reload) .then(internalNginx.reload)
.then(() => { .then(() => {
throw err; throw err;
}); });
}); });
} else {
// 3. Generate the LE config
return internalNginx.generateLetsEncryptRequestConfig(certificate)
.then(internalNginx.reload)
.then(() => {
// 4. Request cert
return internalCertificate.requestLetsEncryptSsl(certificate);
})
.then(() => {
// 5. Remove LE config
return internalNginx.deleteLetsEncryptRequestConfig(certificate);
})
.then(internalNginx.reload)
.then(() => {
// 6. Re-instate previously disabled hosts
return internalCertificate.enableInUseHosts(in_use_result);
})
.then(() => {
return certificate;
})
.catch((err) => {
// In the event of failure, revert things and throw err back
return internalNginx.deleteLetsEncryptRequestConfig(certificate)
.then(() => {
return internalCertificate.enableInUseHosts(in_use_result);
})
.then(internalNginx.reload)
.then(() => {
throw err;
});
});
}
}) })
.then(() => { .then(() => {
// At this point, the letsencrypt cert should exist on disk. // At this point, the letsencrypt cert should exist on disk.
@ -763,26 +783,25 @@ const internalCertificate = {
let tokenLoc = '~/cloudflare-token'; let tokenLoc = '~/cloudflare-token';
let storeKey = 'echo "dns_cloudflare_api_token = ' + apiToken + '" > ' + tokenLoc; let storeKey = 'echo "dns_cloudflare_api_token = ' + apiToken + '" > ' + tokenLoc;
let cmd = certbot_command + ' certonly --non-interactive ' + let cmd =
storeKey + " && " +
certbot_command + ' certonly --non-interactive ' +
'--cert-name "npm-' + certificate.id + '" ' + '--cert-name "npm-' + certificate.id + '" ' +
'--agree-tos ' + '--agree-tos ' +
'--email "' + certificate.meta.letsencrypt_email + '" ' + '--email "' + certificate.meta.letsencrypt_email + '" ' +
'--domains "' + certificate.domain_names.join(',') + '" ' + '--domains "' + certificate.domain_names.join(',') + '" ' +
'--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc + ' ' + '--dns-cloudflare --dns-cloudflare-credentials ' + tokenLoc +
(le_staging ? '--staging' : ''); (le_staging ? ' --staging' : '')
+ ' && rm ' + tokenLoc;
if (debug_mode) { if (debug_mode) {
logger.info('Command:', cmd); logger.info('Command:', cmd);
} }
return utils.exec(storeKey).then((result) => { return utils.exec(cmd).then((result) => {
utils.exec(cmd).then((result) => { logger.info(result);
utils.exec('rm ' + tokenLoc).then(result => { return result;
logger.success(result);
return result;
});
}); });
});
}, },

View File

@ -39,6 +39,7 @@ module.exports = Mn.View.extend({
if (!this.ui.form[0].checkValidity()) { if (!this.ui.form[0].checkValidity()) {
$('<input type="submit">').hide().appendTo(this.ui.form).click().remove(); $('<input type="submit">').hide().appendTo(this.ui.form).click().remove();
$(this).addClass('btn-loading');
return; return;
} }
@ -94,6 +95,7 @@ module.exports = Mn.View.extend({
} }
this.ui.buttons.prop('disabled', true).addClass('btn-disabled'); this.ui.buttons.prop('disabled', true).addClass('btn-disabled');
this.ui.save.addClass('btn-loading');
// compile file data // compile file data
let form_data = new FormData(); let form_data = new FormData();
@ -132,6 +134,7 @@ module.exports = Mn.View.extend({
.catch(err => { .catch(err => {
alert(err.message); alert(err.message);
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled'); this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
this.ui.save.removeClass('btn-loading');
}); });
} }
}, },
@ -161,7 +164,7 @@ module.exports = Mn.View.extend({
text: input text: input
}; };
}, },
createFilter: /^(?:[^.*]+\.?)+[^.]$/ createFilter: /^(?:[^.]+\.?)+[^.]$/
}); });
this.ui.cloudflare.hide(); this.ui.cloudflare.hide();
}, },