1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2024-11-23 02:27:05 +00:00

bug fix on modal close and repeated cert issuance

This commit is contained in:
Ashiq5 2020-11-05 21:03:29 +06:00
parent 25ae216e00
commit 8574b43542
4 changed files with 54 additions and 32 deletions

View File

@ -367,11 +367,9 @@ def ssl_get_csr(domain):
@app.route('/ssl/renew/<domain>', methods=['POST'])
@authorized_personnel_only
def ssl_renew(domain):
from exclusiveprocess import Lock
from utils import load_environment
from ssl_certificates import provision_certificates
existing_key = request.form.get('existing_key')
Lock(die=True).forever()
env = load_environment()
if existing_key == "yes":
status = provision_certificates(env, limit_domains=[], domain_to_be_renewed=domain)

View File

@ -209,17 +209,17 @@ $(function() {
// so that we don't attempt to show another modal while this one
// is closing.
global_modal_state = 0; // OK
})
});
$('#global_modal .btn-default').click(function() {
global_modal_state = 1; // Cancel
})
});
$('#global_modal').on('hidden.bs.modal', function (e) {
// do the cancel function
if (global_modal_state == null) global_modal_state = 1; // cancel if the user hit ESC or clicked outside of the modal
if (global_modal_funcs && global_modal_funcs[global_modal_state])
global_modal_funcs[global_modal_state]();
})
})
});
function show_modal_error(title, message, callback) {
$('#global_modal h4').text(title);
@ -239,7 +239,7 @@ function show_modal_error(title, message, callback) {
return false; // handy when called from onclick
}
function show_modal_confirm(title, question, verb, yes_callback, cancel_callback) {
function show_modal_confirm(title, question, verb, yes_callback, cancel_callback, extra_callback=null) {
$('#global_modal h4').text(title);
if (typeof question == 'string') {
$('#global_modal .modal-dialog').addClass("modal-sm");
@ -256,7 +256,8 @@ function show_modal_confirm(title, question, verb, yes_callback, cancel_callback
$('#global_modal .btn-default').show().text(verb[1]);
$('#global_modal .btn-danger').show().text(verb[0]);
}
global_modal_funcs = [yes_callback, cancel_callback];
if (extra_callback) global_modal_funcs = [yes_callback, cancel_callback, extra_callback];
else global_modal_funcs = [yes_callback, cancel_callback];
global_modal_state = null;
$('#global_modal').modal({});
return false; // handy when called from onclick

View File

@ -137,46 +137,47 @@ function ssl_install(elem) {
$('html, body').animate({ scrollTop: $('#ssl_install_header').offset().top - $('.navbar-fixed-top').height() - 20 })
return false;
}
let flag = false;
function ssl_renew_or_replace_modal(elem) {
if (!flag) {
$('#global_modal .modal-footer').append('<button type="button" class="btn btn-warning" data-dismiss="modal">Renew</button>');
flag = true;
}
$('#global_modal .btn-warning').click(function() {
global_modal_state = 2; // Renew
});
show_modal_confirm(
"Options",
"Do you want to replace the certificate with a new one or just renew this one?",
["Replace", "Renew"],
"Replace",
function () {
$('#global_modal .modal-footer .btn-warning').remove();
flag = false;
ssl_install(elem);
},
}, function() {$('#global_modal .modal-footer .btn-warning').remove();flag = false;},
function () {
$('#global_modal .modal-footer .btn-warning').remove();
flag = false;
ssl_cert_renew(elem);
});
}
function ssl_cert_renew(elem) {
if (!flag) {
$('#global_modal .modal-footer').append('<button type="button" class="btn btn-warning" data-dismiss="modal">Yes</button>');
flag = true;
}
$('#global_modal .btn-warning').click(function() {
global_modal_state = 2; // Renew
});
var domain = $(elem).parents('tr').attr('data-domain');
show_modal_confirm(
"Options",
"Renewing options",
"Do you want to renew with the existing key?",
["Yes", "No"],
"No",
function () {
ajax_with_indicator(true);
api(
"/ssl/renew/" + domain,
"POST",
{
existing_key: "yes"
},
function(data) {
$('#ajax_loading_indicator').stop(true).hide();
show_modal_error(data["title"], data["log"]);
show_tls(true);
},
function () {
$('#ajax_loading_indicator').stop(true).hide();
show_modal_error("Error", "Something is not right, sorry!");
show_tls(true);
});
},
function () {
ajax_with_indicator(true);
$('#global_modal .modal-footer .btn-warning').remove();flag = false;
$('#ajax_loading_indicator').show();
api(
"/ssl/renew/" + domain,
"POST",
@ -194,7 +195,28 @@ function ssl_cert_renew(elem) {
show_tls(true);
}
);
});
}, function() {$('#global_modal .modal-footer .btn-warning').remove();flag = false;},
function () {
$('#global_modal .modal-footer .btn-warning').remove();
flag = false;
$('#ajax_loading_indicator').show();
api(
"/ssl/renew/" + domain,
"POST",
{
existing_key: "yes"
},
function(data) {
$('#ajax_loading_indicator').stop(true).hide();
show_modal_error(data["title"], data["log"]);
show_tls(true);
},
function () {
$('#ajax_loading_indicator').stop(true).hide();
show_modal_error("Error", "Something is not right, sorry!");
show_tls(true);
});
},);
}
function show_csr() {

View File

@ -39,6 +39,7 @@ apt_install openssl
# Create a directory to store TLS-related things like "SSL" certificates.
mkdir -p $STORAGE_ROOT/ssl
mkdir -p $STORAGE_ROOT/ssl-backup # creating a backup directory for ssl certs just to be safe
# Generate a new private key.
#