From b753fe0f921c682542fb3aafd388e67a5cc32727 Mon Sep 17 00:00:00 2001 From: mcrane Date: Sat, 14 Mar 2009 22:52:14 -0600 Subject: Add new package to backup and restore files and directories --- config/backup/backup.inc | 132 ++++++++++++++++++ config/backup/backup.tmp | 309 ++++++++++++++++++++++++++++++++++++++++++ config/backup/backup.xml | 115 ++++++++++++++++ config/backup/backup_edit.tmp | 213 +++++++++++++++++++++++++++++ 4 files changed, 769 insertions(+) create mode 100644 config/backup/backup.inc create mode 100644 config/backup/backup.tmp create mode 100644 config/backup/backup.xml create mode 100755 config/backup/backup_edit.tmp (limited to 'config/backup') diff --git a/config/backup/backup.inc b/config/backup/backup.inc new file mode 100644 index 00000000..34fb31e3 --- /dev/null +++ b/config/backup/backup.inc @@ -0,0 +1,132 @@ +10^x|1024->2^x] + $s=array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB'); + $e=floor(log($bytes,$convention)); + return round($bytes/pow($convention,$e),2).' '.$s[$e]; +} + + +function backup_sync_package_php() +{ + + global $config; + if($config['installedpackages']['backup']['config'] != "") { + + conf_mount_rw(); + config_unlock(); + + foreach($config['installedpackages']['backup']['config'] as $rowhelper) { + if ($rowhelper['enabled'] != "false") { + //$tmp_php = base64_decode($rowhelper['php']); + if (strlen($tmp_php) > 0) { + $tmp .= "// name: ".$rowhelper['name']." \n"; + $tmp .= "// description: ".$rowhelper['description']." \n\n"; + $tmp .= base64_decode($rowhelper['php']); + $tmp .= "\n"; + } + } + + } + + conf_mount_ro(); + + } +} + + +function php_sync_package() +{ + + global $config; + backup_sync_package_php(); + +} + + +function php_install_command() +{ + + global $config; + conf_mount_rw(); + config_lock(); + + if (!is_dir('/usr/local/www/packages/')) { + exec("mkdir /usr/local/www/packages/"); + } + + if (!is_dir('/usr/local/www/packages/backup/')) { + exec("mkdir /usr/local/www/packages/backup/"); + } + + + //rename PHP files from .tmp to .php + exec("cp /tmp/backup.tmp /usr/local/www/packages/backup/backup.php"); + unlink_if_exists("/tmp/backup.tmp"); + + exec("cp /tmp/backup_edit.tmp /usr/local/www/packages/backup/backup_edit.php"); + unlink_if_exists("/tmp/backup_edit.tmp"); + + //write_config(); + + + + php_sync_package(); + + conf_mount_ro(); + config_unlock(); + +} + + +function deinstall_command() +{ + + conf_mount_rw(); + config_lock(); + unlink_if_exists("/usr/local/pkg/backup.xml"); + unlink_if_exists("/usr/local/pkg/backup.inc"); + exec("rm /usr/local/www/packages/backup/"); + conf_mount_ro(); + config_unlock(); + +} + +?> \ No newline at end of file diff --git a/config/backup/backup.tmp b/config/backup/backup.tmp new file mode 100644 index 00000000..6ce7a3ae --- /dev/null +++ b/config/backup/backup.tmp @@ -0,0 +1,309 @@ + 0) { + $backup_cmd = 'tar --create --verbose --gzip --file '.$tmp.$filename.' --directory / '; + foreach ($a_backup as $ent) { + if ($ent['enabled'] =="true"){ + //htmlspecialchars($ent['name']); + //htmlspecialchars($ent['path']); + //htmlspecialchars($ent['description']); + $backup_cmd .= htmlspecialchars($ent['path']).' '; + + } + $i++; + } + //echo $backup_cmd; //exit; + system($backup_cmd); + } + + session_cache_limiter('public'); + $fd = fopen($tmp.$filename, "rb"); + header("Content-Type: binary/octet-stream"); + header("Content-Length: " . filesize($tmp.$filename)); + header('Content-Disposition: attachment; filename="'.$filename.'"'); + fpassthru($fd); + exit; + } +} + +if ($_GET['a'] == "other") { + if ($_GET['t'] == "restore") { + $tmp = '/tmp/'; + $filename = 'pfsense.bak.tgz'; + + //extract the tgz file + if (file_exists('/tmp/'.$filename)) { + //echo "The file $filename exists"; + system('cd /; tar xvpfz /tmp/'.$filename.' '); + header( 'Location: backup.php?savemsg=Backup+has+been+restored.' ) ; + } + else { + header( 'Location: backup.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ; + } + + exit; + } +} + +if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { + $filename = 'pfsense.bak.tgz'; + move_uploaded_file($_FILES['ulfile']['tmp_name'], "/tmp/" . $filename); + $savemsg = "Uploaded file to /tmp/" . htmlentities($_FILES['ulfile']['name']); + system('cd /; tar xvpfz /tmp/'.$filename.' '); +} + + +include("head.inc"); + +?> + + + + +

Backup: Files & Directories

+ + + +
+ + +
+ +
+ + + + \n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
+ + + + + +
+

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

+
+ +
+
+ +
+ +
+ + + + + + + + + +
Upload and Restore
Use this to upload and restore your backup file.File to upload: + + + +
+
+
+
+ + + +\n"; + echo "
\n"; + echo "Backup / Restore
\n"; + echo "The 'backup' button will tar gzip the directories that are listed below to /tmp/pfsense.bak.tgz it then presents a file to download. \n"; + echo "If the backup file does not exist in /tmp/pfsense.bak.tgz then the 'restore' button will be hidden. \n"; + echo "

\n"; + echo "
\n"; + echo " \n"; + if (file_exists('/tmp/pfsense.bak.tgz')) { + echo " \n"; + } + echo "
\n"; + echo "

\n\n"; + + +echo "
\n"; + + +if ($config_change == 1) { + write_config(); + $config_change = 0; +} + +//if ($savemsg) print_info_box($savemsg); +//if (file_exists($d_hostsdirty_path)): echo"

"; +//print_info_box_np("This is an info box."); +//echo"
"; +//endif; + +?> + + + + + + + + + + + 0) { + + foreach ($a_backup as $ent) { + + ?> + + + + + + + + + + + + + + + + + + +
NameEnabledDescription + + + + + + +
+ +
+   + +   + +   + + + + + + +
+
+ + + + + +
+
+ +

+ + +
+
+
+
+
+
+
+
+ + + + + +
+ + + + + diff --git a/config/backup/backup.xml b/config/backup/backup.xml new file mode 100644 index 00000000..44b3809d --- /dev/null +++ b/config/backup/backup.xml @@ -0,0 +1,115 @@ + + + + + + + + Backup + Describe your package requirements here + Currently there are no FAQ items provided. + Backup Settings + 0.1.2 + Settings + /usr/local/pkg/backup.inc + + Backup Files/Dir + Backup settings. +
Diagnostics
+ backup.xml + /packages/backup/backup.php +
+ + + Settings + /pkg_edit.php?xml=backup.xml&id=0 + + + + Settings + /packages/backup.php + + + + installedpackages->package->$packagename->configuration->backup + + /usr/local/pkg/ + 0755 + http://portableusbapps.com/packages/config/backup/backup.xml + + + /usr/local/pkg/ + 0755 + http://portableusbapps.com/packages/config/backup/backup.inc + + + /tmp/ + 0755 + http://portableusbapps.com/packages/config/backup/backup.tmp + + + /tmp/ + 0755 + http://portableusbapps.com/packages/config/backup/backup_edit.tmp + + + + Example Variable One + var1 + Enter the variable one here. + input + + + Example Variable Two + var1 + Enter the variable one here. + input + + + + + + php_sync_package(); + + + php_sync_package(); + + + php_install_command(); + + + deinstall_command(); + +
\ No newline at end of file diff --git a/config/backup/backup_edit.tmp b/config/backup/backup_edit.tmp new file mode 100755 index 00000000..69d63866 --- /dev/null +++ b/config/backup/backup_edit.tmp @@ -0,0 +1,213 @@ + + + + + + +

Backup: Edit

+ + + +
+ + +
+ +
+ + + + +
+ + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
Name + +
Path + +
Enabled + \n"; + echo " \n"; + switch (htmlspecialchars($pconfig['enabled'])) { + case "true": + echo " \n"; + echo " \n"; + break; + case "false": + echo " \n"; + echo " \n"; + + break; + default: + echo " \n"; + echo " \n"; + } + echo " \n"; + ?> +
Description + +
Enter the description here.
+
  + + + + +
+
+ +
+
+
+
+
+
+ +
+ +
+ + + + -- cgit v1.2.3 From 22ed812a199a8b5d779a97389cd26c42731aacad Mon Sep 17 00:00:00 2001 From: mcrane Date: Tue, 17 Mar 2009 12:48:06 -0600 Subject: Change version of Backup package --- config/backup/backup.inc | 7 +------ config/backup/backup.xml | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) (limited to 'config/backup') diff --git a/config/backup/backup.inc b/config/backup/backup.inc index 34fb31e3..fa2783d6 100644 --- a/config/backup/backup.inc +++ b/config/backup/backup.inc @@ -79,7 +79,7 @@ function php_sync_package() backup_sync_package_php(); } - + function php_install_command() { @@ -96,7 +96,6 @@ function php_install_command() exec("mkdir /usr/local/www/packages/backup/"); } - //rename PHP files from .tmp to .php exec("cp /tmp/backup.tmp /usr/local/www/packages/backup/backup.php"); unlink_if_exists("/tmp/backup.tmp"); @@ -104,10 +103,6 @@ function php_install_command() exec("cp /tmp/backup_edit.tmp /usr/local/www/packages/backup/backup_edit.php"); unlink_if_exists("/tmp/backup_edit.tmp"); - //write_config(); - - - php_sync_package(); conf_mount_ro(); diff --git a/config/backup/backup.xml b/config/backup/backup.xml index 44b3809d..6bd813ac 100644 --- a/config/backup/backup.xml +++ b/config/backup/backup.xml @@ -41,7 +41,7 @@ Describe your package requirements here Currently there are no FAQ items provided. Backup Settings - 0.1.2 + 0.1.3 Settings /usr/local/pkg/backup.inc -- cgit v1.2.3 From 9efd4729b34a8e3dcb01f7a370f9ceb5d9b96ce8 Mon Sep 17 00:00:00 2001 From: mcrane Date: Tue, 17 Mar 2009 12:50:17 -0600 Subject: Backup package change path to package files and adjust version --- config/backup/backup.xml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'config/backup') diff --git a/config/backup/backup.xml b/config/backup/backup.xml index 6bd813ac..7f6c7b8a 100644 --- a/config/backup/backup.xml +++ b/config/backup/backup.xml @@ -61,29 +61,29 @@ Settings /packages/backup.php - + - installedpackages->package->$packagename->configuration->backup + installedpackages->package->$packagename->configuration->backup /usr/local/pkg/ - 0755 - http://portableusbapps.com/packages/config/backup/backup.xml + 0755 + http://www.pfsense.com/packages/config/backup/backup.xml /usr/local/pkg/ - 0755 - http://portableusbapps.com/packages/config/backup/backup.inc + 0755 + http://www.pfsense.com/packages/config/backup/backup.inc /tmp/ - 0755 - http://portableusbapps.com/packages/config/backup/backup.tmp + 0755 + http://www.pfsense.com/packages/config/backup/backup.tmp /tmp/ - 0755 - http://portableusbapps.com/packages/config/backup/backup_edit.tmp - + 0755 + http://www.pfsense.com/packages/config/backup/backup_edit.tmp + Example Variable One @@ -97,13 +97,13 @@ Enter the variable one here. input - + php_sync_package(); - + php_sync_package(); -- cgit v1.2.3 From d3b717133d2b78a0fab78dd1169d70273a5d146d Mon Sep 17 00:00:00 2001 From: mcrane Date: Tue, 17 Mar 2009 13:13:05 -0600 Subject: Change repair path to backup.xml --- config/backup/backup.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/backup') diff --git a/config/backup/backup.xml b/config/backup/backup.xml index 7f6c7b8a..594ef398 100644 --- a/config/backup/backup.xml +++ b/config/backup/backup.xml @@ -7,7 +7,7 @@ /* $Id$ */ /* ========================================================================== */ /* - phpservice.xml + backup.xml Copyright (C) 2008 Mark J Crane All rights reserved. */ -- cgit v1.2.3 From 4d775b55e8f015b21f4aef49cb629c9ddba6b173 Mon Sep 17 00:00:00 2001 From: mcrane Date: Tue, 17 Mar 2009 13:15:06 -0600 Subject: Backup package increment build version --- config/backup/backup.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/backup') diff --git a/config/backup/backup.xml b/config/backup/backup.xml index 594ef398..d3e504e3 100644 --- a/config/backup/backup.xml +++ b/config/backup/backup.xml @@ -41,7 +41,7 @@ Describe your package requirements here Currently there are no FAQ items provided. Backup Settings - 0.1.3 + 0.1.4 Settings /usr/local/pkg/backup.inc -- cgit v1.2.3 From e71f29843a079db4b5ca9f6636342c69ab1a22c8 Mon Sep 17 00:00:00 2001 From: mcrane Date: Tue, 17 Mar 2009 13:42:09 -0600 Subject: Backup package example pfsense conf path changed to /cf/conf --- config/backup/backup.tmp | 2 +- config/backup/backup.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'config/backup') diff --git a/config/backup/backup.tmp b/config/backup/backup.tmp index 6ce7a3ae..86d645d0 100644 --- a/config/backup/backup.tmp +++ b/config/backup/backup.tmp @@ -144,7 +144,7 @@ if ($_GET["savemsg"]) { are recommended for backup. - +
pfSense Config/conf
pfSense Config/cf/conf
RRD Graph Data Files/var/db/rrd

diff --git a/config/backup/backup.xml b/config/backup/backup.xml index d3e504e3..a0f72ba2 100644 --- a/config/backup/backup.xml +++ b/config/backup/backup.xml @@ -41,7 +41,7 @@ Describe your package requirements here Currently there are no FAQ items provided. Backup Settings - 0.1.4 + 0.1.5 Settings /usr/local/pkg/backup.inc -- cgit v1.2.3