Backup: Completed functionality to back up and restore paths defined in Default Settings.

This commit is contained in:
Nate Jones
2014-08-16 22:15:01 +00:00
parent 941022ddbf
commit 620d1002e5
2 changed files with 195 additions and 132 deletions

View File

@@ -1,73 +1,77 @@
<?php
$text['title-zzz']['en-us'] = "zzz";
$text['title-zzz']['es-cl'] = "zzz";
$text['title-zzz']['pt-pt'] = "zzz";
$text['title-zzz']['fr-fr'] = "zzz";
$text['title-backup']['en-us'] = "Backup";
$text['title-backup']['es-cl'] = "Copia de seguridad";
$text['title-backup']['pt-pt'] = "Backup";
$text['title-backup']['fr-fr'] = "Sauvegarde";
$text['description-zzz']['en-us'] = "zzz";
$text['description-zzz']['es-cl'] = "zzz";
$text['description-zzz']['pt-pt'] = "zzz";
$text['description-zzz']['fr-fr'] = "zzz";
$text['header-backup']['en-us'] = "Backup";
$text['header-backup']['es-cl'] = "Copia de seguridad";
$text['header-backup']['pt-pt'] = "Backup";
$text['header-backup']['fr-fr'] = "Sauvegarde";
$text['button-add']['en-us'] = "Add";
$text['button-add']['es-cl'] = "Agregar";
$text['button-add']['pt-pt'] = "Adicionar";
$text['button-add']['fr-fr'] = "Ajouter";
$text['description-backup']['en-us'] = "To create a backup of paths defined in Default Settings, click the 'Backup' button below and then choose a location on your local system to save the file.";
$text['description-backup']['es-cl'] = "Para crear una copia de seguridad de rutas definidas en la configuración predeterminada, haga clic en el botón 'Copia de seguridad' a continuación y luego elija una ubicación en el sistema local para guardar el archivo.";
$text['description-backup']['pt-pt'] = "Para criar uma cópia de segurança dos caminhos definidos em configurações padrão, clique no botão 'Backup' abaixo e, em seguida, escolher um local em seu sistema local para salvar o arquivo.";
$text['description-backup']['fr-fr'] = "Pour créer une sauvegarde de chemins définis dans les paramètres par défaut, cliquez sur le bouton 'Sauvegarder' ci-dessous, puis choisissez un emplacement sur votre système local pour enregistrer le fichier.";
$text['button-edit']['en-us'] = "Edit";
$text['button-edit']['es-cl'] = "Editar";
$text['button-edit']['pt-pt'] = "Editar";
$text['button-edit']['fr-fr'] = "Editer";
$text['label-file_format']['en-us'] = "File Format";
$text['label-file_format']['es-cl'] = "Formato de Archivo";
$text['label-file_format']['pt-pt'] = "Formato de arquivo";
$text['label-file_format']['fr-fr'] = "Format de Fichier";
$text['button-delete']['en-us'] = "Delete";
$text['button-delete']['es-cl'] = "Eliminar";
$text['button-delete']['pt-pt'] = "Remoção";
$text['button-delete']['fr-fr'] = "Supprimer";
$text['header-restore']['en-us'] = "Restore";
$text['header-restore']['es-cl'] = "Restaurar";
$text['header-restore']['pt-pt'] = "Restaurar";
$text['header-restore']['fr-fr'] = "Restaurer";
$text['button-save']['en-us'] = "Save";
$text['button-save']['es-cl'] = "Guardar";
$text['button-save']['pt-pt'] = "Guardar";
$text['button-save']['fr-fr'] = "Sauvegarder";
$text['description-restore']['en-us'] = "To restore a backup from a file on your local system, click 'Browse' then select the desired backup file (eg. 'backup_[YYMMDD]_[HHMMSS].tgz'), then click the 'Restore' button.";
$text['description-restore']['es-cl'] = "Para restaurar una copia de seguridad de un archivo en el sistema local, haga clic en 'Examinar' y seleccione el archivo de copia de seguridad que desee (por ejemplo, 'backup_[YYMMDD]_[HHMMSS].tgz'), a continuación, haga clic en el botón 'Restaurar'.";
$text['description-restore']['pt-pt'] = "Para restaurar um backup de um arquivo em seu sistema local, clique em 'Procurar' e selecione o arquivo de backup desejado (por exemplo, 'backup_[YYMMDD]_[HHMMSS].tgz'), então clique no botão 'Restaurar'.";
$text['description-restore']['fr-fr'] = "Pour restaurer une sauvegarde à partir d'un fichier sur votre système local, cliquez sur 'Parcourir' puis sélectionnez le fichier de sauvegarde souhaité (par exemple, 'backup_[YYMMDD]_[HHMMSS].tgz'), puis cliquez sur le bouton 'Restaurer'.";
$text['button-back']['en-us'] = "Back";
$text['button-back']['es-cl'] = "Volver";
$text['button-back']['pt-pt'] = "Voltar";
$text['button-back']['fr-fr'] = "Retour";
$text['description-restore_warning']['en-us'] = "Warning: Existing files, if any, will be overwritten.";
$text['description-restore_warning']['es-cl'] = "Advertencia: Los archivos existentes, si los hay, se sobrescribirá.";
$text['description-restore_warning']['pt-pt'] = "Aviso: Os arquivos existentes, se houver, serão substituídos.";
$text['description-restore_warning']['fr-fr'] = "Attention: les fichiers existants, le cas échéant, sera écrasé.";
$text['button-search']['en-us'] = "Search";
$text['button-search']['es-cl'] = "Buscar";
$text['button-search']['pt-pt'] = "Pesquisar";
$text['button-search']['fr-fr'] = "Chercher";
$text['label-select_backup']['en-us'] = "Select Backup File";
$text['label-select_backup']['es-cl'] = "Seleccione Copia de Seguridad";
$text['label-select_backup']['pt-pt'] = "Selecione Backup";
$text['label-select_backup']['fr-fr'] = "Sélectionnez Sauvegarde";
$text['confirm-delete']['en-us'] = "Do you really want to delete this?";
$text['confirm-delete']['es-cl'] = "¿Realmente desea eliminar esto?";
$text['confirm-delete']['pt-pt'] = "Deseja realmente remover isto?";
$text['confirm-delete']['fr-fr'] = "Voulez-vous vraiment supprimer cela?";
$text['button-backup']['en-us'] = "Backup";
$text['button-backup']['es-cl'] = "Copia de Seguridad";
$text['button-backup']['pt-pt'] = "Backup";
$text['button-backup']['fr-fr'] = "Sauvegarde";
$text['message-add']['en-us'] = "Add Completed";
$text['message-add']['es-cl'] = "Agregar Completo";
$text['message-add']['pt-pt'] = "Adição Realizada";
$text['message-add']['fr-fr'] = "Ajouté";
$text['button-restore']['en-us'] = "Restore";
$text['button-restore']['es-cl'] = "Restaurar";
$text['button-restore']['pt-pt'] = "Restaurar";
$text['button-restore']['fr-fr'] = "Restaurer";
$text['message-update']['en-us'] = "Update Completed";
$text['message-update']['es-cl'] = "Actualización Completa";
$text['message-update']['pt-pt'] = "Actualização Realizada";
$text['message-update']['fr-fr'] = "Mis à jour";
$text['message-backup_failed_format']['en-us'] = "Backup Failed - Unable to Create Backup File";
$text['message-backup_failed_format']['es-cl'] = "Copia de seguridad Error - No se puede crear archivo de copia de seguridad";
$text['message-backup_failed_format']['pt-pt'] = "Falha no backup - Não é possível criar arquivo de backup";
$text['message-backup_failed_format']['fr-fr'] = "Échec de la sauvegarde - Impossible de créer le fichier de sauvegarde";
$text['message-delete']['en-us'] = "Delete Completed";
$text['message-delete']['es-cl'] = "Eliminación Completa";
$text['message-delete']['pt-pt'] = "Remoção Realizada";
$text['message-delete']['fr-fr'] = "Supprimé";
$text['message-backup_failed_paths']['en-us'] = "Backup Failed - No Backup Paths Defined";
$text['message-backup_failed_paths']['es-cl'] = "Fallidos de copia de seguridad - No hay rutas de copia de seguridad definida";
$text['message-backup_failed_paths']['pt-pt'] = "Backup falhou - Sem Caminhos backup definido";
$text['message-backup_failed_paths']['fr-fr'] = "Échec de sauvegarde - Pas de chemins sauvegarde définie";
$text['message-required']['en-us'] = "Please provide: ";
$text['message-required']['es-cl'] = "Por favor ingrese: ";
$text['message-required']['pt-pt'] = "Por favor forneça: ";
$text['message-required']['fr-fr'] = "Merci d'indiquer: ";
$text['message-restore_completed']['en-us'] = "Restore Completed";
$text['message-restore_completed']['es-cl'] = "Restaurar Completado";
$text['message-restore_completed']['pt-pt'] = "Concluída a Restauração";
$text['message-restore_completed']['fr-fr'] = "Restaurer Terminé";
$text['message-duplicate']['en-us'] = "Duplicate detected";
$text['message-duplicate']['es-cl'] = "Duplicar detectado";
$text['message-duplicate']['pt-pt'] = "Duplicar detectado";
$text['message-duplicate']['fr-fr'] = "Dupliquer détecté";
$text['message-restore_failed_format']['en-us'] = "Restore Failed - Invalid File Format";
$text['message-restore_failed_format']['es-cl'] = "Restaurar Error - Formato de archivo no válido";
$text['message-restore_failed_format']['pt-pt'] = "Falha na restauração - Formato de arquivo inválido";
$text['message-restore_failed_format']['fr-fr'] = "Échec de la restauration - Format de fichier incorrect";
$text['message-restore_failed_upload']['en-us'] = "Restore Failed - File Upload Failed";
$text['message-restore_failed_upload']['es-cl'] = "Falló la recup - Cargar archivo Error";
$text['message-restore_failed_upload']['pt-pt'] = "Falha de restauração - Upload de arquivo falhou";
$text['message-restore_failed_upload']['fr-fr'] = "Échec de la restauration - File Upload Échec";
?>

View File

@@ -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']."&nbsp;</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']."&nbsp;</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>";