Projet

Général

Profil

Télécharger (6,87 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / system_firmware_restorefullbackup.php @ 62480a44

1
<?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
	pfSense_BUILDER_BINARIES:	/etc/rc.restore_full_backup
36
	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
require("guiconfig.inc");
52
require_once("filter.inc");
53
require_once("shaper.inc");
54

    
55
if($_POST['overwriteconfigxml'])
56
	touch("/tmp/do_not_restore_config.xml");
57

    
58
if($_GET['backupnow'])
59
	mwexec_bg("/etc/rc.create_full_backup");
60

    
61
if($_GET['downloadbackup']) {
62
	$filename = basename($_GET['downloadbackup']);
63
	$path = "/root/{$filename}";
64
	if(file_exists($path)) {
65
		session_write_close();
66
		ob_end_clean();
67
		session_cache_limiter('public');
68
		//$fd = fopen("/root/{$filename}", "rb");
69
		$filesize = filesize("/root/{$filename}");
70
		header("Cache-Control: ");
71
		header("Pragma: ");
72
		header("Content-Type: application/octet-stream");
73
		header("Content-Length: " .(string)(filesize($path)) );
74
		header('Content-Disposition: attachment; filename="'.$filename.'"');
75
		header("Content-Transfer-Encoding: binary\n");
76
		if($file = fopen("/root/{$filename}", 'rb')){
77
			while( (!feof($file)) && (connection_status()==0) ){
78
				print(fread($file, 1024*8));
79
				flush();
80
			}
81
			fclose($file);
82
		}
83

    
84
		exit;
85
	}
86
}
87

    
88
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
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
<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
</form>
118
<?php endif; ?>
119
<form action="system_firmware_restorefullbackup.php" method="post">
120
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="restore full backup">
121
	<tr>
122
		<td>
123
<?php
124
	$tab_array = array();
125
	$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
	display_top_tabs($tab_array);
131
?>
132
		</td>
133
	</tr>
134
	<tr>
135
		<td>
136
			<div id="mainarea">
137
			<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
138
				<tr>
139
					<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
					<td colspan="1" class="listtopic"></td>
143
				</tr>
144
<?php
145
				chdir("/root");
146
				$available_restore_files = glob("pfSense-full-backup-*");
147
				$counter = 0;
148
				foreach($available_restore_files as $arf) {
149
					$counter++;
150
					$size = exec("gzip -l /root/$arf | grep -v compressed | awk '{ print $2 }'");
151
					echo "<tr>";
152
					echo "<td  class='listlr' width='50%' colspan='1'>";
153
					echo "<input type='radio' name='restorefile' value='$arf' /> $arf";
154
					echo "</td>";
155
					echo "<td  class='listr' width='30%' colspan='1'>";
156
					echo date ("F d Y H:i:s", filemtime($arf));
157
					echo "</td>";
158
					echo "<td  class='listr' width='40%' colspan='1'>";
159
					echo format_bytes($size);
160
					echo "</td>";
161
					echo "<td  class='listr nowrap' width='20%' colspan='1'>";
162
					echo "<a onclick=\"return confirm('" . gettext("Do you really want to delete this backup?") . "')\" href='system_firmware_restorefullbackup.php?deletefile=" . htmlspecialchars($arf) . "'>";
163
					echo gettext("Delete");
164
					echo "</a> | ";
165
					echo "<a href='system_firmware_restorefullbackup.php?downloadbackup=" . htmlspecialchars($arf) . "'>";
166
					echo gettext("Download");
167
					echo "</a>";
168
					echo "</td>";
169
					echo "</tr>";
170
				}
171
				if($counter == 0) {
172
					echo "<tr>";
173
					echo "<td  class='listlr' width='100%' colspan='4' align='center'>";
174
					echo gettext("Could not locate any previous backups.");
175
					echo "</td>";
176
					echo "</tr>";
177
				}
178
?>
179
				<tr>
180
					<td width="78%" colspan="3">
181
						&nbsp;<br/>
182
						<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
					</td>
186
				</tr>
187
			</table>
188
			</div>
189
		</td>
190
	</tr>
191
</table>
192
</form>
193

    
194
<script type="text/javascript">
195
//<![CDATA[
196
encrypt_change();
197
decrypt_change();
198
//]]>
199
</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
?>
(209-209/246)