Backup: Completed functionality to back up and restore paths defined in Default Settings.
This commit is contained in:
+135
-76
@@ -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 "<table width=\"100%\" border=\"0\" cellpadding=\"7\" cellspacing=\"0\">\n";
|
||||
echo "<tr>\n";
|
||||
echo " <th colspan='2' align='left'>Backup</th>\n";
|
||||
echo "</tr>\n";
|
||||
echo "<tr>\n";
|
||||
echo " <td width='20%' class=\"vncell\" style='text-align: left;'>\n";
|
||||
echo " <a href='".PROJECT_PATH."/app/backup/index.php?a=download'>download</a> \n";
|
||||
echo " </td>\n";
|
||||
echo " <td class=\"row_style1\">\n";
|
||||
echo " <br />\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 " <br />\n";
|
||||
echo " <br />\n";
|
||||
echo " </td>\n";
|
||||
echo "</tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<div align='center'>";
|
||||
|
||||
echo "<span class=\"\" >Restore Application</span><br>\n";
|
||||
echo "<div class='borderlight' style='padding:10px;'>\n";
|
||||
//Browse to Backup File
|
||||
echo "Click on 'Browse' then locate and select the application backup file named '.bak'. \n";
|
||||
echo "Then click on 'Restore.' \n";
|
||||
echo "<table width='100%' border='0'>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['header-backup']."</b></td>\n";
|
||||
echo " <td width='50%' align='right'></td>\n";
|
||||
echo " </tr>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td align='left' colspan='2'>".$text['description-backup']."</td>\n";
|
||||
echo " </tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<br><br>";
|
||||
|
||||
echo "<div align='center'>";
|
||||
echo "<form name='frmrestore' method='post' action='restore2.php'>";
|
||||
echo " <table border='0' cellpadding='0' cellspacing='0'>";
|
||||
echo "<table>";
|
||||
echo " <tr>";
|
||||
echo " <td>".$text['label-file_format']." </td>";
|
||||
echo " <td>";
|
||||
echo " <select class='formfld' name='file_format' id='file_format'>";
|
||||
echo " <option value='tgz' ".(($file_format == 'tgz') ? 'selected' : null).">TAR GZIP</option>";
|
||||
echo " <option value='tbz' ".(($file_format == 'tbz') ? 'selected' : null).">TAR BZIP</option>";
|
||||
echo " <option value='rar' ".(($file_format == 'rar') ? 'selected' : null).">RAR</option>";
|
||||
echo " <option value='zip' ".(($file_format == 'zip') ? 'selected' : null).">ZIP</option>";
|
||||
echo " </select>";
|
||||
echo " </td>";
|
||||
echo " <td><input type='button' class='btn' value='".$text['button-backup']."' onclick=\"document.location.href='".PROJECT_PATH."/app/backup/index.php?a=backup&file_format='+document.getElementById('file_format').options[document.getElementById('file_format').selectedIndex].value;\"></td>";
|
||||
echo " </tr>";
|
||||
echo "</table>";
|
||||
echo "</div>";
|
||||
echo "<br><br>";
|
||||
|
||||
echo "<table width='100%' border='0'>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td class='' colspan='2' nowrap='nowrap' align='left'>\n";
|
||||
echo " <table width='200'><tr>";
|
||||
echo " <td><input type='file' class='frm' onChange='frmrestore.fileandpath.value = frmrestore.filename.value;' style='font-family: verdana; font-size: 11px;' name='filename'></td>";
|
||||
echo " <td>";
|
||||
echo " <input type='hidden' name='fileandpath' value=''>\n";
|
||||
echo " <input type='submit' class='btn' value='Restore'>\n";
|
||||
echo " </td>";
|
||||
echo " </tr></table>";
|
||||
echo " </td>\n";
|
||||
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['header-restore']."</b></td>\n";
|
||||
echo " <td width='50%' align='right'></td>\n";
|
||||
echo " </tr>\n";
|
||||
echo " </table>\n";
|
||||
echo " <tr>\n";
|
||||
echo " <td align='left' colspan='2'>".$text['description-restore']."</td>\n";
|
||||
echo " </tr>\n";
|
||||
echo "</table>\n";
|
||||
echo "<br><br>";
|
||||
|
||||
echo "<div align='center'>";
|
||||
echo "<form name='frmrestore' method='post' enctype='multipart/form-data' action=''>";
|
||||
echo "<input type='hidden' name='a' value='restore'>";
|
||||
echo "<table>";
|
||||
echo " <tr>";
|
||||
echo " <td>".$text['label-select_backup']." </td>";
|
||||
echo " <td><input type='file' class='formfld fileinput' name='backup_file'></td>";
|
||||
echo " <td><input type='submit' class='btn' value='".$text['button-restore']."'></td>";
|
||||
echo " </tr>";
|
||||
echo "</table>";
|
||||
echo "<br>";
|
||||
echo "<span style='font-weight: bold; text-decoration: underline; color: #000;'>".$text['description-restore_warning']."</span>";
|
||||
echo "</form>\n";
|
||||
echo "</div>";
|
||||
echo "<br><br><br>";
|
||||
|
||||
echo "</div>";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user