Portions created by the Initial Developer are Copyright (C) 2008-2012 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; if (permission_exists("backup_download")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //download the backup if ($_GET['a'] == "backup" && permission_exists('backup_download')) { $file_format = $_GET['file_format']; $file_format = ($file_format != '') ? $file_format : 'tgz'; //build the backup file $backup_path = ($_SESSION['server']['backup']['path'] != '') ? $_SESSION['server']['backup']['path'] : '/tmp'; $backup_file = 'backup_'.date('Ymd_His').'.'.$file_format; if (count($_SESSION['backup']['path']) > 0) { //determine compression method switch ($file_format) { case "rar" : $cmd = 'rar a -ow -r '; break; case "zip" : $cmd = 'zip -r '; break; case "tbz" : $cmd = 'tar -jvcf '; break; default : $cmd = 'tar -zvcf '; } $cmd .= $backup_path.'/'.$backup_file.' '; foreach ($_SESSION['backup']['path'] as $value) { $cmd .= $value.' '; } exec($cmd); //download the file session_cache_limiter('public'); if (file_exists($backup_path."/".$backup_file)) { $fd = fopen($backup_path."/".$backup_file, 'rb'); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: binary"); header("Content-Description: File Transfer"); header('Content-Disposition: attachment; filename='.$backup_file); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past header("Content-Length: ".filesize($backup_path."/".$backup_file)); header("Pragma: no-cache"); header("Expires: 0"); ob_clean(); fpassthru($fd); exit; } else { //set response message $_SESSION["message"] = $text['message-backup_failed_format']; header("Location: ".$_SERVER['PHP_SELF']); exit; } } else { //set response message $_SESSION["message"] = $text['message-backup_failed_paths']; header("Location: ".$_SERVER['PHP_SELF']); exit; } } //restore a backup if ($_POST['a'] == "restore" && permission_exists('backup_upload')) { $backup_path = ($_SESSION['server']['backup']['path'] != '') ? $_SESSION['server']['backup']['path'] : '/tmp'; $backup_file = $_FILES['backup_file']['name']; if (is_uploaded_file($_FILES['backup_file']['tmp_name'])) { //move temp file to backup path move_uploaded_file($_FILES['backup_file']['tmp_name'], $backup_path.'/'.$backup_file); //determine file format and restore backup $file_format = pathinfo($_FILES['backup_file']['name'], PATHINFO_EXTENSION); $valid_format = true; switch ($file_format) { case "rar" : $cmd = 'rar x -ow -o+ '.$backup_path.'/'.$backup_file.' /'; break; case "zip" : $cmd = 'umask 755; unzip -o -qq -X -K '.$backup_path.'/'.$backup_file.' -d /'; break; case "tbz" : $cmd = 'tar -xvpjf '.$backup_path.'/'.$backup_file.' -C /'; break; case "tgz" : $cmd = 'tar -xvpzf '.$backup_path.'/'.$backup_file.' -C /'; break; default: $valid_format = false; } if (!$valid_format) { @unlink($backup_path.'/'.$backup_file); $_SESSION["message"] = $text['message-restore_failed_format']; header("Location: ".$_SERVER['PHP_SELF']); exit; } else { exec($cmd); //set response message $_SESSION["message"] = $text['message-restore_completed']; header("Location: ".$_SERVER['PHP_SELF']); exit; } } else { //set response message $_SESSION["message"] = $text['message-restore_failed_upload']; header("Location: ".$_SERVER['PHP_SELF']); exit; } } //add the header require_once "resources/header.php"; $document['title'] = $text['title-destinations']; //show the content echo "
"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['header-backup']."
".$text['description-backup']."
\n"; echo "

"; echo "
"; echo ""; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
".$text['label-file_format']." "; echo " "; echo "
"; echo "
"; echo "

"; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
".$text['header-restore']."
".$text['description-restore']."
\n"; echo "

"; echo "
"; echo "
"; echo ""; echo ""; echo " "; echo " "; echo " "; echo " "; echo " "; echo "
".$text['label-select_backup']." 
"; echo "
"; echo "".$text['description-restore_warning'].""; echo "
\n"; echo "
"; echo "


"; echo "
"; //show the footer require_once "resources/footer.php"; ?>