From 31d4f4e0a177725f98d8e670de3170f0fb47ee3e Mon Sep 17 00:00:00 2001 From: mcrane Date: Fri, 2 Oct 2009 19:21:05 -0600 Subject: Backup package make changes so that it will work on nano version and some white space clean up. --- config/backup/backup.inc | 47 +++----- config/backup/backup.tmp | 257 ++++++++++++++++++++++-------------------- config/backup/backup_edit.tmp | 200 ++++++++++++++++---------------- 3 files changed, 249 insertions(+), 255 deletions(-) (limited to 'config/backup') diff --git a/config/backup/backup.inc b/config/backup/backup.inc index b6adfbc9..13c62f26 100644 --- a/config/backup/backup.inc +++ b/config/backup/backup.inc @@ -33,51 +33,42 @@ function byte_convert( $bytes ) { + if ($bytes<=0) + return '0 Byte'; - if ($bytes<=0) - return '0 Byte'; - - $convention=1000; //[1000->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]; + $convention=1000; //[1000->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(); - + global $config; + if($config['installedpackages']['backup']['config'] != "") { + conf_mount_rw(); 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 .= "// 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(); - } @@ -86,47 +77,41 @@ 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/"); } - + //create the backup directory - if (!is_dir('/root/backup/')) { + if (!is_dir('/root/backup/')) { exec("mkdir /root/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"); - + 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 index 10e03db3..3cada9b3 100644 --- a/config/backup/backup.tmp +++ b/config/backup/backup.tmp @@ -30,26 +30,30 @@ require("guiconfig.inc"); require("/usr/local/pkg/backup.inc"); -$a_backup = &$config['installedpackages']['backup']['config']; +$a_backup = &$config['installedpackages']['backup']['config']; if ($_GET['act'] == "del") { - if ($_GET['type'] == 'backup') { - if ($a_backup[$_GET['id']]) { - unset($a_backup[$_GET['id']]); - write_config(); - header("Location: backup.php"); - exit; - } - } + if ($_GET['type'] == 'backup') { + if ($a_backup[$_GET['id']]) { + conf_mount_rw(); + unset($a_backup[$_GET['id']]); + write_config(); + header("Location: backup.php"); + conf_mount_ro(); + exit; + } + } } 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 / '; @@ -59,48 +63,52 @@ if ($_GET['a'] == "download") { //htmlspecialchars($ent['path']); //htmlspecialchars($ent['description']); $backup_cmd .= htmlspecialchars($ent['path']).' '; - - } + } $i++; - } - //echo $backup_cmd; //exit; - system($backup_cmd); - } - + } + //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); + + conf_mount_ro(); exit; } } if ($_GET['a'] == "other") { - if ($_GET['t'] == "restore") { - $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.' ) ; - } - else { - header( 'Location: backup.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ; - } - - exit; - } + 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.' ) ; + } + else { + header( 'Location: backup.php?savemsg=Restore+failed.+Backup+file+not+found.' ) ; + } + conf_mount_ro(); + exit; + } } if (($_POST['submit'] == "Upload") && is_uploaded_file($_FILES['ulfile']['tmp_name'])) { - $filename = 'pfsense.bak.tgz'; + 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.' '); + conf_mount_ro(); } @@ -115,7 +123,7 @@ include("head.inc"); @@ -123,60 +131,59 @@ if ($_GET["savemsg"]) {
- - +
+
-

+

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
-

+



- +
- +
- - - - - - - - - -
Upload and Restore
Use this to upload and restore your backup file.File to upload: - - - -
-
-
+ + + + + + + + +
Upload and Restore
Use this to upload and restore your backup file.File to upload: + + + +
+
+
- + \n"; @@ -197,7 +204,7 @@ if ($_GET["savemsg"]) { echo "
\n"; echo "

\n\n"; - + echo "
\n"; @@ -213,22 +220,22 @@ if ($config_change == 1) { //endif; ?> - - - - - - - + +
NameEnabledDescription - - - - - - -
- -
+ + + + + @@ -236,55 +243,55 @@ if ($config_change == 1) { $i = 0; if (count($a_backup) > 0) { - - foreach ($a_backup as $ent) { - + + foreach ($a_backup as $ent) { + ?> - - - - - - - + + + + + + - - - - - - - - - - - -
NameEnabledDescription + + + + + + +
+ +
-   - -   - -   - - - - - - -
-
+   + +   + +   + + + + + + +
+
- - - - - -
-
- + ?> + + + + + + + + + +
+ + + + + + + + + +
diff --git a/config/backup/backup_edit.tmp b/config/backup/backup_edit.tmp index 69d63866..12020556 100755 --- a/config/backup/backup_edit.tmp +++ b/config/backup/backup_edit.tmp @@ -5,17 +5,17 @@ backup_edit.php Copyright (C) 2008 Mark J Crane All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - + 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - + 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE @@ -32,7 +32,7 @@ require("guiconfig.inc"); require("/usr/local/pkg/backup.inc"); -$a_backup = &$config['installedpackages']['backup']['config']; +$a_backup = &$config['installedpackages']['backup']['config']; $id = $_GET['id']; if (isset($_POST['id'])) { @@ -40,15 +40,17 @@ if (isset($_POST['id'])) { } if ($_GET['act'] == "del") { - if ($_GET['type'] == 'backup') { - if ($a_backup[$_GET['id']]) { - unset($a_backup[$_GET['id']]); - write_config(); - php_sync_package(); - header("Location: backup.php"); - exit; - } - } + if ($_GET['type'] == 'backup') { + if ($a_backup[$_GET['id']]) { + conf_mount_rw(); + unset($a_backup[$_GET['id']]); + write_config(); + php_sync_package(); + header("Location: backup.php"); + conf_mount_ro(); + exit; + } + } } if (isset($id) && $a_backup[$id]) { @@ -57,7 +59,7 @@ if (isset($id) && $a_backup[$id]) { $pconfig['path'] = $a_backup[$id]['path']; $pconfig['enabled'] = $a_backup[$id]['enabled']; $pconfig['description'] = $a_backup[$id]['description']; - + } if ($_POST) { @@ -66,11 +68,11 @@ if ($_POST) { $pconfig = $_POST; if (!$input_errors) { - + $ent = array(); $ent['name'] = $_POST['name']; - $ent['path'] = $_POST['path']; - $ent['enabled'] = $_POST['enabled']; + $ent['path'] = $_POST['path']; + $ent['enabled'] = $_POST['enabled']; $ent['description'] = $_POST['description']; if (isset($id) && $a_backup[$id]) { @@ -78,13 +80,13 @@ if ($_POST) { $a_backup[$id] = $ent; } else { - //add + //add $a_backup[] = $ent; } - + write_config(); php_sync_package(); - + header("Location: backup.php"); exit; } @@ -112,98 +114,98 @@ function show_advanced_config() {
- - + +
+
-
- -
- - - - - - + + + + + + + + + + + + + + +
Name + + + + +

PHP
+
+

+ --> +
+ + + + + + + - + + - + - - - - - - - - - - - - - - -
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.
-
  - - - - -
- - -
-
-
-
-
-
- -
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