Portions created by the Initial Developer are Copyright (C) 2008-2019 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists("backup_download")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //download the backup if ($_GET['a'] == "download" && permission_exists('backup_download')) { //get the file format $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.' '; if (isset($_SESSION['backup']['path'])) { foreach ($_SESSION['backup']['path'] as $value) { if (file_exists($value)) { $cmd .= $value.' '; } } } $cmd .= " 2>&1"; exec($cmd, $response, $restore_errlevel); $response_txt = "
" . implode("
", $response); //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 message::add($text['message-backup_failed_format'] . $response_txt, 'negative'); header("Location: ".$_SERVER['PHP_SELF']); exit; } } else { //set response message message::add($text['message-backup_failed_paths'], 'negative'); header("Location: ".$_SERVER['PHP_SELF']); exit; } } //script a backup (cron) if ($_GET['a'] == "script" && permission_exists('backup_download')) { $file_format = $_GET['file_format']; $target_type = "script"; $backup = new backup; $command = $backup->command("backup", $file_format); } //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']) && file_exists($backup_path.'/'.$backup_file)) { //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); message::add($text['message-restore_failed_format'], 'negative'); header("Location: ".$_SERVER['PHP_SELF']); exit; } else { $cmd .= ' 2>&1'; exec($cmd, $response, $restore_errlevel); $response_txt = "
" . implode("
", $response); if ($restore_errlevel == 0) { //set response message message::add($text['message-restore_completed']); header("Location: ".$_SERVER['PHP_SELF']); exit; } else { message::add($text['message-restore_failed_extract'] . $response_txt, 'negative'); header("Location: ".$_SERVER['PHP_SELF']); exit; } } } else { //set response message message::add($text['message-restore_failed_upload'], 'negative'); header("Location: ".$_SERVER['PHP_SELF']); exit; } } //add the header require_once "resources/header.php"; $document['title'] = $text['title-destinations']; // backup type switch javascript echo ""; //show the content echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; } echo " \n"; echo "
\n"; echo "".$text['header-backup']."\n"; echo "

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


"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo "\n"; echo "\n"; echo ""; echo ""; echo "\n"; echo "\n"; echo ""; echo ""; echo "
\n"; echo " ".$text['label-source_paths']."\n"; echo "\n"; if (isset($_SESSION['backup']['path'])) foreach ($_SESSION['backup']['path'] as $backup_path) { echo $backup_path."
\n"; } echo "
\n"; echo " ".$text['label-file_format']."\n"; echo "\n"; echo " "; echo "
\n"; echo " ".$text['label-target_type']."\n"; echo "\n"; echo " "; echo "
"; echo "
"; echo "\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo "
\n"; echo " ".$text['label-command']."\n"; echo "\n"; echo " "; echo "
"; echo "
"; echo "
"; echo "
"; echo ""; echo ""; echo "
"; echo "

"; if (permission_exists("backup_upload")) { echo "
      \n"; echo " ".$text['header-restore']."\n"; echo "

"; echo $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 "
\n"; echo "

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