diff --git a/app/backup/app_languages.php b/app/backup/app_languages.php index d749521a0f..f6110bb233 100755 --- a/app/backup/app_languages.php +++ b/app/backup/app_languages.php @@ -1,73 +1,77 @@ diff --git a/app/backup/index.php b/app/backup/index.php index 0d780dff5d..49bea58a60 100644 --- a/app/backup/index.php +++ b/app/backup/index.php @@ -26,7 +26,7 @@ include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; -if (if_group("backup_download")) { +if (permission_exists("backup_download")) { //access granted } else { @@ -35,110 +35,169 @@ else { } //add multi-lingual support -// require_once "app_languages.php"; + require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //download the backup - if ($_GET['a'] == "download" && permission_exists('backup_download')) { + 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 = '/tmp'; - $backup_name = 'backup.tgz'; - //system('cd /tmp;tar cvzf /tmp/backup.tgz backup); - $i = 0; + $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) { - $cmd = 'tar --create --verbose --gzip --file '.$backup_path.'/'.$backup_name.' --directory '; + //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.' '; - $i++; } - //echo $cmd; - system($cmd); - } + exec($cmd); - //download the file - session_cache_limiter('public'); - if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.base64_decode($_GET['filename']))) { - $fd = fopen($_SESSION['switch']['recordings']['dir'].'/'.base64_decode($_GET['filename']), "rb"); - header("Content-Type: application/force-download"); - header("Content-Type: application/octet-stream"); - //header("Content-Transfer-Encoding: binary"); - header("Content-Type: application/download"); - header("Content-Description: File Transfer"); - header('Content-Disposition: attachment; filename=backup.tgz'); - 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($_SESSION['switch']['recordings']['dir'].'/'.base64_decode($_GET['filename']))); - header("Pragma: no-cache"); - header("Expires: 0"); - ob_clean(); - fpassthru($fd); + //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; } } - exit; - } -//upload the backup - if (permission_exists('backup_upload')) { - if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name']) && permission_exists('recording_upload')) { - //upload the file - move_uploaded_file($_FILES['ulfile']['tmp_name'], $_SESSION['switch']['recordings']['dir'].'/'.$_FILES['ulfile']['name']); - $savemsg = $text['message-uploaded']." ".$_SESSION['switch']['recordings']['dir']."/". htmlentities($_FILES['ulfile']['name']); - //system('chmod -R 744 '.$_SESSION['switch']['recordings']['dir'].'*'); - unset($_POST['txtCommand']); - //restore the backup - system('tar -xvpzf /tmp/backup.tgz -C /tmp'); + +//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 "
| Backup | \n"; - echo "|
|---|---|
| \n"; - echo " download \n"; - echo " | \n"; - echo "\n";
- echo " \n"; - echo "To backup your application click on the download link and then choose \n"; - echo "a safe location on your computer to save the file. You may want to \n"; - echo "save the backup to more than one computer to prevent the backup from being lost. \n"; - echo " \n"; - echo " \n"; - echo " | \n";
- echo "
| ".$text['header-backup']." | \n"; + echo "\n"; + echo " |
| ".$text['description-backup']." | \n"; + echo "|