1 |
5b237745
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
8ccc8f1a
|
Scott Ullrich
|
<?php
|
3 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
4 |
5b237745
|
Scott Ullrich
|
/*
|
5 |
|
|
diag_backup.php
|
6 |
07bd3f83
|
Scott Ullrich
|
part of m0n0wall (http://m0n0.ch/wall)
|
7 |
8ccc8f1a
|
Scott Ullrich
|
|
8 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
9 |
|
|
All rights reserved.
|
10 |
8ccc8f1a
|
Scott Ullrich
|
|
11 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
12 |
|
|
modification, are permitted provided that the following conditions are met:
|
13 |
8ccc8f1a
|
Scott Ullrich
|
|
14 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
this list of conditions and the following disclaimer.
|
16 |
8ccc8f1a
|
Scott Ullrich
|
|
17 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
notice, this list of conditions and the following disclaimer in the
|
19 |
|
|
documentation and/or other materials provided with the distribution.
|
20 |
8ccc8f1a
|
Scott Ullrich
|
|
21 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
22 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
23 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
24 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
25 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
31 |
|
|
*/
|
32 |
|
|
|
33 |
|
|
/* omit no-cache headers because it confuses IE with file downloads */
|
34 |
|
|
$omit_nocacheheaders = true;
|
35 |
8ccc8f1a
|
Scott Ullrich
|
require("guiconfig.inc");
|
36 |
5b237745
|
Scott Ullrich
|
|
37 |
df157bb7
|
Scott Ullrich
|
function spit_out_select_items($area) {
|
38 |
8e35abee
|
Scott Ullrich
|
$select = <<<EOD
|
39 |
df157bb7
|
Scott Ullrich
|
<select name="{$area}">
|
40 |
8e35abee
|
Scott Ullrich
|
<option VALUE="">ALL</option>
|
41 |
5161a6e6
|
Scott Ullrich
|
<option VALUE="aliases">Aliases</option>
|
42 |
8e35abee
|
Scott Ullrich
|
<option VALUE="shaper">Traffic Shaper</option>
|
43 |
|
|
<option VALUE="filter">Firewall Rules</option>
|
44 |
|
|
<option VALUE="nat">NAT</option>
|
45 |
|
|
<option VALUE="pptpd">PPTP Server</option>
|
46 |
|
|
<option VALUE="ipsec">IPSEC VPN</option>
|
47 |
|
|
<option VALUE="captiveportal">Captive Portal</option>
|
48 |
|
|
<option VALUE="installedpackages">Package Manager</option>
|
49 |
|
|
<option VALUE="interfaces">Interfaces</option>
|
50 |
|
|
<option VALUE="dhcpd">DHCP Server</option>
|
51 |
|
|
<option VALUE="syslog">Syslog</option>
|
52 |
|
|
<option VALUE="system">System</option>
|
53 |
|
|
</select>
|
54 |
|
|
EOD;
|
55 |
|
|
echo $select;
|
56 |
|
|
|
57 |
|
|
}
|
58 |
|
|
|
59 |
5b237745
|
Scott Ullrich
|
if ($_POST) {
|
60 |
|
|
unset($input_errors);
|
61 |
7cf03119
|
Bill Marquette
|
if (stristr($_POST['Submit'], "Restore configuration"))
|
62 |
5b237745
|
Scott Ullrich
|
$mode = "restore";
|
63 |
8ccc8f1a
|
Scott Ullrich
|
else if (stristr($_POST['Submit'], "Reinstall"))
|
64 |
|
|
$mode = "reinstallpackages";
|
65 |
5b237745
|
Scott Ullrich
|
else if (stristr($_POST['Submit'], "Download"))
|
66 |
|
|
$mode = "download";
|
67 |
7cf03119
|
Bill Marquette
|
else if (stristr($_POST['Submit'], "Restore version"))
|
68 |
|
|
$mode = "restore_ver";
|
69 |
|
|
|
70 |
aab57926
|
Scott Ullrich
|
if ($_POST["nopackages"] <> "")
|
71 |
528cad39
|
Colin Smith
|
$options = "nopackages";
|
72 |
8ccc8f1a
|
Scott Ullrich
|
|
73 |
7cf03119
|
Bill Marquette
|
if ($_POST["ver"] <> "")
|
74 |
|
|
$ver2restore = $_POST["ver"];
|
75 |
|
|
|
76 |
5b237745
|
Scott Ullrich
|
if ($mode) {
|
77 |
|
|
if ($mode == "download") {
|
78 |
|
|
config_lock();
|
79 |
8ccc8f1a
|
Scott Ullrich
|
$fn = "config-" . $config['system']['hostname'] . "." .
|
80 |
5b237745
|
Scott Ullrich
|
$config['system']['domain'] . "-" . date("YmdHis") . ".xml";
|
81 |
528cad39
|
Colin Smith
|
if($options == "nopackages") {
|
82 |
|
|
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' /conf/config.xml > /tmp/config.xml.nopkg");
|
83 |
f66683e6
|
Bill Marquette
|
$fs = filesize("{$g['tmp_path']}/config.xml.nopkg");
|
84 |
528cad39
|
Colin Smith
|
header("Content-Type: application/octet-stream");
|
85 |
|
|
header("Content-Disposition: attachment; filename=$fn");
|
86 |
|
|
header("Content-Length: $fs");
|
87 |
f66683e6
|
Bill Marquette
|
readfile("{$g['tmp_path']}/config.xml.nopkg");
|
88 |
528cad39
|
Colin Smith
|
} else {
|
89 |
181462b5
|
Scott Ullrich
|
if($_POST['backuparea'] <> "") {
|
90 |
|
|
/* user wishes to backup specific area of configuration */
|
91 |
|
|
$current_trafficshaper_section = backup_config_section($_POST['backuparea']);
|
92 |
|
|
/* generate aliases xml */
|
93 |
|
|
$fout = fopen("{$g['tmp_path']}/backup_section.txt","w");
|
94 |
|
|
fwrite($fout, $current_trafficshaper_section);
|
95 |
|
|
fclose($fout);
|
96 |
|
|
$fs = filesize($g['tmp_path'] . "/backup_section.txt");
|
97 |
|
|
header("Content-Type: application/octet-stream");
|
98 |
|
|
$fn = $_POST['backuparea'] . "-" . $fn;
|
99 |
|
|
header("Content-Disposition: attachment; filename=$fn");
|
100 |
|
|
header("Content-Length: $fs");
|
101 |
e55f5da6
|
Scott Ullrich
|
readfile($g['tmp_path'] . "/backup_section.txt");
|
102 |
7e036443
|
Scott Ullrich
|
unlink($g['tmp_path'] . "/backup_section.txt");
|
103 |
181462b5
|
Scott Ullrich
|
} else {
|
104 |
|
|
$fs = filesize($g['conf_path'] . "/config.xml");
|
105 |
|
|
header("Content-Type: application/octet-stream");
|
106 |
|
|
header("Content-Disposition: attachment; filename=$fn");
|
107 |
|
|
header("Content-Length: $fs");
|
108 |
|
|
readfile($g['conf_path'] . "/config.xml");
|
109 |
|
|
}
|
110 |
528cad39
|
Colin Smith
|
}
|
111 |
5b237745
|
Scott Ullrich
|
config_unlock();
|
112 |
|
|
exit;
|
113 |
|
|
} else if ($mode == "restore") {
|
114 |
|
|
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
|
115 |
181462b5
|
Scott Ullrich
|
$fd = fopen($_FILES['conffile']['tmp_name'], "r");
|
116 |
|
|
if(!$fd) {
|
117 |
|
|
log_error("Warning, could not open " . $_FILES['conffile']['tmp_name']);
|
118 |
|
|
return 1;
|
119 |
|
|
}
|
120 |
|
|
while(!feof($fd)) {
|
121 |
|
|
$tmp .= fread($fd,49);
|
122 |
|
|
}
|
123 |
|
|
fclose($fd);
|
124 |
|
|
if(stristr($tmp, "m0n0wall" != false)) {
|
125 |
|
|
log_error("Upgrading m0n0wall configuration to pfsense.");
|
126 |
|
|
/* m0n0wall was found in config. convert it. */
|
127 |
|
|
$upgradedconfig = str_replace("m0n0wall", "pfsense", $tmp);
|
128 |
|
|
fopen($_FILES['conffile']['tmp_name'], "w");
|
129 |
|
|
fwrite($fd, $upgradedconfig);
|
130 |
bfd3e487
|
Scott Ullrich
|
fclose($fd);
|
131 |
181462b5
|
Scott Ullrich
|
}
|
132 |
fdef6434
|
Bill Marquette
|
if($_POST['restorearea'] <> "") {
|
133 |
181462b5
|
Scott Ullrich
|
/* restore a specific area of the configuration */
|
134 |
7822d966
|
Colin Smith
|
$rules = file_get_contents($_FILES['conffile']['tmp_name']);
|
135 |
fdef6434
|
Bill Marquette
|
restore_config_section($_POST['restorearea'], $rules);
|
136 |
f4f07798
|
Scott Ullrich
|
filter_configure();
|
137 |
|
|
$savemsg = "The configuration area has been restored.";
|
138 |
5b237745
|
Scott Ullrich
|
} else {
|
139 |
181462b5
|
Scott Ullrich
|
/* restore the entire configuration */
|
140 |
|
|
if (config_install($_FILES['conffile']['tmp_name']) == 0) {
|
141 |
923e16ed
|
Scott Ullrich
|
/* this will be picked up by /index.php */
|
142 |
|
|
conf_mount_rw();
|
143 |
07cd2b4b
|
Scott Ullrich
|
touch("/needs_package_sync");
|
144 |
923e16ed
|
Scott Ullrich
|
conf_mount_ro();
|
145 |
8ed1f1a9
|
Scott Ullrich
|
$reloadall = true;
|
146 |
|
|
|
147 |
4cf2cc4a
|
Scott Ullrich
|
$savemsg = "The configuration has been restored. The firewall is now reloading the settings.";
|
148 |
181462b5
|
Scott Ullrich
|
} else {
|
149 |
|
|
$input_errors[] = "The configuration could not be restored.";
|
150 |
|
|
}
|
151 |
923e16ed
|
Scott Ullrich
|
}
|
152 |
5b237745
|
Scott Ullrich
|
} else {
|
153 |
|
|
$input_errors[] = "The configuration could not be restored (file upload error).";
|
154 |
|
|
}
|
155 |
8ccc8f1a
|
Scott Ullrich
|
} else if ($mode == "reinstallpackages") {
|
156 |
|
|
header("Location: pkg_mgr_install.php?mode=reinstallall");
|
157 |
|
|
exit;
|
158 |
7cf03119
|
Bill Marquette
|
} else if ($mode == "restore_ver") {
|
159 |
|
|
$input_errors[] = "XXX - this feature may hose your config (do NOT backrev configs!) - billm";
|
160 |
|
|
if ($ver2restore <> "") {
|
161 |
|
|
$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
|
162 |
|
|
if (config_install($conf_file) == 0) {
|
163 |
8ed1f1a9
|
Scott Ullrich
|
$reloadall = true;
|
164 |
4cf2cc4a
|
Scott Ullrich
|
$savemsg = "The configuration has been restored. The firewall is now reloading the settings.";
|
165 |
7cf03119
|
Bill Marquette
|
} else {
|
166 |
|
|
$input_errors[] = "The configuration could not be restored.";
|
167 |
|
|
}
|
168 |
|
|
} else {
|
169 |
|
|
$input_errors[] = "No version selected.";
|
170 |
|
|
}
|
171 |
5b237745
|
Scott Ullrich
|
}
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
6a1e6651
|
Bill Marquette
|
|
175 |
02e1170d
|
Scott Ullrich
|
$id = rand() . '.' . time();
|
176 |
|
|
|
177 |
|
|
$mth = ini_get('upload_progress_meter.store_method');
|
178 |
|
|
$dir = ini_get('upload_progress_meter.file.filename_template');
|
179 |
|
|
|
180 |
b63695db
|
Scott Ullrich
|
$pgtitle = "Diagnostics: Backup/restore";
|
181 |
|
|
include("head.inc");
|
182 |
|
|
|
183 |
5b237745
|
Scott Ullrich
|
?>
|
184 |
|
|
|
185 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
186 |
|
|
<?php include("fbegin.inc"); ?>
|
187 |
310b2c06
|
Bill Marquette
|
<p class="pgtitle"><?=$pgtitle?></p>
|
188 |
9e2a4fce
|
Erik Kristensen
|
|
189 |
|
|
<form action="diag_backup.php" method="post" enctype="multipart/form-data" onSubmit="check_upload_status(<?= $id; ?>);">
|
190 |
|
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
191 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
192 |
|
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
193 |
|
|
<tr>
|
194 |
|
|
<td>
|
195 |
12af52d9
|
Scott Ullrich
|
<?php
|
196 |
9e2a4fce
|
Erik Kristensen
|
$tab_array = array();
|
197 |
|
|
$tab_array[0] = array("Local", true, "diag_backup.php");
|
198 |
|
|
$tab_array[1] = array("Remote", false, "diag_confbak.php");
|
199 |
|
|
display_top_tabs($tab_array);
|
200 |
12af52d9
|
Scott Ullrich
|
?>
|
201 |
9e2a4fce
|
Erik Kristensen
|
</td>
|
202 |
|
|
</tr>
|
203 |
|
|
<tr>
|
204 |
|
|
<td>
|
205 |
|
|
<div id="mainarea">
|
206 |
|
|
<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
|
207 |
|
|
<tr>
|
208 |
|
|
<td colspan="2" class="listtopic">Backup configuration</td>
|
209 |
|
|
</tr>
|
210 |
|
|
<tr>
|
211 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
212 |
|
|
<td width="78%" class="vtable">
|
213 |
|
|
<p>Click this button to download the system configuration in XML format.<br /><br /> Backup area: <?php spit_out_select_items("backuparea"); ?></p>
|
214 |
|
|
<p><input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">Do not backup package information.</p>
|
215 |
|
|
<p><input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration"></p>
|
216 |
|
|
</td>
|
217 |
|
|
</tr>
|
218 |
|
|
<tr>
|
219 |
|
|
<td colspan="2" class="list" height="12"> </td>
|
220 |
5b237745
|
Scott Ullrich
|
</tr>
|
221 |
8ccc8f1a
|
Scott Ullrich
|
<tr>
|
222 |
9e2a4fce
|
Erik Kristensen
|
<td colspan="2" class="listtopic">Restore configuration</td>
|
223 |
|
|
</tr>
|
224 |
|
|
<tr>
|
225 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
226 |
|
|
<td width="78%" class="vtable">
|
227 |
|
|
Open a pfSense configuration XML file and click the button below to restore the configuration. <br /><br /> Restore area: <?php spit_out_select_items("restorearea"); ?>
|
228 |
|
|
<p><input name="conffile" type="file" class="formfld" id="conffile" size="40"></p>
|
229 |
|
|
<p><input name="Submit" type="submit" class="formbtn" id="restore" value="Restore configuration"></p>
|
230 |
|
|
<p><strong><span class="red">Note:</span></strong><br />The firewall will reload the settings after restoring the configuration.<br /></p>
|
231 |
|
|
</td>
|
232 |
|
|
</tr>
|
233 |
|
|
<?php if($config['installedpackages']['package'] != "") { ?>
|
234 |
|
|
<tr>
|
235 |
|
|
<td colspan="2" class="list" height="12"> </td>
|
236 |
|
|
</tr>
|
237 |
|
|
<tr>
|
238 |
|
|
<td colspan="2" class="listtopic">Reinstall packages</td>
|
239 |
|
|
</tr>
|
240 |
|
|
<tr>
|
241 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
242 |
|
|
<td width="78%" class="vtable">
|
243 |
|
|
<p>Click this button to reinstall all system packages. This may take a while. <br /><br />
|
244 |
|
|
<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="Reinstall packages">
|
245 |
|
|
</td>
|
246 |
|
|
</tr>
|
247 |
|
|
<?php } ?>
|
248 |
|
|
</table>
|
249 |
|
|
</div>
|
250 |
b24bf37b
|
Colin Smith
|
</td>
|
251 |
9e2a4fce
|
Erik Kristensen
|
</tr>
|
252 |
|
|
</table>
|
253 |
|
|
</form>
|
254 |
|
|
|
255 |
5b237745
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
256 |
|
|
</body>
|
257 |
38d48421
|
Colin Smith
|
</html>
|
258 |
8ed1f1a9
|
Scott Ullrich
|
|
259 |
|
|
<?php
|
260 |
|
|
|
261 |
|
|
if($reloadall == true) {
|
262 |
|
|
reload_all();
|
263 |
|
|
}
|
264 |
|
|
|
265 |
7822d966
|
Colin Smith
|
?>
|