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 +++++++++++++++++++++++++++++ pkg_config.7.xml | 14 ++ 5 files changed, 783 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 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.
+
  + + + + +
+
+ +
+
+
+
+
+
+ +
+ +
+ + + + diff --git a/pkg_config.7.xml b/pkg_config.7.xml index ee3170a5..fd8f91e1 100755 --- a/pkg_config.7.xml +++ b/pkg_config.7.xml @@ -140,6 +140,20 @@ markjcrane@gmail.com phpservice.xml + + Backup + + Tool to Backup and Restore files and directories. + System + + http://www.pfsense.com/packages/config/phpservice/backup.xml + http://files.pfsense.org/packages/7/All/ + 0.1.2 + Beta + 1.2 + markjcrane@gmail.com + backup.xml + snort Snort is a libpcap-based packet sniffer/logger which can be used as a lightweight network intrusion detection system. It features rules based logging and can perform content searching/matching in addition to being used to detect a variety of other attacks and probes, such as buffer overflows, stealth port scans, CGI attacks, SMB probes, and much more. -- cgit v1.2.3