From fc07dc3a9de4b65e66e050063f2780d13b077cb4 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sat, 8 Aug 2015 23:13:13 +0200 Subject: backup package - cleanup round two - Clean up obvious leftover crap - XHTML valid code - Add the configured backup path to the displayed table --- config/backup/backup.php | 170 +++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 95 deletions(-) (limited to 'config/backup') 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 @@ 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 & Directories"; include("head.inc"); ?> - -

Backup: Files & Directories

+ - -

- Use this to tool to backup files and directories. The following directories - are recommended for backup. - + Use this to tool to backup files and directories. The following directories are recommended for backup: - - + + +
pfSense Config/cf/conf
RRD Graph Data Files/var/db/rrd
pfSense Config/cf/conf
RRD Graph Data Files/var/db/rrd
-

@@ -161,73 +154,65 @@ if ($_GET["savemsg"]) {
- -
- + +
Upload and Restore
Use this to upload and restore your backup file. File to upload: - + - +


-
+ + + + + + +
+ Backup / Restore
+ The 'Backup' button compresses the directories that are listed below to /root/backup/pfsense.bak.tgz; after that it presents the file for download.
+ If the backup file does not exist in /root/backup/pfsense.bak.tgz then the 'Restore' button will be hidden.


+
+ + \n"; + } + ?> +
+

-\n"; - echo "\n"; - echo "\n"; - echo "Backup / Restore
\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 "

\n"; - echo "\n"; - echo "\n"; - echo " \n"; - if (file_exists('/root/backup/pfsense.bak.tgz')) { - echo " \n"; - } - echo "\n"; - echo "\n"; - echo "\n"; - echo "

\n\n"; - - -echo "
\n"; + +"; -//print_info_box_np("This is an info box."); -//echo"
"; -//endif; - ?> - - + + + @@ -245,17 +230,20 @@ if ($config_change == 1) { + - @@ -267,12 +255,12 @@ if ($config_change == 1) { ?> - + @@ -283,17 +271,9 @@ if ($config_change == 1) {
NameEnabledNamePathEnabled Description - +
  +   +   -   +   + - - + +
- +
-
-
-
-
-
-
-
-
-
+
-- cgit v1.2.3