* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
use EGroupware\Api;
if (!is_object(@$GLOBALS['egw'])) // called from outside eGW ==> setup
{
include ('./inc/functions.inc.php');
@set_time_limit(0);
// Check header and authentication
if (!$GLOBALS['egw_setup']->auth('Config'))
{
Header('Location: index.php');
exit;
}
// Does not return unless user is authorized
$GLOBALS['egw_setup']->loaddb();
$tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
$self = 'db_backup.php';
$is_setup = true;
}
$db_backup = new Api\Db\Backup();
$asyncservice = new asyncservice();
// download a backup, has to be before any output !!!
if ($_POST['download'])
{
list($file) = each($_POST['download']);
$file = $db_backup->backup_dir.'/'.basename($file); // basename to now allow to change the dir
while (@ob_end_clean()) {} // end all active output buffering
ini_set('zlib.output_compression',0); // switch off zlib.output_compression, as this would limit downloads in size to memory_limit
html::content_header(basename($file));
readfile($file);
exit;
}
$setup_tpl = CreateObject('phpgwapi.Template',$tpl_root);
$setup_tpl->set_file(array(
'T_head' => 'head.tpl',
'T_footer' => 'footer.tpl',
'T_db_backup' => 'db_backup.tpl',
));
$setup_tpl->set_var('hidden_vars', html::input_hidden('csrf_token', egw_csrf::token(__FILE__)));
// check CSRF token for POST requests with any content (setup uses empty POST to call it's modules!)
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST)
{
egw_csrf::validate($_POST['csrf_token'], __FILE__);
}
$setup_tpl->set_block('T_db_backup','schedule_row','schedule_rows');
$setup_tpl->set_block('T_db_backup','set_row','set_rows');
$setup_tpl->set_var('stage_title',$stage_title = lang('DB backup and restore'));
$setup_tpl->set_var('stage_desc',lang('This program lets you backup your database, schedule a backup or restore it.'));
$setup_tpl->set_var('error_msg','');
$bgcolor = array('#DDDDDD','#EEEEEE');
if (is_object($GLOBALS['egw_setup']->html))
{
$GLOBALS['egw_setup']->html->show_header($stage_title,False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
}
else
{
$setup_tpl->set_block('T_db_backup','setup_header');
$setup_tpl->set_var('setup_header','');
$GLOBALS['egw_info']['flags']['app_header'] = $stage_title;
common::egw_header();
parse_navbar();
$run_in_egw = true;
}
// save backup housekeeping settings
if ($_POST['save_backup_settings'])
{
$matches = array();
preg_match('/^[1-9][0-9]*$/', $_POST['backup_mincount'], $matches);
$minCount = $matches[0];
$filesBackup = $_POST['backup_files'] === 'backup_files';
if (empty($minCount))
{
$minCount = 0;
$setup_tpl->set_var('error_msg',htmlspecialchars(lang("'%1' must be integer", lang("backup min count"))));
}
$db_backup->saveConfig($minCount,$is_setup ? (boolean)$filesBackup : null);
if (is_int($minCount) && $minCount > 0)
{
$cleaned_files = array();
/* Remove old backups. */
$db_backup->housekeeping($cleaned_files);
foreach ($cleaned_files as $file)
{
echo '
'.lang('entry has been deleted sucessfully').': '.$file."