2017-08-04 16:28:16 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2019-02-09 14:44:30 +01:00
$backups = Backup :: getList ();
2018-09-20 12:05:22 +02:00
2020-03-09 15:29:58 +01:00
// Controllo sul requisito ZIP
2017-09-11 17:49:03 +02:00
if ( ! extension_loaded ( 'zip' )) {
echo "
< div class = 'alert alert-warning' >
2018-11-12 10:49:37 +01:00
< i class = 'fa fa-times' ></ i > " .tr('Estensione zip non supportata').'.
2018-03-22 17:20:33 +01:00
'.tr(' Il backup verrà eseguito , ma non in formato ZIP . Sarà quindi scaricabile solo tramite FTP o con copia - incolla ').' .
2017-09-11 17:49:03 +02:00
</ div > ' ;
}
2020-03-09 15:29:58 +01:00
if ( ! empty ( $backup_dir )) {
$message = tr ( 'Il percorso di backup è attualmente in: _PATH_' , [
'_PATH_' => '<b>' . slashes ( $backup_dir ) . '</b>' ,
]);
} else {
$message = tr ( 'Sembra che tu non abbia ancora specificato un percorso per il backup' ) . '.' ;
}
// Controllo sui permessi di scrittura
if ( ! is_writable ( $backup_dir ) || ! is_readable ( $backup_dir )) {
2018-03-22 17:20:33 +01:00
echo '
2020-03-09 15:29:58 +01:00
< div class = " alert alert-danger " >
< i class = " fa fa-warning " ></ i > '.$message.' < br > '.tr(' La cartella di backup indicata non è utilizzabile dal gestionale a causa di alcuni permessi di scrittura non impostati correttamente ').' .
2018-03-22 17:20:33 +01:00
</ div > ' ;
2020-03-09 15:29:58 +01:00
return ;
2018-03-22 17:20:33 +01:00
}
2020-03-09 15:29:58 +01:00
echo '<p>' . tr ( 'Il backup è molto importante perché permette di creare una copia della propria installazione e relativi dati per poterla poi ripristinare in seguito a errori, cancellazioni accidentali o guasti hardware' ) . '.</p>' ;
2020-10-29 16:48:37 +01:00
if ( string_starts_with ( $backup_dir , base_dir ())) {
2018-03-22 17:20:33 +01:00
echo '
< div class = " alert alert-warning " >
2023-03-14 16:56:33 +01:00
< i class = " fa fa-warning " ></ i > '.tr(' Per motivi di sicurezza si consiglia di modificare il percorso della cartella di backup al di fuori della cartella di OSM , possibilmente in una unità esterna . Puoi modificare il percorso di backup dal tuo file _FILE_ ' , [
2024-03-22 15:52:24 +01:00
'_FILE_' => '<b>config.inc.php</b>' ,
]) . ' .
2018-03-22 17:20:33 +01:00
</ div > ' ;
}
2019-02-09 14:44:30 +01:00
// Operazioni JavaScript
2018-09-19 17:15:01 +02:00
echo '
< script >
2019-02-09 14:44:30 +01:00
// Ripristino backup
2018-09-19 17:15:01 +02:00
function restore () {
if ( $ ( " #blob " ) . val ()) {
swal ({
title : " '.tr('Avviare la procedura?').' " ,
type : " warning " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Sì').' "
}) . then ( function ( result ) {
$ ( " #restore " ) . submit ();
})
} else {
swal ({
title : " '.tr('Selezionare un file!').' " ,
type : " error " ,
})
}
}
2019-02-09 14:44:30 +01:00
// Creazione backup
2024-03-03 17:52:50 +01:00
function creaBackup ( button ){
2019-02-09 14:44:30 +01:00
swal ({
2024-03-03 17:52:50 +01:00
title : " '.tr('Creare un nuovo backup?').' " ,
text : " '.tr('Seleziona cosa escludere dal backup:').' " ,
input : " select " ,
inputOptions : {
" exclude_attachments " : " 📎 '.tr('Allegati').' " ,
" only_database " : " 🗃️ '.tr('Tutto tranne database').' "
},
inputAttributes : {
title : " '.tr('Seleziona cosa escludere dal backup').' "
},
inputPlaceholder : " '.tr('Non escludere nulla').' " ,
2019-02-09 14:44:30 +01:00
type : " warning " ,
showCancelButton : true ,
confirmButtonClass : " btn btn-lg btn-success " ,
confirmButtonText : " '.tr('Crea').' " ,
2024-03-03 17:52:50 +01:00
}) . then ( function ( result ) {
2021-09-17 12:18:21 +02:00
let restore = buttonLoading ( button );
$ ( " #main_loading " ) . show ();
2024-03-03 17:52:50 +01:00
let selectedOption = result ;
2021-09-17 12:18:21 +02:00
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
type : " GET " ,
data : {
id_module : globals . id_module ,
op : " backup " ,
2024-03-03 17:52:50 +01:00
exclude : selectedOption
2021-09-17 12:18:21 +02:00
},
success : function ( data ) {
$ ( " #main_loading " ) . fadeOut ();
buttonRestore ( button , restore );
// Ricaricamento della pagina corrente
window . location . reload ();
},
error : function () {
swal ( " '.tr('Errore').' " , " '.tr('Errore durante la creazione del backup').' " , " error " );
renderMessages ();
buttonRestore ( button , restore );
}
});
}) . catch ( swal . noop );
2019-02-09 14:44:30 +01:00
}
// Caricamento
2019-05-29 05:19:15 +02:00
function loadSize ( number , id ){
2019-02-09 14:44:30 +01:00
$ ( " # " + id ) . html ( " '.tr('Calcolo in corso').'... " );
$ . ajax ({
url : globals . rootdir + " /actions.php " ,
2021-09-17 12:18:21 +02:00
type : " GET " ,
2019-02-09 14:44:30 +01:00
data : {
id_module : globals . id_module ,
op : " size " ,
2019-05-29 05:19:15 +02:00
number : number ,
2019-02-09 14:44:30 +01:00
},
success : function ( data ) {
$ ( " # " + id ) . html ( data );
}
});
}
2018-09-19 17:15:01 +02:00
</ script > ' ;
2019-02-09 14:44:30 +01:00
echo '
< div class = " row " >
< div class = " col-md-8 " >
2023-03-14 16:56:33 +01:00
< div class = " alert bg-light-blue-active " >
< p > '.$message.' </ p >< br >
< p > '.tr(' Spazio totale occupato dai backup : _SPAZIO_ ' , [
2024-03-22 15:52:24 +01:00
'_SPAZIO_' => '<i id="total_size"></i>' ,
]) . ' </ p >
2023-03-14 16:56:33 +01:00
< p > '.tr(' Numero di backup : _NUM_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => count ( $backups ),
]) . ' </ p >
2019-02-09 14:44:30 +01:00
</ div >
</ div >
2020-03-09 15:29:58 +01:00
2019-02-09 14:44:30 +01:00
< script >
2021-06-28 12:53:14 +02:00
loadSize ( '.count($backups).' , " total_size " );
2019-02-09 14:44:30 +01:00
</ script > ' ;
2018-10-05 12:05:33 +02:00
$upload_max_filesize = ini_get ( 'upload_max_filesize' );
2018-12-21 16:54:34 +01:00
$max_execution_time = ini_get ( 'max_execution_time' );
2020-02-07 18:13:48 +01:00
if ( setting ( 'Permetti il ripristino di backup da file esterni' )) {
2020-02-11 11:43:59 +01:00
echo '
2018-09-19 16:02:15 +02:00
< div class = " col-md-4 " >
2024-05-16 18:02:50 +02:00
< div class = " card card-success " >
< div class = " card-header with-border " >
< h3 class = " card-title " >
2018-12-21 16:54:34 +01:00
'.tr(' Ripristina backup ').' < small > ( upload_max_filesize : '.$upload_max_filesize.' ) </ small > < small > ( max_execution_time : '.$max_execution_time.' ) </ small >
2018-09-19 16:02:15 +02:00
</ h3 >
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2018-09-19 16:02:15 +02:00
< form action = " " method = " post " enctype = " multipart/form-data " id = " restore " >
< input type = " hidden " name = " op " value = " restore " >
2019-05-29 05:19:15 +02:00
{[ " type " : " file " , " name " : " blob " , " required " : 1 , " accept " : " .zip " ]}
2018-09-19 16:02:15 +02:00
2018-09-19 17:15:01 +02:00
< button type = " button " class = " btn btn-primary pull-right " onclick = " restore() " >
2018-09-19 16:02:15 +02:00
< i class = " fa fa-upload " ></ i > '.tr(' Ripristina ').' ...
</ button >
</ form >
</ div >
</ div >
2020-02-07 18:13:48 +01:00
</ div > ' ;
}
echo '
2018-09-19 16:02:15 +02:00
</ div > ' ;
2017-09-12 17:59:30 +02:00
2018-09-19 16:02:15 +02:00
// Lettura file di backup
2017-08-04 16:28:16 +02:00
if ( file_exists ( $backup_dir )) {
$backups_zip = [];
$backups_file = [];
2019-05-29 05:19:15 +02:00
foreach ( $backups as $key => $backup ) {
2020-10-29 16:48:37 +01:00
if ( string_ends_with ( $backup , '.zip' )) {
2019-05-29 05:19:15 +02:00
$backups_zip [ $key ] = $backup ;
2018-03-03 15:03:28 +01:00
} else {
2019-05-29 05:19:15 +02:00
$backups_file [ $key ] = $backup ;
2017-08-04 16:28:16 +02:00
}
}
if ( empty ( $backups_zip ) && empty ( $backups_file )) {
echo '
2020-03-09 15:29:58 +01:00
< div class = " alert alert-info " >
2017-09-11 17:49:03 +02:00
< i class = " fa fa-warning " ></ i > '.tr(' Non è ancora stato trovato alcun backup ! ').'
'.tr(' Se hai già inserito dei dati su OSM crealo il prima possibile ... ').'
</ div > ' ;
2017-08-04 16:28:16 +02:00
} else {
2017-09-11 17:49:03 +02:00
echo '
< div class = " row " >
< div class = " col-xs-12 col-md-6 " >
< h3 > '.tr(' Backup compressi ').' </ h3 > ' ;
2017-08-04 16:28:16 +02:00
if ( ! empty ( $backups_zip )) {
2019-02-09 14:44:30 +01:00
foreach ( $backups_zip as $id => $backup ) {
2017-08-04 16:28:16 +02:00
$name = basename ( $backup );
2018-03-03 15:03:28 +01:00
$info = Backup :: readName ( $backup );
2018-03-19 15:30:16 +01:00
$data = $info [ 'YYYY' ] . '-' . $info [ 'm' ] . '-' . $info [ 'd' ];
2018-03-03 15:03:28 +01:00
$ora = $info [ 'H' ] . ':' . $info [ 'i' ] . ':' . $info [ 's' ];
2024-03-22 15:52:24 +01:00
$tipo = $info [ 'AAAAAAA' ];
2017-08-04 16:28:16 +02:00
echo '
2017-09-11 17:49:03 +02:00
< div class = " callout callout-info " >
< h4 > '.tr(' Backup del _DATE_ alle _TIME_ ' , [
2024-03-22 15:52:24 +01:00
'_DATE_' => Translator :: dateToLocale ( $data ),
'_TIME_' => Translator :: timeToLocale ( $ora ),
]) . ' </ h4 >
2017-09-11 17:49:03 +02:00
< p >< small >
'.tr(' Nome del file ').' : '.$name.' < br >
2024-03-22 15:52:24 +01:00
'.tr(' Tipo ').' : '.(($tipo == ' PARTIAL ') ? ' 🟠 '.tr(' Parziale ') : ' 🟢 '.tr(' Completo ')).' < br >
2019-02-09 14:44:30 +01:00
'.tr(' Dimensione ').' : < i id = " c-'. $id .' " ></ i >
2017-09-11 17:49:03 +02:00
</ small ></ p >
2020-03-09 15:29:58 +01:00
2019-02-09 14:44:30 +01:00
< script >
2019-05-29 05:19:15 +02:00
loadSize ( " '. $id .' " , " c-'. $id .' " );
2019-02-09 14:44:30 +01:00
</ script >
2020-03-09 15:29:58 +01:00
2020-09-23 17:53:19 +02:00
< a class = " btn btn-primary " href = " '.base_path().'/modules/backups/actions.php?op=getfile&number='. $id .' " target = " _blank " >< i class = " fa fa-download " ></ i > '.tr(' Scarica ').' </ a >
2017-09-11 17:49:03 +02:00
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
2021-10-26 13:08:27 +02:00
< a class = " btn btn-warning ask " data - backto = " record-edit " data - method = " post " data - op = " restore " data - number = " '. $id .' " data - msg = " '.tr('Clicca su Ripristina per ripristinare questo backup').' " data - button = " Ripristina " data - class = " btn btn-lg btn-warning " >
< i class = " fa fa-upload " ></ i > '.tr(' Ripristina ').'
2018-09-19 16:02:15 +02:00
</ a >
2019-05-29 05:19:15 +02:00
< a class = " btn btn-danger ask " title = " '.tr('Elimina backup').' " data - backto = " record-list " data - op = " del " data - number = " '. $id .' " >
2018-09-19 16:02:15 +02:00
< i class = " fa fa-trash " ></ i >
</ a >
</ div >
2017-09-11 17:49:03 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-11 17:49:03 +02:00
} else {
echo '
2023-03-14 16:56:33 +01:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr(' Non è stato trovato alcun backup di questa tipologia . ').'
2017-09-11 17:49:03 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-11 17:49:03 +02:00
echo '
</ div >
< div class = " col-xs-12 col-md-6 " >
< h3 > '.tr(' Backup non compressi ').' </ h3 > ' ;
2017-08-04 16:28:16 +02:00
// Backup non compressi e quindi non scaricabili
if ( ! empty ( $backups_file )) {
foreach ( $backups_file as $backup ) {
$name = basename ( $backup );
2018-03-03 15:03:28 +01:00
$info = Backup :: readName ( $backup );
2018-03-19 15:30:16 +01:00
$data = $info [ 'YYYY' ] . '-' . $info [ 'm' ] . '-' . $info [ 'd' ];
2018-03-03 15:03:28 +01:00
$ora = $info [ 'H' ] . ':' . $info [ 'i' ] . ':' . $info [ 's' ];
2017-09-08 13:24:48 +02:00
2017-08-04 16:28:16 +02:00
echo '
2017-09-11 17:49:03 +02:00
< div class = " callout callout-warning " >
< h4 > '.tr(' Backup del _DATE_ alle _TIME_ ' , [
2024-03-22 15:52:24 +01:00
'_DATE_' => Translator :: dateToLocale ( $data ),
'_TIME_' => Translator :: timeToLocale ( $ora ),
]) . ' </ h4 >
2017-09-11 17:49:03 +02:00
< p >< small >
'.tr(' Nome del file ').' : '.$name.' < br >
2019-02-09 14:44:30 +01:00
'.tr(' Dimensione ').' : < i id = " n-'. $id .' " ></ i >
2017-09-11 17:49:03 +02:00
</ small ></ p >
2020-03-09 15:29:58 +01:00
2019-02-09 14:44:30 +01:00
< script >
2019-05-29 05:19:15 +02:00
loadSize ( " '. $id .' " , " n-'. $id .' " );
2019-02-09 14:44:30 +01:00
</ script >
2017-09-11 17:49:03 +02:00
< a class = " btn btn-sm btn-warning disabled " href = " javascript:; " >< i class = " fa fa-times " ></ i > '.tr(' Non scaricabile ').' </ a >
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
2019-05-29 05:19:15 +02:00
< a class = " btn btn-warning ask " data - backto = " record-edit " data - method = " post " data - op = " restore " data - number = " '. $id .' " data - msg = " '.tr('Vuoi ripristinare questo backup?').' " data - button = " Ripristina " data - class = " btn btn-lg btn-warning " >
2018-09-19 16:02:15 +02:00
< i class = " fa fa-upload " ></ i >
</ a >
2019-05-29 05:19:15 +02:00
< a class = " btn btn-danger ask " title = " '.tr('Elimina backup').' " data - backto = " record-list " data - op = " del " data - number = " '. $id .' " >
2018-09-19 16:02:15 +02:00
< i class = " fa fa-trash " ></ i >
</ a >
</ div >
2017-09-11 17:49:03 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-11 17:49:03 +02:00
} else {
echo '
2023-03-14 16:56:33 +01:00
< div class = " alert alert-info " >
< i class = " fa fa-info-circle " ></ i > '.tr(' Non è stato trovato alcun backup di questa tipologia . ').'
2017-09-11 17:49:03 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-11 17:49:03 +02:00
echo '
</ div >
</ div > ' ;
2017-08-04 16:28:16 +02:00
}
} else {
echo '
2017-09-11 17:49:03 +02:00
< div class = " alert alert-danger " > '.tr(' La cartella di backup non esiste ! ').' '.tr(' Non è possibile eseguire i backup ! ').' </ div > ' ;
2017-08-04 16:28:16 +02:00
}
2019-02-09 14:44:30 +01:00
// Creazione backup
2017-09-11 17:49:03 +02:00
if ( ! empty ( $backup_dir )) {
2017-08-04 16:28:16 +02:00
echo '
2024-03-02 23:04:03 +01:00
< div class = " btn-group pull-right " >
< a class = " btn btn-primary " aria - haspopup = " true " aria - expanded = " false " onclick = " creaBackup(this) " >
2024-03-03 12:55:26 +01:00
< i class = " fa fa-archive " ></ i > '.tr(' Crea backup ').'
2024-03-02 23:04:03 +01:00
</ a >
</ div >
2019-02-09 14:44:30 +01:00
< div class = " clearfix " ></ div > ' ;
2017-08-04 16:28:16 +02:00
}