Moaaaar buttons (certificate management view)

This commit is contained in:
Alexandre Aubin 2019-10-17 18:50:31 +02:00
parent 266e349d1f
commit 3f8aff1a99
2 changed files with 48 additions and 61 deletions

View file

@ -198,60 +198,47 @@
status: status_,
actions_enabled : actions_enabled
};
c.view('domain/domain_cert', data_);
});
});
c.view('domain/domain_cert', data_, function() {
// Configure install / renew buttons behavior
$("button[data-action]").on("click", function () {
var action = $(this).data("action"),
domain = $(this).data("domain"),
confirm_key = "",
api_url = "";
switch (action) {
case 'install-LE':
confirm_key = 'confirm_cert_install_LE';
api_url = '/domains/cert-install/' + domain;
break;
case 'regen-selfsigned':
confirm_key = 'confirm_cert_regen_selfsigned';
api_url = '/domains/cert-install/' + domain + "?self_signed";
break;
case 'renew-letsencrypt':
confirm_key = 'confirm_cert_manual_renew_LE';
api_url = '/domains/cert-renew/' + domain + "?force";
break;
case 'replace-with-selfsigned':
confirm_key = 'confirm_cert_revert_to_selfsigned';
api_url = '/domains/cert-install/' + domain + "?self_signed&force";
break;
default:
c.flash('fail', y18n.t('unknown_action', [action]));
return
}
// Install let's encrypt certificate on domain
app.get('#/domains/:domain/cert-install-LE', function (c) {
c.confirm(
y18n.t('certificate'),
y18n.t('confirm_cert_install_LE', [c.params['domain']]),
y18n.t(confirm_key, [domain]),
function(){
c.api('POST', '/domains/cert-install/' + c.params['domain'], {}, function(data) {
c.redirect_to('#/domains/'+c.params['domain']+'/cert-management', {slide:false});
c.api('POST', api_url, {}, function(data) {
c.redirect_to('#/domains/'+domain+'/cert-management', {slide:false});
});
}
);
});
// Regenerate a self-signed certificate
app.get('#/domains/:domain/cert-regen-selfsigned', function (c) {
c.confirm(
y18n.t('certificate'),
y18n.t('confirm_cert_regen_selfsigned', [c.params['domain']]),
function(){
c.api('POST', '/domains/cert-install/' + c.params['domain'] + "?self_signed", {}, function(data) {
c.redirect_to('#/domains/'+c.params['domain']+'/cert-management', {slide:false});
});
}
);
});
// Manually renew a Let's Encrypt certificate
app.get('#/domains/:domain/cert-renew-letsencrypt', function (c) {
c.confirm(
y18n.t('certificate'),
y18n.t('confirm_cert_manual_renew_LE', [c.params['domain']]),
function(){
c.api('POST', '/domains/cert-renew/' + c.params['domain'] + "?force", {}, function(data) {
c.redirect_to('#/domains/'+c.params['domain']+'/cert-management', {slide:false});
});
}
);
});
// Replace valid cert with self-signed
app.get('#/domains/:domain/cert-replace-with-selfsigned', function (c) {
c.confirm(
y18n.t('certificate'),
y18n.t('confirm_cert_revert_to_selfsigned', [c.params['domain']]),
function(){
c.api('POST', '/domains/cert-install/' + c.params['domain'] + "?self_signed&force", {}, function(data) {
c.redirect_to('#/domains/'+c.params['domain']+'/cert-management', {slide:false});
});
}
);
});

View file

@ -46,36 +46,36 @@
<p><span class="fa-fw fa-meh-o"></span>
{{t 'domain_not_eligible_for_ACME'}}</p>
{{/if}}
<a role="button" href="#/domains/{{name}}/cert-install-LE" class="btn btn-success {{#unless status.ACME_eligible}}disabled{{/unless}}">
<button class="btn btn-success {{#unless status.ACME_eligible}}disabled{{/unless}}" data-domain="{{name}}" data-action="install-LE" >
<span class="fa-star"></span> {{t 'install_letsencrypt_cert'}}
</a>
</button>
<hr>
</div>
{{/if}}
{{#if actions_enabled.manual_renew_letsencrpt}}
<div class="container">
<p>{{t 'manually_renew_letsencrypt_message'}}</p>
<a role="button" href="#/domains/{{name}}/cert-renew-letsencrypt" class="btn btn-warning">
<button class="btn btn-warning" data-domain="{{name}}" data-action="renew-letsencrypt">
<span class="fa-refresh"></span> {{t 'manually_renew_letsencrypt'}}
</a>
</button>
</div>
<hr>
{{/if}}
{{#if actions_enabled.regen_selfsigned}}
<div class="container">
<p>{{t 'regenerate_selfsigned_cert_message'}}</p>
<a href="#/domains/{{name}}/cert-regen-selfsigned" role="button" class="btn btn-warning">
<button class="btn btn-warning" data-domain="{{name}}" data-action="regen-selfsigned">
<span class="fa-refresh"></span> {{t 'regenerate_selfsigned_cert'}}
</a>
</button>
</div>
<hr>
{{/if}}
{{#if actions_enabled.replace_with_selfsigned}}
<div class="container">
<p>{{t 'revert_to_selfsigned_cert_message'}}</p>
<a href="#/domains/{{name}}/cert-replace-with-selfsigned" role="button" class="btn btn-danger">
<button class="btn btn-danger" data-domain="{{name}}" data-action="replace-with-selfsigned">
<span class="fa-exclamation-triangle"></span> {{t 'revert_to_selfsigned_cert'}}
</a>
</button>
</div>
{{/if}}
</div>