1 |
c1605b35
|
Scott Ullrich
|
<?php
|
2 |
|
|
/* $Id$ */
|
3 |
|
|
/*
|
4 |
|
|
system_firmware_restorefullbackup.php
|
5 |
|
|
Copyright (C) 2011 Scott Ullrich
|
6 |
|
|
All rights reserved.
|
7 |
|
|
|
8 |
|
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9 |
|
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10 |
|
|
All rights reserved.
|
11 |
|
|
|
12 |
|
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
|
|
|
15 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
|
|
|
18 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
19 |
|
|
notice, this list of conditions and the following disclaimer in the
|
20 |
|
|
documentation and/or other materials provided with the distribution.
|
21 |
|
|
|
22 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
/*
|
35 |
e70f748f
|
Scott Ullrich
|
pfSense_BUILDER_BINARIES: /etc/rc.restore_full_backup
|
36 |
c1605b35
|
Scott Ullrich
|
pfSense_MODULE: backup
|
37 |
|
|
*/
|
38 |
|
|
|
39 |
|
|
##|+PRIV
|
40 |
|
|
##|*IDENT=page-diagnostics-restore-full-backup
|
41 |
|
|
##|*NAME=Diagnostics: Restore full backup
|
42 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Restore Full Backup' page.
|
43 |
|
|
##|*MATCH=system_firmware_restorefullbackup.php
|
44 |
|
|
##|-PRIV
|
45 |
|
|
|
46 |
|
|
/* Allow additional execution time 0 = no limit. */
|
47 |
|
|
ini_set('max_execution_time', '0');
|
48 |
|
|
ini_set('max_input_time', '0');
|
49 |
|
|
|
50 |
|
|
require_once("functions.inc");
|
51 |
7c1260e3
|
Scott Ullrich
|
require("guiconfig.inc");
|
52 |
c1605b35
|
Scott Ullrich
|
require_once("filter.inc");
|
53 |
|
|
require_once("shaper.inc");
|
54 |
|
|
|
55 |
4b805dbc
|
Renato Botelho
|
if($_POST['overwriteconfigxml'])
|
56 |
b8bfcce5
|
Scott Ullrich
|
touch("/tmp/do_not_restore_config.xml");
|
57 |
|
|
|
58 |
4b805dbc
|
Renato Botelho
|
if($_GET['backupnow'])
|
59 |
e70f748f
|
Scott Ullrich
|
mwexec_bg("/etc/rc.create_full_backup");
|
60 |
ea76bdaf
|
Scott Ullrich
|
|
61 |
|
|
if($_GET['downloadbackup']) {
|
62 |
62480a44
|
Renato Botelho
|
$filename = basename($_GET['downloadbackup']);
|
63 |
ceb3515d
|
Scott Ullrich
|
$path = "/root/{$filename}";
|
64 |
62480a44
|
Renato Botelho
|
if(file_exists($path)) {
|
65 |
4b805dbc
|
Renato Botelho
|
session_write_close();
|
66 |
|
|
ob_end_clean();
|
67 |
110603e4
|
Scott Ullrich
|
session_cache_limiter('public');
|
68 |
ceb3515d
|
Scott Ullrich
|
//$fd = fopen("/root/{$filename}", "rb");
|
69 |
|
|
$filesize = filesize("/root/{$filename}");
|
70 |
|
|
header("Cache-Control: ");
|
71 |
|
|
header("Pragma: ");
|
72 |
110603e4
|
Scott Ullrich
|
header("Content-Type: application/octet-stream");
|
73 |
ceb3515d
|
Scott Ullrich
|
header("Content-Length: " .(string)(filesize($path)) );
|
74 |
7e2ad1be
|
Scott Ullrich
|
header('Content-Disposition: attachment; filename="'.$filename.'"');
|
75 |
ceb3515d
|
Scott Ullrich
|
header("Content-Transfer-Encoding: binary\n");
|
76 |
|
|
if($file = fopen("/root/{$filename}", 'rb')){
|
77 |
4b805dbc
|
Renato Botelho
|
while( (!feof($file)) && (connection_status()==0) ){
|
78 |
|
|
print(fread($file, 1024*8));
|
79 |
|
|
flush();
|
80 |
|
|
}
|
81 |
|
|
fclose($file);
|
82 |
110603e4
|
Scott Ullrich
|
}
|
83 |
ceb3515d
|
Scott Ullrich
|
|
84 |
110603e4
|
Scott Ullrich
|
exit;
|
85 |
ea76bdaf
|
Scott Ullrich
|
}
|
86 |
e70f748f
|
Scott Ullrich
|
}
|
87 |
|
|
|
88 |
f0f8bee2
|
Scott Ullrich
|
if ($_GET['deletefile']) {
|
89 |
|
|
$filename = $_GET['deletefile'];
|
90 |
|
|
if(file_exists("/root/{$filename}")) {
|
91 |
|
|
unlink("/root/" . $filename);
|
92 |
|
|
$savemsg = gettext("$filename has been deleted.");
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
|
96 |
c1605b35
|
Scott Ullrich
|
if ($_POST['restorefile']) {
|
97 |
|
|
$filename = $_POST['restorefile'];
|
98 |
|
|
if(file_exists("/root/{$filename}")) {
|
99 |
|
|
mwexec_bg("/etc/rc.restore_full_backup /root/" . escapeshellcmd($filename));
|
100 |
|
|
$savemsg = gettext("The firewall is currently restoring $filename");
|
101 |
|
|
}
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
$pgtitle = array(gettext("Diagnostics"),gettext("Restore full backup"));
|
105 |
|
|
include("head.inc");
|
106 |
|
|
|
107 |
|
|
?>
|
108 |
|
|
|
109 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
110 |
|
|
<?php include("fbegin.inc"); ?>
|
111 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
112 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
113 |
|
|
<?php if (is_subsystem_dirty('restore')): ?><p>
|
114 |
|
|
<form action="reboot.php" method="post">
|
115 |
931dde97
|
Colin Fleming
|
<input name="Submit" type="hidden" value="Yes" />
|
116 |
|
|
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br/>" . gettext("The firewall is now rebooting."));?><br/>
|
117 |
c1605b35
|
Scott Ullrich
|
</form>
|
118 |
|
|
<?php endif; ?>
|
119 |
|
|
<form action="system_firmware_restorefullbackup.php" method="post">
|
120 |
931dde97
|
Colin Fleming
|
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="restore full backup">
|
121 |
c1605b35
|
Scott Ullrich
|
<tr>
|
122 |
|
|
<td>
|
123 |
|
|
<?php
|
124 |
|
|
$tab_array = array();
|
125 |
3ff39566
|
Scott Ullrich
|
$tab_array[] = array(gettext("Manual Update"), false, "system_firmware.php");
|
126 |
|
|
$tab_array[] = array(gettext("Auto Update"), false, "system_firmware_check.php");
|
127 |
|
|
$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
|
128 |
|
|
if($g['hidedownloadbackup'] == false)
|
129 |
|
|
$tab_array[] = array(gettext("Restore Full Backup"), true, "system_firmware_restorefullbackup.php");
|
130 |
c1605b35
|
Scott Ullrich
|
display_top_tabs($tab_array);
|
131 |
|
|
?>
|
132 |
|
|
</td>
|
133 |
|
|
</tr>
|
134 |
|
|
<tr>
|
135 |
|
|
<td>
|
136 |
|
|
<div id="mainarea">
|
137 |
931dde97
|
Colin Fleming
|
<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
138 |
c1605b35
|
Scott Ullrich
|
<tr>
|
139 |
1f6442a7
|
Scott Ullrich
|
<td colspan="1" class="listtopic"><?=gettext("Filename"); ?></td>
|
140 |
|
|
<td colspan="1" class="listtopic"><?=gettext("Date"); ?></td>
|
141 |
|
|
<td colspan="1" class="listtopic"><?=gettext("Size"); ?></td>
|
142 |
52971880
|
Vinicius Coque
|
<td colspan="1" class="listtopic"></td>
|
143 |
c1605b35
|
Scott Ullrich
|
</tr>
|
144 |
|
|
<?php
|
145 |
|
|
chdir("/root");
|
146 |
|
|
$available_restore_files = glob("pfSense-full-backup-*");
|
147 |
9928303b
|
Scott Ullrich
|
$counter = 0;
|
148 |
c1605b35
|
Scott Ullrich
|
foreach($available_restore_files as $arf) {
|
149 |
9928303b
|
Scott Ullrich
|
$counter++;
|
150 |
1f6442a7
|
Scott Ullrich
|
$size = exec("gzip -l /root/$arf | grep -v compressed | awk '{ print $2 }'");
|
151 |
c1605b35
|
Scott Ullrich
|
echo "<tr>";
|
152 |
ea76bdaf
|
Scott Ullrich
|
echo "<td class='listlr' width='50%' colspan='1'>";
|
153 |
931dde97
|
Colin Fleming
|
echo "<input type='radio' name='restorefile' value='$arf' /> $arf";
|
154 |
c1605b35
|
Scott Ullrich
|
echo "</td>";
|
155 |
f0f8bee2
|
Scott Ullrich
|
echo "<td class='listr' width='30%' colspan='1'>";
|
156 |
61265070
|
Scott Ullrich
|
echo date ("F d Y H:i:s", filemtime($arf));
|
157 |
c1605b35
|
Scott Ullrich
|
echo "</td>";
|
158 |
1f6442a7
|
Scott Ullrich
|
echo "<td class='listr' width='40%' colspan='1'>";
|
159 |
e70f748f
|
Scott Ullrich
|
echo format_bytes($size);
|
160 |
1f6442a7
|
Scott Ullrich
|
echo "</td>";
|
161 |
931dde97
|
Colin Fleming
|
echo "<td class='listr nowrap' width='20%' colspan='1'>";
|
162 |
7c1260e3
|
Scott Ullrich
|
echo "<a onclick=\"return confirm('" . gettext("Do you really want to delete this backup?") . "')\" href='system_firmware_restorefullbackup.php?deletefile=" . htmlspecialchars($arf) . "'>";
|
163 |
f0f8bee2
|
Scott Ullrich
|
echo gettext("Delete");
|
164 |
ea76bdaf
|
Scott Ullrich
|
echo "</a> | ";
|
165 |
ceb3515d
|
Scott Ullrich
|
echo "<a href='system_firmware_restorefullbackup.php?downloadbackup=" . htmlspecialchars($arf) . "'>";
|
166 |
|
|
echo gettext("Download");
|
167 |
|
|
echo "</a>";
|
168 |
f0f8bee2
|
Scott Ullrich
|
echo "</td>";
|
169 |
c1605b35
|
Scott Ullrich
|
echo "</tr>";
|
170 |
|
|
}
|
171 |
9928303b
|
Scott Ullrich
|
if($counter == 0) {
|
172 |
|
|
echo "<tr>";
|
173 |
931dde97
|
Colin Fleming
|
echo "<td class='listlr' width='100%' colspan='4' align='center'>";
|
174 |
|
|
echo gettext("Could not locate any previous backups.");
|
175 |
9928303b
|
Scott Ullrich
|
echo "</td>";
|
176 |
|
|
echo "</tr>";
|
177 |
|
|
}
|
178 |
4b805dbc
|
Renato Botelho
|
?>
|
179 |
c1605b35
|
Scott Ullrich
|
<tr>
|
180 |
7d86e6a8
|
Scott Ullrich
|
<td width="78%" colspan="3">
|
181 |
b8bfcce5
|
Scott Ullrich
|
<br/>
|
182 |
931dde97
|
Colin Fleming
|
<input type="checkbox" name="overwriteconfigxml" id="overwriteconfigxml" checked="checked" /> <?=gettext("do not restore config.xml."); ?>
|
183 |
|
|
<br/>
|
184 |
|
|
<input name="Restore" type="submit" class="formbtn" id="restore" value="<?=gettext("Restore"); ?>" />
|
185 |
c1605b35
|
Scott Ullrich
|
</td>
|
186 |
|
|
</tr>
|
187 |
|
|
</table>
|
188 |
|
|
</div>
|
189 |
|
|
</td>
|
190 |
|
|
</tr>
|
191 |
|
|
</table>
|
192 |
|
|
</form>
|
193 |
|
|
|
194 |
931dde97
|
Colin Fleming
|
<script type="text/javascript">
|
195 |
|
|
//<![CDATA[
|
196 |
c1605b35
|
Scott Ullrich
|
encrypt_change();
|
197 |
|
|
decrypt_change();
|
198 |
931dde97
|
Colin Fleming
|
//]]>
|
199 |
c1605b35
|
Scott Ullrich
|
</script>
|
200 |
|
|
|
201 |
|
|
<?php include("fend.inc"); ?>
|
202 |
|
|
</body>
|
203 |
|
|
</html>
|
204 |
|
|
<?php
|
205 |
|
|
|
206 |
|
|
if (is_subsystem_dirty('restore'))
|
207 |
|
|
system_reboot();
|
208 |
|
|
|
209 |
52971880
|
Vinicius Coque
|
?>
|