console.log(); let uchip = null; let backup_table = null; let backup_list = JSON.parse('{{mod.backup|json_encode|raw}}'); let initial_state = JSON.parse('{{mod.initial_state|json_encode|raw}}'); let new_files = []; $(document).ready(function() { {% if mod.isie == 1 %} uchip = new $.Uchip(); {% else %} uchip = new Uchip(); {% endif %} listBackup(backup_list); listBackupSelect(backup_list); backupStats(); handleInitialState(); $('#accordion1').on('hidden.bs.collapse', toggleIcon); $('#accordion1').on('shown.bs.collapse', toggleIcon); }); function toggleIcon(e) { $(e.target) .prev('.panel-heading') .find(".more-less") .toggleClass('glyphicon-plus glyphicon-minus'); } function handleInitialState(){ if(initial_state.account_st == 1){ checkState('account', '#btn-account'); } if(initial_state.mysql_st == 1){ checkState('mysql', '#btn-mysql'); } if(initial_state.homedir_st == 1){ checkState('homedir', '#btn-homedir'); } if(initial_state.mail_st == 1){ checkState('mail', '#btn-mail'); } if(initial_state.ssl_st == 1){ checkState('ssl', '#btn-ssl'); } } function show_options_restore(typevalue){ if(typevalue!=''){ $(".restore-with-info").slideDown('slow'); }else{ $(".restore-with-info").slideUp('slow'); } $(".restore_files_mysql").slideUp('slow'); $("#restore_all_content").prop("checked",true); $("#restore_partial_content").prop("checked",false); } function checkState(type, button){ uchip.call('module=backups&acc=checkstate', { data: "&type=" + type, callback: function(res){ if(res.changed === true){ if(res.file != false){ new_files.push(res.file) listBackup(res.backup_list); noti_bubble($(button).text() + ' {{langmod.BCSUCCALCRE}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); }else{ noti_bubble('{{langmod.BCERROALCRE1}} ' + $(button).text() + ' {{langmod.BCERROALCRE2}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); } let icon = $(button).data('icon'); uchip.handleButton(button, icon, false); }else{ setTimeout(function(){ checkState(type, button); },5000) } } }); } function ajaxcreatebackup(elem){ $(elem).parent().find('.tooltip').remove(); let icon = $(elem).data('icon'); let type = $(elem).data('type'); uchip.handleButton(elem, icon); uchip.call('module=backups&acc=test', { data: "&typefile=" + type, callback: function(res){ checkState(type, elem); } }); } function testFTPConnection(elem){ if(uchip.validator('.ftp_config')){ uchip.handleButton(elem, 'fa-plug'); let pass = Base64.encode($('#backup_ftp_pass').val()); uchip.call('module=backups&acc=testftp', { data: "server=" + $('#backup_ftp_server').val() + "&port=" + $('#backup_ftp_port').val() + "&user=" + $('#backup_ftp_user').val() + "&pass=" + pass, callback: function(res){ if(res.result == 'success'){ noti_bubble('{{langmod.BCTESTFTPS}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); }else{ noti_bubble('{{langmod.BCTESTFTPE}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); } uchip.handleButton(elem, 'fa-plug', true); } }); } } function saveAutoBackup(elem){ let valid = true; if(!uchip.validator('.email-required')){ valid = false; } if($('#auto_location_ftp').is(':checked') && !uchip.validator('.ftp_config')){ valid = false; } if(!valid){ return; } let data = ''; $('.auto-backup-input').each(function(){ let input = $(this); data += input.attr('id') + '='; if(input.attr('type') === 'checkbox' || input.attr('type') === 'radio'){ data += input.is(':checked') ? 1 : 0; }else if(input.attr('type') === 'text' || input.hasClass('auto-backup-input-select')){ data += input.val(); } data += '&'; }); uchip.handleButton(elem, 'fa-floppy-o'); uchip.call('module=backups&acc=saveauto', { data: data, callback: function(response){ uchip.handleButton(elem, 'fa-floppy-o', true); noti_bubble('{{langmod.BCAUTOCONFOK}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); } }); } function backupStats(){ let html_stats = ''; let size='{{mod.sizehome}}'; size=(size!='')?size:1; let quota='{{mod.packquota}}'; quota=(quota!='')?quota:1; let homedir = size / 1024; let total_quota = quota * 1024 * 1024; let homedir_percent = (homedir * 100) / total_quota; html_stats = '
' + ' | {{ langmod.LABELDB02 }} | ' + '' + ' |
---|
{{langmod.EDELETEEMAIL}}
'; var strfooter = ''; $("#deletemodalmail .modal-header").html(strheader); $("#deletemodalmail .modal-body").html(strbody); $("#deletemodalmail .modal-footer").html(strfooter); $("#deletemodalmail").modal('toggle'); } function verify_checboxdb(typecheck){ if($(".checkdb:checked").length > 0){ $(".restbtndb").removeClass('disabled'); }else{ $(".restbtndb").addClass('disabled'); } } function restoreallaccount(){ $("#deletemodalmail").modal('hide'); $(".allaccount i").removeClass("fa-download").addClass("fa-spinner fa-spin"); $(".allaccount").addClass("disabled"); uchip.call('module=backups&acc=restoreallaccount', { data: 'nameFile='+$("#selectBack").val(), callback: function(response){ $(".allaccount i").removeClass("fa-spinner fa-spin").addClass("fa-download"); $(".allaccount").removeClass("disabled"); noti_bubble('{{ langmod.LABELSUCCESSRES02 }}','{{ langmod.LABELSUCEES02 }}','success',false,false,'3000',true); } }); } function restoreAlldatabase(){ $("#deletemodalmail").modal('hide'); $(".alldb i").removeClass("fa-download").addClass("fa-spinner fa-spin"); uchip.call('module=backups&acc=restoreAlldatabase', { data: 'nameFile='+$("#selectBack").val(), callback: function(response){ $(".alldb i").removeClass("fa-spinner fa-spin").addClass("fa-download"); noti_bubble('{{ langmod.LABELSUCCESSRESDB02 }}','{{ langmod.LABELSUCEES02 }}','success',false,false,'3000',true); } }); } function restoreallFiles(){ $("#deletemodalmail").modal('hide'); $(".allfiles i").removeClass("fa-download").addClass("fa-spinner fa-spin"); uchip.call('module=backups&acc=restoreallFile', { data: 'nameFile='+$("#selectBack").val(), callback: function(response){ $(".allfiles i").removeClass("fa-spinner fa-spin").addClass("fa-download"); noti_bubble('{{ langmod.LABELSUCCESSRESFIL02 }}','{{ langmod.LABELSUCEES02 }}','success',false,false,'3000',true); } }); } function restorefiles(pathfile,cont){ $("#deletemodalmail").modal('hide'); let filesSend=''; if(pathfile==''){ if($(".checkfiles").filter(':checked').length == 0){ noti_bubble('{{ langmod.LABELERRORFILE02 }}','{{ langmod.LABELERROR02 }}','error',false,false,'3000',true); return false; } $(".restbtnfile i").removeClass("fa-check-square").addClass("fa-spinner fa-spin"); $(".checkfiles").each(function(){ if($(this).is(":checked")){ filesSend += '&filesSelected[]='+$(this).val(); } }); }else{ $(".btf"+cont+" i").removeClass("fa-download").addClass("fa-spinner fa-spin"); $(".btf"+cont+"").addClass("disabled"); filesSend = '&filesSelected[]='+pathfile } uchip.call('module=backups&acc=restoreFile', { data: 'nameFile='+$("#selectBack").val()+filesSend, callback: function(response){ $(".btf"+cont+"").removeClass("disabled"); $(".btf"+cont+" i").removeClass("fa-spinner fa-spin").addClass("fa-download"); noti_bubble('{{ langmod.LABELSUCCESSRESFIL02 }}','{{ langmod.LABELSUCEES02 }}','success',false,false,'3000',true); $(".restbtnfile i").removeClass("fa-spinner fa-spin").addClass("fa-check-square"); $(".checkfiles").prop("checked",false); } }); } function listFilesback(pathFile){ if(pathFile!='home/'){ $(".backbtn").removeClass('disabled'); }else{ $(".backbtn").addClass('disabled'); } $(".restore_files_mysql").slideDown('slow'); $(".restore_allaccount").slideUp('fast'); $('#backup_table_files').html('' + ' | {{ langmod.LABELFILETIT02 }} | ' + '' + ' |
---|
File | ' + 'Size | ' + 'Creation date | ' + 'Actions | ' + '
---|
{{langmod.BCDELTIT1}}
'; strbody += '' + file + '
'; strbody += '{{langmod.BCDELTIT2}}
'; var strfooter = ''; $("#deletemodal .modal-footer").html(strfooter); $("#deletemodal .modal-body").html(strbody); $("#deletemodal .modal-header").html(strheader); ///btnporcess('on','btnyesdel','{{ langmod.DYES }}'); $("#deletemodal").modal('toggle'); return false; }else{ $("#deletemodal").modal('hide'); let btn = '#btn_del_' + index; let tr = $('#tr_bckfile_' + index); tr.addClass('deleting_tr'); uchip.handleButton(btn, 'fa-trash'); uchip.call('module=backups&acc=delete', { data: "file=" + file, callback: function(res){ if(res.result == 'success'){ noti_bubble('{{langmod.BCDELETEOK}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); tr.slideUp('fast', function(){ backup_table.row(this).remove().draw(); }); }else{ tr.removeClass('deleting_tr'); uchip.handleButton(btn,'fa-trash', true); noti_bubble('{{langmod.BCERRODEL}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); } } }); } } function dumpSql(elem){ if(!uchip.validator('#backup_db')){ return false; } let db = $('#backup_db').val(); uchip.handleButton(elem, 'fa-database'); let data_send = "db=" + db; uchip.call('module=mysql_manager&acc=dumpsql', { data: data_send, callback: function(response){ if(response.result == 'success'){ noti_bubble('{{langmod.BSBACKUPOK}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); window.open('./{{users}}/index.php?module=mysql_manager&acc=download_backup&identifier=' + response.identifier, '_blank'); }else{ noti_bubble('{{langmod.BCGENERROR}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); } uchip.handleButton(elem, 'fa-database', true); } }); } // CECILIO MORALES JS function searchbackup(){ var spin = ''; $("#restselect").html(spin); $("#restradio").html(spin); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=backups&acc=type", complete: function(datos){ //console.log(datos.responseText); //alert(datos.responseText); var str = datos.responseText; var trozo = str.split('|@|'); $("#restselect").html(trozo[0]); $("#restradio").html(trozo[1]); return false; } }); return false; } function restoreback(st,file,row){ if(st==0){ $("#btndole"+row).hide(); $("#btnacition"+row).show(); $("#hiddenvalue").val(file+'||'+row); $("#myModaldetail").modal('toggle'); } if(st==1){ $("#hiddenvalue").val(file+'||'+row); $("#myModaldetail").modal('toggle'); return false; } if(st==2){ $("#btnacition"+row).hide(); $("#btndole"+row).show(); } if(st==3){ var sw=''; if($("#homeuser2").prop('checked')){sw=sw+'homeuser||';} if($("#mysqluser2").prop('checked')){sw=sw+'mysqluser||';} if($("#mailuser2").prop('checked')){sw=sw+'mailuser||';} if($("#ftpaccounts2").prop('checked')){sw=sw+'ftpaccounts||';} if($("#nameds2").prop('checked')){sw=sw+'nameds||';} if($("#passaccount").prop('checked')){sw=sw+'passaccount||';} if(sw!=''){ var trozval=$("#hiddenvalue").val(); var trozo =trozval.split('||'); var row =trozo[1]; var file =trozo[0]; $("#myModaldetail").modal('toggle'); $("#btn-restorenow"+row).html(' {{langmod.BCLABEL18}}'); $("#btn-restorenow"+row).addClass('disabled'); $("#btn-restorenow"+row).attr('disabled',true); $("#btn-restorecancel"+row).hide(); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=backups&acc=restoreback", data:"file="+file+"&options="+sw, complete: function(datos){ console.log(datos.responseText); if(datos.responseText==1){ $("#btnacition"+row).hide(); $("#btndole"+row).show(); noti_bubble('{{ langmod.BCLABEL15 }}','{{ langmod.BCSUCCT }}','success',false,false,'3000',true); }else{ noti_bubble('{{ langmod.BCLABEL22 }}','{{ langmod.BCLABEL12 }}','error',false,false,'5000',true); $("#btnacition"+row).hide(); $("#btndole"+row).show(); } return false; } }); }else{ noti_bubble('{{ langmod.BCLABEL21 }}','{{ langmod.BCLABEL12 }}','error',false,false,'5000',true); return false; } } return false; } function typerestore(sw){ if(sw==0){ $("#backupfile").hide('blind'); $("#serverbackup").show('blind'); $("#btnretoreuser").show(); searchbackup(); }else{ $("#serverbackup").hide('blind'); $("#backupfile").show('blind'); $("#btnretoreuser").hide(); } } $("#btnretoreuser").click(function(){ if($("#selecttypebackup").val()==''){ noti_bubble('{{langmod.BCLABEL11}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); return false; } var restaure =''; var homeuser =0; var mysqluser =0; var mailuser =0; var ftp =0; var named =0; $("input:checkbox:checked").each(function() { restaure=$(this).val(); if($(this).val()=='home'){ homeuser = 1;} if($(this).val()=='mysql'){ mysqluser = 1;} if($(this).val()=='mail'){ mailuser = 1;} if($(this).val()=='ftp'){ ftp = 1;} if($(this).val()=='named'){ named = 1;} }); if(restaure==''){ noti_bubble('{{langmod.BCLABEL13}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); return false; } var selecttypebackup = $("#selecttypebackup").val(); $("#btnretoreuser").attr('disabled',true); $("#btnretoreuser").addClass('disabled'); $("#btnretoreuser").html(' {{ langmod.BCLABEL14 }}'); $("#btnretoreuser").removeClass('btn-success'); $("#btnretoreuser").addClass('btn-primary'); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); $.ajax({ type: "POST", url: "./{{users}}/index.php?module=backups&acc=restoreuserbackup", data:"homeuser="+homeuser+"&mysqluser="+mysqluser+"&mailuser="+mailuser+"&selecttypebackup="+selecttypebackup+"&ftp="+ftp+"&named="+named, complete: function(datos){ //alert(datos.responseText); if(datos.responseText=='OK'){ noti_bubble('{{langmod.BCLABEL15}}','{{langmod.BCSUCCT}}','success',false,false,'3000',true); }else{ noti_bubble('{{langmod.BCLABEL16}}','{{langmod.BCLABEL12}}','error',false,false,'3000',true); } $("#btnretoreuser").attr('disabled',false); $("#btnretoreuser").removeClass('disabled'); $("#btnretoreuser").html('{{ langmod.BTNRESTORE }}'); $("#btnretoreuser").removeClass('btn-primary'); $("#btnretoreuser").addClass('btn-success'); return false; } }); }); $("#restor_file").change(function() { $("#btn_rest_file").hide(); var file = this.files[0]; var imagefile = file.type; var match="application/gzip"; if(imagefile!=match){ noti_bubble('{{langmod.BCALERt1}}','','error',false,false,'3000',true); return false; }else{ $("#btn_rest_file ").show(); return false; } }); $("#restore_sql").change(function (){ $("#btn_rest_sql").hide(); var file = this.files[0]; var imagefile = file.type; var match="application/sql"; if(imagefile!=match){ noti_bubble('{{langmod.BCALERt1}}','','error',false,false,'3000',true); return false; }else{ $("#btn_rest_sql ").show(); return false; } }); $('#btn_rest_sql').click(function () { noti_bubble('{{langmod.BCLOADING}}','','warning',false,false,'3000',true); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); $.ajax({ url: "./{{users}}/index.php?module=backups&acc=restore_sql", type: "POST", data: new FormData(uploadsql), contentType: false, cache: false, processData:false, success: function(data){ //$("#message2").html('{{langmod.BCBACKUPOK}}'); noti_bubble('{{langmod.BCBACKUPOK}}','','success',false,false,'3000',true); return false; } }); return false; }); $('#btn_rest_file').click(function () { noti_bubble('{{langmod.BCLOADING}}','','warning',false,false,'3000',true); $.ajaxSetup({ headers: { 'csrftoken' : '{{ tokenajax }}' } }); var uploadtargz =$("#restor_file"); $.ajax({ url: "./{{users}}/index.php?module=backups&acc=restore_file", type: "POST", data: new FormData(uploadtargz), contentType: false, cache: false, processData:false, success: function(datos){ if(datos.responseText==0){ noti_bubble('{{langmod.BCBACKUPOK}}','','success',false,false,'3000',true); }else{ var errormsj=datos.responseText; noti_bubble('{{langmod.BCBACKUPOK}}',errormsj,'error',false,false,'3000',true); } return false; } }); return false; }); $("#btn_rest_file").on('submit',(function(e) { e.preventDefault(); $("#message").empty(); $('#loading').show(); $.ajax({ url: "ajax_php_file.php", // Url to which the request is send type: "POST", // Type of request to be send, called as method data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values) contentType: false, // The content type used when sending data to the server. cache: false, // To unable request pages to be cached processData:false, // To send DOMDocument or non processed data file it is set to false success: function(data) // A function to be called if request succeeds { $('#loading').hide(); $("#message").html(data); } }); }));