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' ;
switch ( filter ( 'op' )) {
case 'getfile' :
2019-05-29 05:19:15 +02:00
$number = filter ( 'number' );
$number = intval ( $number );
2017-08-04 16:28:16 +02:00
2019-05-29 05:19:15 +02:00
$backups = Backup :: getList ();
$backup = $backups [ $number ];
2024-05-23 11:36:25 +02:00
$filename = basename (( string ) $backup );
2019-05-29 05:19:15 +02:00
download ( $backup , $filename );
2017-08-04 16:28:16 +02:00
break ;
case 'del' :
2019-05-29 05:19:15 +02:00
$number = filter ( 'number' );
$number = intval ( $number );
$backups = Backup :: getList ();
$backup = $backups [ $number ];
2024-05-23 11:36:25 +02:00
$filename = basename (( string ) $backup );
2017-09-11 17:49:03 +02:00
2019-05-29 05:19:15 +02:00
delete ( $backup );
2017-08-04 16:28:16 +02:00
2019-05-29 05:19:15 +02:00
if ( ! file_exists ( $backup )) {
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Backup _FILE_ eliminato!' , [
2019-05-29 05:19:15 +02:00
'_FILE_' => '"' . $filename . '"' ,
2018-07-07 13:56:22 +02:00
]));
2017-08-04 16:28:16 +02:00
} else {
2018-07-19 17:29:21 +02:00
flash () -> error ( tr ( " Errore durante l'eliminazione del backup _FILE_! " , [
2019-05-29 05:19:15 +02:00
'_FILE_' => '"' . $filename . '"' ,
2018-07-07 13:56:22 +02:00
]));
2017-08-04 16:28:16 +02:00
}
break ;
case 'backup' :
2024-03-22 15:52:24 +01:00
$ignores = [ 'dirs' => [], 'files' => []];
2024-03-02 23:04:03 +01:00
2024-03-22 15:52:24 +01:00
if ( filter ( 'exclude' ) == 'exclude_attachments' ) {
$ignores = [ 'dirs' => [ 'files' ]];
} elseif ( filter ( 'exclude' ) == 'only_database' ) {
$ignores = [ 'dirs' => [ 'vendor' , 'update' , 'templates' , 'src' , 'plugins' , 'modules' , 'logs' , 'locale' , 'lib' , 'include' , 'files' , 'config' , 'assets' , 'api' ], 'files' => [ '*.php' , '*.md' , '*.json' , '*.js' , '*.xml' , '.*' ]];
2024-03-02 23:04:03 +01:00
}
2024-03-22 15:52:24 +01:00
2021-09-17 12:18:21 +02:00
try {
2024-03-04 02:07:58 +01:00
$result = Backup :: create ( $ignores );
2021-09-17 12:18:21 +02:00
if ( $result ) {
flash () -> info ( tr ( 'Nuovo backup creato correttamente!' ));
} else {
flash () -> error ( tr ( 'Errore durante la creazione del backup!' ) . ' ' . str_replace ( '_DIR_' , '"' . $backup_dir . '"' , tr ( 'Verifica che la cartella _DIR_ abbia i permessi di scrittura!' )));
}
2024-01-15 15:30:45 +01:00
} catch ( Exception $e ) {
2021-09-17 12:18:21 +02:00
flash () -> error ( tr ( 'Errore durante la creazione del backup!' ) . ' ' . $e -> getMessage ());
2017-08-04 16:28:16 +02:00
}
2019-02-09 14:44:30 +01:00
break ;
case 'size' :
2019-05-29 05:19:15 +02:00
$number = filter ( 'number' );
$number = intval ( $number );
2019-02-09 14:44:30 +01:00
2019-05-29 05:19:15 +02:00
$backups = Backup :: getList ();
2020-03-09 15:29:58 +01:00
$backup = $backups [ $number ] ? : $backup_dir ;
2019-05-29 05:19:15 +02:00
echo Util\FileSystem :: size ( $backup );
2019-02-09 14:44:30 +01:00
2017-08-04 16:28:16 +02:00
break ;
}
2018-09-19 16:02:15 +02:00
if ( filter ( 'op' ) == 'restore' ) {
if ( ! extension_loaded ( 'zip' )) {
flash () -> error ( tr ( 'Estensione zip non supportata!' ) . '<br>' . tr ( 'Verifica e attivala sul tuo file _FILE_' , [
2024-03-22 15:52:24 +01:00
'_FILE_' => '<b>php.ini</b>' ,
]));
2018-09-19 16:02:15 +02:00
return ;
}
2024-04-10 10:09:24 +02:00
$number = filter ( 'number' );
2024-04-22 12:35:30 +02:00
if ( $number === null ) {
2019-05-29 05:19:15 +02:00
$path = $_FILES [ 'blob' ][ 'tmp_name' ];
2018-09-19 16:02:15 +02:00
} else {
2024-04-10 10:09:24 +02:00
$number != '' ? $number : 0 ;
2019-05-29 05:19:15 +02:00
$number = intval ( $number );
$backups = Backup :: getList ();
$path = $backups [ $number ];
2018-09-19 16:02:15 +02:00
}
2023-08-04 14:54:28 +02:00
2024-03-20 15:42:07 +01:00
try {
$result = Backup :: restore ( $path , is_file ( $path ));
$database -> beginTransaction ();
if ( $result ) {
flash () -> warning ( tr ( 'Ripristino eseguito correttamente!' ));
} else {
flash () -> error ( tr ( 'Errore durante il ripristino del backup!' ) . '<br>' . $result );
}
} catch ( Exception $e ) {
flash () -> error ( tr ( 'Errore durante il ripristino del backup!' ) . ' ' . $e -> getMessage ());
}
2018-09-19 16:02:15 +02:00
}