console.log();
let ssl_list = JSON.parse('{{mod.listssl|raw}}');
let uchip = null;
let ssl_table = null;
$(document).ready(function() {
{% if mod.isie == 1 %}
uchip = new $.Uchip();
{% else %}
uchip = new Uchip();
{% endif %}
listSLL(ssl_list);
});
function listSLL(list){
ssl_list = list;
let table_content = '';
let index = 0;
if(ssl_list.length > 0){
let html_content = '';
let index = 0;
ssl_list.forEach(function(ssl){
let extra_san = '{{langmod.SSLNONELABEL}}';
if(ssl.san.length > 0){
extra_san = '';
ssl.san.forEach(function(san){
extra_san += '' + san + '';
});
}
let expiration = '-';
if(ssl.sslinfo.expiration_info.date != '-'){
expiration = moment.unix(ssl.sslinfo.expiration_info.date).format('MMM DD YYYY');
if(ssl.sslinfo.expiration_info.is_expired === true){
expiration += '{{langmod.SSLEXPD}}';
}else{
expiration += '' +
'' +
'' +
'';
}
}
html_content += '
';
index++;
});
let table_html = '' +
'' +
'' +
'{{langmod.LMDOMAIN}} | ' +
'Additionals (SAN) | ' +
// 'Signed By | ' +
'{{langmod.LMEXP}} | ' +
'{{langmod.SSLACTIONS}} | ' +
'
' +
'' +
'' +
html_content +
'' +
'
';
$('#ssl_list_wrapper').html(table_html);
$('#ssl_table').DataTable().destroy();
ssl_table = $('#ssl_table').DataTable();
$('[data-toggle="tooltip"]').tooltip();
}else{
$('#ssl_list_wrapper').html('{{langmod.SSLNOTCREATED}}
');
}
}
function renderInfo(response){
let html_info = 'SUBJECT: ' + response.subject + '
';
if(response.aliases.length > 0){
html_info += 'ALIASES: ' + response.aliases.map(function(san){
return san.replace('DNS:','');
}).join(', ') + '
';
}
let issuers = response.issuer.map(function(issuer){
return issuer.param + '=' + issuer.value;
}).join(', ');
html_info += '{{langmod.SSLVALIFLAB}}: ' + response.valid_from + '
' +
'{{langmod.SSLVALIULAB}}: ' + response.valid_until + '
' +
'{{langmod.SSLSIGNLAB}}: ' + response.signature + '
' +
'{{langmod.SSLPUBKLAB}}: ' + response.public_key + '
' +
'{{langmod.SSLISSUERLAB}}: ' + issuers + '
';
if(response.self_signed == true){
html_info += '{{langmod.SSLSEFLSIGNED}}
';
}
if(response.is_expired == true){
html_info += '{{langmod.SSLEXPIREDLAB}}
';
}
return '' + html_info + '
';
}
function renderFileHTML(response, title, domain, type){
return '' +
'' +
'
' + response.result + '
' +
'
' +
'
';
}
function copyFileContent(){
$('#file_content').show();
var copyText = document.getElementById('file_content');
copyText.select();
document.execCommand("copy");
$('#file_content').hide();
$('.copied-message').fadeIn('fast', function(){
setTimeout(function(){
$('.copied-message').fadeOut('fast');
}, 3500);
});
}
function infomodal(index, domain, type, title){
uchip.handleButton('#info_btn_' + index, 'fa-info');
uchip.call('module=letsencrypt&acc=infomodal', {
data:'domain=' + domain + '&type=' + type,
callback: function(response){
if(type == 'info'){
$('#modalinfo_twice .modal-body').html(renderInfo(response));
}else{
$('#modalinfo_twice .modal-body').html(renderFileHTML(response, title, domain, type));
}
$('#modalinfo_twice').modal('toggle');
setTimeout(function(){
$('[data-toggle="tooltip"]').tooltip();
}, 100);
uchip.handleButton('#info_btn_' + index, 'fa-info', true);
}
});
}
function installDomain(elem){
uchip.handleButton(elem, 'fa-lock');
$('#btn_install_title').text('Installing...');
let domain = $('#domain_lets').val();
let additionals = [];
$('.san-checkbox:checked').each(function(){
additionals.push($(this).val());
});
let path = $('#domain_lets').find('option:selected').data('path');
let data = 'domain=' + domain + '&additionals=' + additionals.join(',') + '&path=' + path;
uchip.call('module=letsencrypt&acc=addssl', {
data: data,
callback: function(response){
if(response.result == 'success'){
if (response.ssl_status.san_excluded.length > 0 && response.ssl_status.san_excluded[0] !== ""){
noti_bubble('{{langmod.SSLCREATED1}}
' +
'{{langmod.SSLCREATED2}}:
' +
response.ssl_status.san_excluded.join(', '),'{{langmod.SSLALEROK}}','warning',false,false,'9500',true);
}else{
noti_bubble('{{langmod.SSLOK}}','{{langmod.SSLALEROK}}','success',false,false,'3000',true);
}
ssl_list.push(response.domaindata);
listSLL(ssl_list);
cancelInstallation(domain);
}else{
let message = '{{langmod.SSLERRORDO}}';
if(response.code == 2){
message = '{{langmod.SSLINVALIDPATH}}';
}else if(response.code == 1){
message = '{{langmod.SSLINVALIDOM}}';
}else if(response.code == 3){
message = '{{langmod.SSLERRODNS}}';
}
uchip.handleButton(elem, 'fa-lock', true);
$('#btn_install_title').text('{{langmod.LMINSTALL}}');
noti_bubble(message,'{{langmod.SSLVALIDATEERROR}}','error',false,false,'3000',true);
}
}
});
}
function validatevhost(elem){
let domain = $(elem).val();
$('#services_toinstall').slideUp();
if($(elem).val() == ''){
$('#btn-lets-add').attr('disabled',true);
$('#btn-lets-add').addClass('disabled');
}else{
$(elem).prop('disabled',true);
$(elem).addClass('disabled');
uchip.handleButton('#btn-lets-add', 'fa-lock');
let optselected = $(elem).find('option:selected');
let is_subdomain = optselected.data('is_subdomain');
let subdomains = optselected.data('subdomains');
$('#btn_install_title').text('{{langmod.SSLVALID}}');
uchip.call('module=letsencrypt&acc=validatedomain', {
data:'domain=' + domain + '&is_subdomain=' + is_subdomain,
callback: function(response){
if(response.result == 'success'){
uchip.handleButton('#btn-lets-add', 'fa-lock', true);
if(!is_subdomain && response.subdomains.length > 0){
let html_san = '';
response.subdomains.forEach(function(sub, i){
html_san += '' +
'' +
'' +
'
';
});
$('#services_toinstall_items').html(html_san);
$('#services_toinstall').slideDown();
}
}else{
let message = '{{langmod.SLLUNKERROR}}';
if(response.hasOwnProperty('code')){
if(response.code == 1){
message = '{{langmod.SSLTRYUPDT}}';
}else{
message = '{{langmod.SSLERRODNS}}';
}
}
uchip.handleButton('#btn-lets-add', 'fa-lock', true);
$('#btn-lets-add').prop('disabled',true);
$('#btn-lets-add').addClass('disabled');
noti_bubble(message,'{{langmod.SSLVALIDATEERROR}}','error',false,false,'5000',true);
}
$('#btn_install_title').text('{{langmod.LMINSTALL}}');
$(elem).prop('disabled',false);
$(elem).removeClass('disabled');
}
});
}
return;
}
function cancelInstallation(nossl){
$('#btn-lets-add').find('.fa').removeClass('fa-spinner fa-spin');
$('#btn-lets-add').find('.fa').addClass('fa-lock');
$('#btn_install_title').text('{{langmod.LMINSTALL}}');
$('.san-checkbox').each(function(){
$(this).prop('checked', false);
});
if (Array.isArray(nossl)){
let select_html = '';
$('#sel_domain_container').html(select_html);
}else{
$("#domain_lets option[value='" + nossl + "']").remove();
}
$('#services_toinstall').slideUp();
}
function deletessl(st, domain, index){
if(st == 0){
let san = $('#btn_del_' + index).data('san');
let strbody = '{{langmod.SSLDELETE1}}:
' +
'' + domain + '';
if(san.length > 0){
strbody += '
{{langmod.SSLDELETE2}}:
' + san.join(',') + '
';
}
strbody += '
{{langmod.SSLDELETE3}}
';
let strfooter = '' +
'';
$('#deleteletsencrypt .modal-body').html(strbody);
$('#deleteletsencrypt .modal-footer').html(strfooter);
$('#deleteletsencrypt').modal('toggle');
return false;
}else{
$('#deleteletsencrypt').modal('hide');
uchip.handleButton('#btn_del_' + index,'fa-trash');
let tr = $('#trssl_' + index);
tr.find('.btn').prop('disabled', true).addClass('disabled');
tr.addClass('deleting_tr');
uchip.call('module=letsencrypt&acc=deletessl', {
data:'domain=' + domain,
callback: function(response){
if(response.result == 'success'){
tr.slideUp('fast', function(){
ssl_table.row(this).remove().draw();
ssl_list.splice(index, 1);
});
noti_bubble('{{langmod.SSLOK}}','{{langmod.SSLALEROK}}','success',false,false,'3000',true);
cancelInstallation(response.nossl);
}else{
tr.find('.btn').prop('disabled', false).removeClass('disabled');
tr.removeClass('deleting_tr');
uchip.handleButton('#btn_del_' + index,'fa-trash', true);
noti_bubble('An unknown error occurred, please try again.','{{langmod.SSLVALIDATEERROR}}','error',false,false,'3000',true);
}
}
});
// $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } });
// $.ajax({
// type: "POST",
// url: "./{{users}}/index.php?module=letsencrypt&acc=delete",
// data: "domain="+domain,
// complete: function(datos){
// $("#sslbody").html(datos.responseText);
// noti_bubble('{{langmod.SSLOK}}','{{langmod.SSLALEROK}}','success',false,false,'3000',true);
// $("#deletemodal").modal('hide');
// return false;
// }
// });
// return false;
}
}
function forcerenew(elem, domain){
uchip.handleButton(elem, 'fa-retweet');
uchip.call('module=letsencrypt&acc=forcerenew', {
data:'domain=' + domain,
callback: function(response){
if(response.result == 'success'){
if(response.ssl_status.san_excluded.length > 0){
noti_bubble('{{langmod.SSLRENEW1}}
' +
'{{langmod.SSLRENEW2}}:
' +
response.ssl_status.san_excluded.join(', '),'{{langmod.SSLALEROK}}','warning',false,false,'9500',true);
}else{
noti_bubble('{{langmod.SSLOK}}','{{langmod.SSLALEROK}}','success',false,false,'3000',true);
}
listSLL(response.list);
}else{
let message = '{{langmod.SSLRENEW3}}';
if(response.code == 4){
message = '{{langmod.SSLRENEW4}}';
}else if(response.code == 3){
message = '{{langmod.SSLERRODNS}}';
}else if(response.code == 5){
message = '{{langmod.SSLRENEW5}}';
}
noti_bubble(message ,'{{langmod.SSLVALIDATEERROR}}','error',false,false,'3000',true);
}
}
});
}
// CECILIO MORALES JS
function updlistssl(){
$.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } });
$.ajax({
type: "POST",
url: "./{{users}}/index.php?module=letsencrypt&acc=list",
complete: function(datos){
$("#sslbody").html(datos.responseText);
return false;
}
});
}
$("#forceallrenew").click(function () {
$("#forceallrenew").attr('disabled', true);
$("#forceallrenew").addClass('disabled');
$.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } });
$.ajax({
type: "POST",
url: "./{{users}}/index.php?module=letsencrypt&acc=forceallrenew",
complete: function(datos){
updlistssl();
$("#forceallrenew").attr('disabled', false);
$("#forceallrenew").removeClass('disabled');
return false;
}
});
});