aboutsummaryrefslogtreecommitdiffstats
path: root/config/backup/backup.php
diff options
context:
space:
mode:
Diffstat (limited to 'config/backup/backup.php')
-rw-r--r--config/backup/backup.php170
1 files changed, 75 insertions, 95 deletions
diff --git a/config/backup/backup.php b/config/backup/backup.php
index d4debcd3..8f4dbf9c 100644
--- a/config/backup/backup.php
+++ b/config/backup/backup.php
@@ -1,8 +1,9 @@
<?php
-/* $Id$ */
/*
backup.php
+ part of pfSense (https://www.pfSense.org/)
Copyright (C) 2008 Mark J Crane
+ Copyright (C) 2015 ESF, LLC
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -26,11 +27,14 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
+require_once("guiconfig.inc");
+require_once("/usr/local/pkg/backup.inc");
-require("guiconfig.inc");
-require("/usr/local/pkg/backup.inc");
-
+global $config, $backup_dir, $backup_filename, $backup_path;
$a_backup = &$config['installedpackages']['backup']['config'];
+$backup_dir = "/root/backup";
+$backup_filename = "pfsense.bak.tgz";
+$backup_path = "{$backup_dir}/{$backup_filename}";
if ($_GET['act'] == "del") {
if ($_GET['type'] == 'backup') {
@@ -49,31 +53,29 @@ if ($_GET['a'] == "download") {
if ($_GET['t'] == "backup") {
conf_mount_rw();
- $tmp = '/root/backup/';
- $filename = 'pfsense.bak.tgz';
- //system('cd /usr/local/;tar cvzf /root/backup/pfsense.bak.tgz freeswitch');
-
$i = 0;
if (count($a_backup) > 0) {
- $backup_cmd = 'tar --create --verbose --gzip --file '.$tmp.$filename.' --directory / ';
+ /* Do NOT remove the trailing space after / from $backup_cmd below!!! */
+ $backup_cmd = "/usr/bin/tar --create --verbose --gzip --file {$backup_path} --directory / ";
foreach ($a_backup as $ent) {
if ($ent['enabled'] == "true") {
- //htmlspecialchars($ent['name']);
- //htmlspecialchars($ent['path']);
- //htmlspecialchars($ent['description']);
- $backup_cmd .= htmlspecialchars($ent['path']).' ';
+ $backup_cmd .= htmlspecialchars($ent['path']) . ' ';
}
$i++;
}
- //echo $backup_cmd; //exit;
system($backup_cmd);
}
session_cache_limiter('public');
- $fd = fopen($tmp.$filename, "rb");
+ $fd = fopen("{$backup_path}", "rb");
+ header("Content-Type: application/force-download");
header("Content-Type: binary/octet-stream");
- header("Content-Length: " . filesize($tmp.$filename));
- header('Content-Disposition: attachment; filename="' . $filename . '"');
+ header("Content-Type: application/download");
+ header("Content-Description: File Transfer");
+ header('Content-Disposition: attachment; filename="' . $backup_filename . '"');
+ header("Cache-Control: no-cache, must-revalidate");
+ header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
+ header("Content-Length: " . filesize($backup_path));
fpassthru($fd);
conf_mount_ro();
@@ -83,17 +85,13 @@ if ($_GET['a'] == "download") {
if ($_GET['a'] == "other") {
if ($_GET['t'] == "restore") {
- conf_mount_rw();
- $tmp = '/root/backup/';
- $filename = 'pfsense.bak.tgz';
-
- //extract the tgz file
- if (file_exists('/root/backup/'.$filename)) {
- //echo "The file $filename exists";
- system('cd /; tar xvpfz /root/backup/'.$filename.' ');
- header( 'Location: backup.php?savemsg=Backup+has+been+restored.' ) ;
+ // Extract the tgz file
+ if (file_exists($backup_path)) {
+ conf_mount_rw();
+ system("/usr/bin/tar -xpzC / -f {$backup_path}");
+ header("Location: backup.php?savemsg=Backup+has+been+restored.");
} else {
- header( 'Location: backup.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ;
+ header("Location: backup.php?savemsg=Restore+failed.+Backup+file+not+found.");
}
conf_mount_ro();
exit;
@@ -102,21 +100,20 @@ if ($_GET['a'] == "other") {
if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
conf_mount_rw();
- $filename = 'pfsense.bak.tgz';
- move_uploaded_file($_FILES['ulfile']['tmp_name'], "/root/backup/" . $filename);
- $savemsg = "Uploaded file to /root/backup/" . htmlentities($_FILES['ulfile']['name']);
- system('cd /; tar xvpfz /root/backup/'.$filename.' ');
+ move_uploaded_file($_FILES['ulfile']['tmp_name'], "{$backup_path}");
+ $savemsg = "Uploaded file to {$backup_dir}" . htmlentities($_FILES['ulfile']['name']);
+ system("/usr/bin/tar -xpzC / -f {$backup_path}");
conf_mount_ro();
}
+$pgtitle = "Backup: Files &amp; Directories";
include("head.inc");
?>
-
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
-<p class="pgtitle">Backup: Files & Directories</p>
+
<?php
if ($_GET["savemsg"]) {
@@ -143,16 +140,12 @@ if ($_GET["savemsg"]) {
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td>
- <p>
- Use this to tool to backup files and directories. The following directories
- are recommended for backup.
-
+ <td>Use this to tool to backup files and directories. The following directories are recommended for backup:
<table>
- <tr><td><strong>pfSense Config</strong></td><td>/cf/conf</td></tr>
- <tr><td><strong>RRD Graph Data Files</strong></td><td>/var/db/rrd</td></tr>
+ <tr><td></td><td></td></tr>
+ <tr><td><strong>pfSense Config</strong></td><td>/cf/conf</td></tr>
+ <tr><td><strong>RRD Graph Data Files</strong></td><td>/var/db/rrd</td></tr>
</table>
- </p>
</td>
</tr>
</table>
@@ -161,73 +154,65 @@ if ($_GET["savemsg"]) {
<br/>
<div id="niftyOutter">
-
- <form action="backup.php" method="POST" enctype="multipart/form-data" name="frmUpload" onSubmit="">
- <table width='100%' width='690' cellpadding='0' cellspacing='0' border='0'>
+ <form action="backup.php" method="post" enctype="multipart/form-data" name="frmUpload" onsubmit="">
+ <table width='690' cellpadding='0' cellspacing='0' border='0'>
<tr><td align='left' colspan='4'><strong>Upload and Restore</strong></td></tr>
<tr>
<td colspan='2'>Use this to upload and restore your backup file.</td>
<td align="right">File to upload:</td>
<td width='50%' valign="top" align='right' class="label">
- <input name="ulfile" type="file" class="button" id="ulfile">
+ <input name="ulfile" type="file" class="button" id="ulfile" />
</td>
<td valign="top" class="label">
- <input name="submit" type="submit" class="button" id="upload" value="Upload">
+ <input name="submit" type="submit" class="button" id="upload" value="Upload" />
</td>
</tr>
</table>
<br />
<br />
- </div>
</form>
+ </div>
+ <table width='690' cellpadding='0' cellspacing='0' border='0'>
+ <tr>
+ <td width='80%'>
+ <strong>Backup / Restore</strong><br />
+ The 'Backup' button compresses the directories that are listed below to /root/backup/pfsense.bak.tgz; after that it presents the file for download.<br />
+ If the backup file does not exist in /root/backup/pfsense.bak.tgz then the 'Restore' button will be hidden.<br /><br /><br />
+ </td>
+ <td width='20%' valign='middle' align='right'>
+ <input type='button' value='Backup' onclick="document.location.href='backup.php?a=download&amp;t=backup';" />
+ <?php
+ if (file_exists($backup_path)) {
+ echo "\t<input type='button' value='Restore' onclick=\"document.location.href='backup.php?a=other&amp;t=restore';\" />\n";
+ }
+ ?>
+ </td>
+ </tr>
+ </table>
+ <br /><br />
-<?php
- echo "<table width='690' cellpadding='0' cellspacing='0' border='0'>\n";
- echo "<tr>\n";
- echo "<td width='80%'>\n";
- echo "<b>Backup / Restore</b><br />\n";
- echo "The 'backup' button will tar gzip the directories that are listed below to /root/backup/pfsense.bak.tgz it then presents a file to download. \n";
- echo "If the backup file does not exist in /root/backup/pfsense.bak.tgz then the 'restore' button will be hidden. \n";
- echo "<br /><br />\n";
- echo "</td>\n";
- echo "<td width='20%' valign='middle' align='right'>\n";
- echo " <input type='button' value='backup' onclick=\"document.location.href='backup.php?a=download&t=backup';\" />\n";
- if (file_exists('/root/backup/pfsense.bak.tgz')) {
- echo " <input type='button' value='restore' onclick=\"document.location.href='backup.php?a=other&t=restore';\" />\n";
- }
- echo "</td>\n";
- echo "</tr>\n";
- echo "</table>\n";
- echo "<br /><br />\n\n";
-
-
-echo " <form action='backup.php' method='post' name='iform' id='iform'>\n";
+ <form action='backup.php' method='post' name='iform' id='iform'>
+<?php
if ($config_change == 1) {
- write_config();
- $config_change = 0;
+ write_config();
+ $config_change = 0;
}
-
-//if ($savemsg) print_info_box($savemsg);
-//if (file_exists($d_hostsdirty_path)): echo"<p>";
-//print_info_box_np("This is an info box.");
-//echo"<br />";
-//endif;
-
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="30%" class="listhdrr">Name</td>
- <td width="20%" class="listhdrr">Enabled</td>
+ <td width="20%" class="listhdrr">Name</td>
+ <td width="25%" class="listhdrr">Path</td>
+ <td width="5%" class="listhdrr">Enabled</td>
<td width="40%" class="listhdr">Description</td>
<td width="10%" class="list">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="17"></td>
- <td valign="middle"><a href="backup_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
+ <td valign="middle"><a href="backup_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" width="17" height="17" border="0" /></a></td>
</tr>
</table>
</td>
@@ -246,16 +231,19 @@ if ($config_change == 1) {
<?=$ent['name'];?>&nbsp;
</td>
<td class="listr" ondblclick="document.location='backup_edit.php?id=<?=$i;?>';">
+ <?=$ent['path'];?>&nbsp;
+ </td>
+ <td class="listr" ondblclick="document.location='backup_edit.php?id=<?=$i;?>';">
<?=$ent['enabled'];?>&nbsp;
</td>
<td class="listbg" ondblclick="document.location='backup_edit.php?id=<?=$i;?>';">
- <font color="#FFFFFF"><?=htmlspecialchars($ent['description']);?>&nbsp;
+ <font color="#FFFFFF"><?=htmlspecialchars($ent['description']);?>&nbsp;</font>
</td>
- <td valign="middle" nowrap class="list">
+ <td valign="middle" nowrap="nowrap" class="list">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
- <td valign="middle"><a href="backup_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" width="17" height="17" border="0"></a></td>
- <td><a href="backup_edit.php?type=backup&act=del&id=<?=$i;?>" onclick="return confirm('Do you really want to delete this?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" width="17" height="17" border="0"></a></td>
+ <td valign="middle"><a href="backup_edit.php?id=<?=$i;?>"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_e.gif" alt="" width="17" height="17" border="0" /></a></td>
+ <td><a href="backup_edit.php?type=backup&amp;act=del&amp;id=<?=$i;?>" onclick="return confirm('Do you really want to delete this?')"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_x.gif" alt="" width="17" height="17" border="0" /></a></td>
</tr>
</table>
</td>
@@ -267,12 +255,12 @@ if ($config_change == 1) {
?>
<tr>
- <td class="list" colspan="3"></td>
+ <td class="list" colspan="4"></td>
<td class="list">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td width="17"></td>
- <td valign="middle"><a href="backup_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" width="17" height="17" border="0"></a></td>
+ <td valign="middle"><a href="backup_edit.php"><img src="/themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="" width="17" height="17" border="0" /></a></td>
</tr>
</table>
</td>
@@ -283,17 +271,9 @@ if ($config_change == 1) {
<td class="list"></td>
</tr>
</table>
-
</form>
-<br>
-<br>
-<br>
-<br>
-<br>
-<br>
-<br>
-<br>
+<br />
</td>
</tr>