2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
switch ( filter ( 'op' )) {
case 'getfile' :
$file = filter ( 'file' );
2017-09-11 17:49:03 +02:00
download ( $backup_dir . $file , $file );
2017-08-04 16:28:16 +02:00
break ;
case 'del' :
$file = filter ( 'file' );
2017-09-11 17:49:03 +02:00
delete ( $backup_dir . $file );
2017-08-04 16:28:16 +02:00
2017-09-08 13:24:48 +02:00
if ( ! file_exists ( $backup_dir . $file )) {
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Backup _FILE_ eliminato!' , [
2017-09-10 14:35:41 +02:00
'_FILE_' => '"' . $file . '"' ,
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_! " , [
2017-09-10 14:35:41 +02:00
'_FILE_' => '"' . $file . '"' ,
2018-07-07 13:56:22 +02:00
]));
2017-08-04 16:28:16 +02:00
}
break ;
case 'backup' :
2018-03-03 15:03:28 +01:00
if ( Backup :: create ()) {
2018-07-19 17:29:21 +02:00
flash () -> info ( tr ( 'Nuovo backup creato correttamente!' ));
2017-09-12 17:59:30 +02:00
} else {
2018-07-19 17:29:21 +02:00
flash () -> error ( tr ( 'Errore durante la creazione del backup!' ) . ' ' . tr_replace ( '_DIR_' , '"' . $backup_dir . '"' , tr ( 'Verifica che la cartella _DIR_ abbia i permessi di scrittura!' )));
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_' , [
'_FILE_' => '<b>php.ini</b>' ,
]));
return ;
}
if ( post ( 'folder' ) == null ) {
$file = $_FILES [ 'blob' ][ 'tmp_name' ] ? : post ( 'zip' );
// Lettura dell'archivio
$zip = new ZipArchive ();
if ( ! $zip -> open ( $file )) {
flash () -> error ( tr ( 'File di installazione non valido!' ));
flash () -> error ( checkZip ( $file ));
return ;
}
// Percorso di estrazione
$extraction_dir = $docroot . '/tmp' ;
directory ( $extraction_dir );
// Estrazione dell'archivio
$zip -> extractTo ( $extraction_dir );
$zip -> close ();
} else {
$extraction_dir = $backup_dir . '/' . post ( 'folder' );
}
// Rimozione del database
$tables = include $docroot . '/update/tables.php' ;
$database -> query ( 'SET foreign_key_checks = 0' );
foreach ( $tables as $tables ) {
$database -> query ( 'DROP TABLE `' . $tables . '`' );
}
$database -> query ( 'DROP TABLE `updates`' );
// Ripristino del database
$database -> multiQuery ( $extraction_dir . '/database.sql' );
$database -> query ( 'SET foreign_key_checks = 1' );
// Salva il file di configurazione
$config = file_get_contents ( $docroot . '/config.inc.php' );
// Copia i file dalla cartella temporanea alla root
copyr ( $extraction_dir , $docroot );
// Ripristina il file di configurazione dell'installazione
file_put_contents ( $docroot . '/config.inc.php' , $config );
// Pulizia
if ( post ( 'folder' ) == null ) {
delete ( $extraction_dir );
}
delete ( $docroot . '/database.sql' );
}