1 |
8ccc8f1a
|
Scott Ullrich
|
<?php
|
2 |
b46bfcf5
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
diag_backup.php
|
5 |
13d193c2
|
Scott Ullrich
|
Copyright (C) 2004-2009 Scott Ullrich
|
6 |
929db667
|
Scott Ullrich
|
All rights reserved.
|
7 |
8ccc8f1a
|
Scott Ullrich
|
|
8 |
929db667
|
Scott Ullrich
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10 |
|
|
All rights reserved.
|
11 |
8ccc8f1a
|
Scott Ullrich
|
|
12 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
13 |
|
|
modification, are permitted provided that the following conditions are met:
|
14 |
8ccc8f1a
|
Scott Ullrich
|
|
15 |
5b237745
|
Scott Ullrich
|
1. Redistributions of source code must retain the above copyright notice,
|
16 |
|
|
this list of conditions and the following disclaimer.
|
17 |
8ccc8f1a
|
Scott Ullrich
|
|
18 |
5b237745
|
Scott Ullrich
|
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 |
8ccc8f1a
|
Scott Ullrich
|
|
22 |
5b237745
|
Scott Ullrich
|
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 |
13d193c2
|
Scott Ullrich
|
/*
|
35 |
|
|
pfSense_BUILDER_BINARIES: /sbin/shutdown
|
36 |
|
|
pfSense_MODULE: backup
|
37 |
|
|
*/
|
38 |
|
|
|
39 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
40 |
|
|
##|*IDENT=page-diagnostics-backup/restore
|
41 |
|
|
##|*NAME=Diagnostics: Backup/restore page
|
42 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Backup/restore' page.
|
43 |
|
|
##|*MATCH=diag_backup.php*
|
44 |
|
|
##|-PRIV
|
45 |
|
|
|
46 |
47d11b79
|
Mark Crane
|
/* Allow additional execution time 0 = no limit. */
|
47 |
3420028c
|
Scott Ullrich
|
ini_set('max_execution_time', '0');
|
48 |
|
|
ini_set('max_input_time', '0');
|
49 |
47d11b79
|
Mark Crane
|
|
50 |
5b237745
|
Scott Ullrich
|
/* omit no-cache headers because it confuses IE with file downloads */
|
51 |
|
|
$omit_nocacheheaders = true;
|
52 |
8ccc8f1a
|
Scott Ullrich
|
require("guiconfig.inc");
|
53 |
7a927e67
|
Scott Ullrich
|
require_once("functions.inc");
|
54 |
|
|
require_once("filter.inc");
|
55 |
|
|
require_once("shaper.inc");
|
56 |
5b237745
|
Scott Ullrich
|
|
57 |
3420028c
|
Scott Ullrich
|
function add_base_packages_menu_items() {
|
58 |
|
|
global $g, $config;
|
59 |
|
|
$base_packages = split($g['base_packages'], ",");
|
60 |
|
|
$modified_config = false;
|
61 |
|
|
foreach($base_packages as $bp) {
|
62 |
da17d77e
|
Ermal Lu?i
|
$basepkg_path = "/usr/local/pkg/{$bp}";
|
63 |
|
|
$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
|
64 |
|
|
if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
|
65 |
|
|
$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
|
66 |
3420028c
|
Scott Ullrich
|
if($pkg_config['menu'] != "") {
|
67 |
|
|
if(is_array($pkg_config['menu'])) {
|
68 |
|
|
foreach($pkg_config['menu'] as $menu) {
|
69 |
|
|
if(is_array($config['installedpackages']['menu']))
|
70 |
|
|
foreach($config['installedpackages']['menu'] as $amenu)
|
71 |
|
|
if($amenu['name'] == $menu['name'])
|
72 |
|
|
continue;
|
73 |
|
|
$config['installedpackages']['menu'][] = $menu;
|
74 |
|
|
$modified_config = true;
|
75 |
|
|
}
|
76 |
|
|
}
|
77 |
|
|
$static_output .= "done.\n";
|
78 |
|
|
update_output_window($static_output);
|
79 |
|
|
}
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
if($modified_config) {
|
83 |
|
|
write_confg("Restored base_package menus after configuration restore.");
|
84 |
|
|
$config = parse_config(true);
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
645ec835
|
Scott Ullrich
|
function remove_bad_chars($string) {
|
89 |
|
|
return preg_replace('/[^a-z|_|0-9]/i','',$string);
|
90 |
|
|
}
|
91 |
|
|
|
92 |
b3277798
|
Scott Ullrich
|
function check_and_returnif_section_exists($section) {
|
93 |
|
|
global $config;
|
94 |
|
|
if(is_array($config[$section]))
|
95 |
|
|
return true;
|
96 |
|
|
return false;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
3244aa21
|
Scott Ullrich
|
function spit_out_select_items($area, $showall) {
|
100 |
b3277798
|
Scott Ullrich
|
global $config;
|
101 |
f47e0c8a
|
Scott Ullrich
|
|
102 |
b3277798
|
Scott Ullrich
|
$areas = array("aliases" => "Aliases",
|
103 |
5542b8f5
|
Scott Ullrich
|
"captiveportal" => "Captive Portal",
|
104 |
|
|
"dnsmasq" => "DNS Forwarder",
|
105 |
|
|
"dhcpd" => "DHCP Server",
|
106 |
b3277798
|
Scott Ullrich
|
"filter" => "Firewall Rules",
|
107 |
5542b8f5
|
Scott Ullrich
|
"interfaces" => "Interfaces",
|
108 |
b3277798
|
Scott Ullrich
|
"ipsec" => "IPSEC",
|
109 |
5542b8f5
|
Scott Ullrich
|
"nat" => "NAT",
|
110 |
|
|
"ovpn" => "OpenVPN",
|
111 |
b3277798
|
Scott Ullrich
|
"installedpackages" => "Package Manager",
|
112 |
5542b8f5
|
Scott Ullrich
|
"pptpd" => "PPTP Server",
|
113 |
|
|
"cron" => "Scheduled Tasks",
|
114 |
b3277798
|
Scott Ullrich
|
"syslog" => "Syslog",
|
115 |
|
|
"system" => "System",
|
116 |
5542b8f5
|
Scott Ullrich
|
"staticroutes" => "Static routes",
|
117 |
|
|
"sysctl" => "System tunables",
|
118 |
|
|
"snmpd" => "SNMP Server",
|
119 |
|
|
"shaper" => "Traffic Shaper",
|
120 |
|
|
"vlans" => "VLANS",
|
121 |
|
|
"wol" => "Wake on LAN"
|
122 |
b3277798
|
Scott Ullrich
|
);
|
123 |
|
|
|
124 |
a1003d57
|
Ermal Lu?i
|
$select = "<select name=\"{$area}\" id=\"{$aread}\" ";
|
125 |
|
|
if ($area == "backuparea")
|
126 |
|
|
$select .= " onChange=backuparea_change(this)";
|
127 |
|
|
$select .= " >\n";
|
128 |
b3277798
|
Scott Ullrich
|
$select .= "<option VALUE=\"\">ALL</option>";
|
129 |
|
|
|
130 |
eef938b5
|
Scott Ullrich
|
if($showall == true)
|
131 |
|
|
foreach($areas as $area => $areaname)
|
132 |
|
|
$select .= "<option value='{$area}'>{$areaname}</option>\n";
|
133 |
3244aa21
|
Scott Ullrich
|
else
|
134 |
|
|
foreach($areas as $area => $areaname)
|
135 |
|
|
if(check_and_returnif_section_exists($area) == true)
|
136 |
|
|
$select .= "<option value='{$area}'>{$areaname}</option>\n";
|
137 |
b3277798
|
Scott Ullrich
|
|
138 |
|
|
$select .= "</select>\n";
|
139 |
|
|
|
140 |
8e35abee
|
Scott Ullrich
|
echo $select;
|
141 |
|
|
|
142 |
|
|
}
|
143 |
|
|
|
144 |
da17d77e
|
Ermal Lu?i
|
if ($_POST['apply']) {
|
145 |
|
|
ob_flush();
|
146 |
|
|
flush();
|
147 |
344c68b2
|
sullrich
|
conf_mount_rw();
|
148 |
|
|
clear_subsystem_dirty("restore");
|
149 |
|
|
conf_mount_ro();
|
150 |
da17d77e
|
Ermal Lu?i
|
exit;
|
151 |
|
|
}
|
152 |
|
|
|
153 |
5b237745
|
Scott Ullrich
|
if ($_POST) {
|
154 |
|
|
unset($input_errors);
|
155 |
7cf03119
|
Bill Marquette
|
if (stristr($_POST['Submit'], "Restore configuration"))
|
156 |
5b237745
|
Scott Ullrich
|
$mode = "restore";
|
157 |
8ccc8f1a
|
Scott Ullrich
|
else if (stristr($_POST['Submit'], "Reinstall"))
|
158 |
|
|
$mode = "reinstallpackages";
|
159 |
5b237745
|
Scott Ullrich
|
else if (stristr($_POST['Submit'], "Download"))
|
160 |
|
|
$mode = "download";
|
161 |
7cf03119
|
Bill Marquette
|
else if (stristr($_POST['Submit'], "Restore version"))
|
162 |
|
|
$mode = "restore_ver";
|
163 |
|
|
|
164 |
aab57926
|
Scott Ullrich
|
if ($_POST["nopackages"] <> "")
|
165 |
528cad39
|
Colin Smith
|
$options = "nopackages";
|
166 |
8ccc8f1a
|
Scott Ullrich
|
|
167 |
7cf03119
|
Bill Marquette
|
if ($_POST["ver"] <> "")
|
168 |
|
|
$ver2restore = $_POST["ver"];
|
169 |
|
|
|
170 |
5b237745
|
Scott Ullrich
|
if ($mode) {
|
171 |
8ff5ffcc
|
Matthew Grooms
|
|
172 |
5b237745
|
Scott Ullrich
|
if ($mode == "download") {
|
173 |
8ff5ffcc
|
Matthew Grooms
|
|
174 |
|
|
if ($_POST['encrypt']) {
|
175 |
|
|
if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
|
176 |
|
|
$input_errors[] = "You must supply and confirm the password for encryption.";
|
177 |
|
|
if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
|
178 |
|
|
$input_errors[] = "The supplied 'Password' and 'Confirm' field values must match.";
|
179 |
528cad39
|
Colin Smith
|
}
|
180 |
8ff5ffcc
|
Matthew Grooms
|
|
181 |
|
|
if (!$input_errors) {
|
182 |
|
|
|
183 |
07b1797b
|
sullrich
|
//$lockbckp = lock('config');
|
184 |
8ff5ffcc
|
Matthew Grooms
|
|
185 |
|
|
$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
|
186 |
|
|
$name = "config-{$host}-".date("YmdHis").".xml";
|
187 |
|
|
$data = "";
|
188 |
|
|
|
189 |
|
|
if($options == "nopackages") {
|
190 |
4195c967
|
sullrich
|
if(!$_POST['backuparea']) {
|
191 |
|
|
/* backup entire configuration */
|
192 |
|
|
$data = file_get_contents("{$g['conf_path']}/config.xml");
|
193 |
|
|
} else {
|
194 |
|
|
/* backup specific area of configuration */
|
195 |
|
|
$data = backup_config_section($_POST['backuparea']);
|
196 |
|
|
$name = "{$_POST['backuparea']}-{$name}";
|
197 |
|
|
}
|
198 |
da17d77e
|
Ermal Lu?i
|
$sfn = "{$g['tmp_path']}/config.xml.nopkg";
|
199 |
4195c967
|
sullrich
|
file_put_contents($sfn, $data);
|
200 |
|
|
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
|
201 |
|
|
$data = file_get_contents($sfn . "-new");
|
202 |
8ff5ffcc
|
Matthew Grooms
|
} else {
|
203 |
|
|
if(!$_POST['backuparea']) {
|
204 |
|
|
/* backup entire configuration */
|
205 |
|
|
$data = file_get_contents("{$g['conf_path']}/config.xml");
|
206 |
|
|
} else {
|
207 |
|
|
/* backup specific area of configuration */
|
208 |
|
|
$data = backup_config_section($_POST['backuparea']);
|
209 |
|
|
$name = "{$_POST['backuparea']}-{$name}";
|
210 |
|
|
}
|
211 |
181462b5
|
Scott Ullrich
|
}
|
212 |
8ff5ffcc
|
Matthew Grooms
|
|
213 |
07b1797b
|
sullrich
|
//unlock($lockbckp);
|
214 |
da17d77e
|
Ermal Lu?i
|
|
215 |
8ff5ffcc
|
Matthew Grooms
|
if ($_POST['encrypt']) {
|
216 |
|
|
$data = encrypt_data($data, $_POST['encrypt_password']);
|
217 |
|
|
tagfile_reformat($data, $data, "config.xml");
|
218 |
181462b5
|
Scott Ullrich
|
}
|
219 |
8ff5ffcc
|
Matthew Grooms
|
|
220 |
1390b049
|
Scott Ullrich
|
/*
|
221 |
|
|
* Backup RRD Data
|
222 |
|
|
*/
|
223 |
|
|
if(!$_POST['donotbackuprrd']) {
|
224 |
|
|
$data = str_replace("</pfsense>", "\t<rrddata>", $data);
|
225 |
|
|
$rrd_files_var_db_rrd = split("\n",`cd /var/db/rrd && ls *.rrd`);
|
226 |
|
|
foreach($rrd_files_var_db_rrd as $rrd) {
|
227 |
|
|
if($rrd) {
|
228 |
|
|
$rrd_data = file_get_contents("{$g['vardb_path']}/rrd/{$rrd}");
|
229 |
|
|
if($rrd_data) {
|
230 |
|
|
$data .= "\t\t<rrddatafile>\n";
|
231 |
|
|
$data .= "\t\t\t<filename>{$rrd}</filename>\n";
|
232 |
|
|
$data .= "\t\t\t<data>" . base64_encode($rrd_data) . "</data>\n";
|
233 |
|
|
$data .= "\t\t</rrddatafile>\n";
|
234 |
|
|
}
|
235 |
|
|
}
|
236 |
|
|
}
|
237 |
|
|
$data .= "\t</rrddata>\n";
|
238 |
|
|
$data .= "</pfsense>\n";
|
239 |
|
|
}
|
240 |
|
|
|
241 |
8ff5ffcc
|
Matthew Grooms
|
$size = strlen($data);
|
242 |
|
|
header("Content-Type: application/octet-stream");
|
243 |
|
|
header("Content-Disposition: attachment; filename={$name}");
|
244 |
|
|
header("Content-Length: $size");
|
245 |
|
|
echo $data;
|
246 |
|
|
|
247 |
|
|
exit;
|
248 |
|
|
}
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
if ($mode == "restore") {
|
252 |
|
|
|
253 |
|
|
if ($_POST['decrypt']) {
|
254 |
|
|
if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
|
255 |
|
|
$input_errors[] = "You must supply and confirm the password for decryption.";
|
256 |
|
|
if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
|
257 |
|
|
$input_errors[] = "The supplied 'Password' and 'Confirm' field values must match.";
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
if (!$input_errors) {
|
261 |
|
|
|
262 |
|
|
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
|
263 |
|
|
|
264 |
|
|
/* read the file contents */
|
265 |
|
|
$data = file_get_contents($_FILES['conffile']['tmp_name']);
|
266 |
|
|
if(!$data) {
|
267 |
|
|
log_error("Warning, could not read file " . $_FILES['conffile']['tmp_name']);
|
268 |
|
|
return 1;
|
269 |
9fd18b1f
|
Scott Ullrich
|
}
|
270 |
8ff5ffcc
|
Matthew Grooms
|
|
271 |
|
|
if ($_POST['decrypt']) {
|
272 |
|
|
if (!tagfile_deformat($data, $data, "config.xml")) {
|
273 |
|
|
$input_errors[] = "The uploaded file does not appear to contain an encrypted pfsense configuration.";
|
274 |
|
|
return 1;
|
275 |
|
|
}
|
276 |
|
|
$data = decrypt_data($data, $_POST['decrypt_password']);
|
277 |
|
|
}
|
278 |
|
|
|
279 |
1d683793
|
sullrich
|
if(stristr($data, "<m0n0wall>")) {
|
280 |
8ff5ffcc
|
Matthew Grooms
|
log_error("Upgrading m0n0wall configuration to pfsense.");
|
281 |
|
|
/* m0n0wall was found in config. convert it. */
|
282 |
|
|
$data = str_replace("m0n0wall", "pfsense", $data);
|
283 |
|
|
$m0n0wall_upgrade = true;
|
284 |
|
|
}
|
285 |
|
|
if($_POST['restorearea']) {
|
286 |
|
|
/* restore a specific area of the configuration */
|
287 |
|
|
if(!stristr($data, $_POST['restorearea'])) {
|
288 |
34cdf949
|
Chris Buechler
|
$input_errors[] = "You have selected to restore an area but we could not locate the correct xml tag.";
|
289 |
8ff5ffcc
|
Matthew Grooms
|
} else {
|
290 |
|
|
restore_config_section($_POST['restorearea'], $data);
|
291 |
|
|
filter_configure();
|
292 |
|
|
$savemsg = "The configuration area has been restored. You may need to reboot the firewall.";
|
293 |
|
|
}
|
294 |
181462b5
|
Scott Ullrich
|
} else {
|
295 |
6819b7f6
|
Renato Botelho
|
if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
|
296 |
2a48bc00
|
Renato Botelho
|
$input_errors[] = "You have selected to restore the full configuration but we could not locate a " . $g['xml_rootobj'] . " tag.";
|
297 |
8ff5ffcc
|
Matthew Grooms
|
} else {
|
298 |
|
|
/* restore the entire configuration */
|
299 |
|
|
file_put_contents($_FILES['conffile']['tmp_name'], $data);
|
300 |
|
|
if (config_install($_FILES['conffile']['tmp_name']) == 0) {
|
301 |
|
|
/* this will be picked up by /index.php */
|
302 |
|
|
conf_mount_rw();
|
303 |
da17d77e
|
Ermal Lu?i
|
mark_subsystem_dirty("restore");
|
304 |
09821234
|
Scott Ullrich
|
touch("/conf/needs_package_sync");
|
305 |
8ff5ffcc
|
Matthew Grooms
|
/* remove cache, we will force a config reboot */
|
306 |
da17d77e
|
Ermal Lu?i
|
if(file_exists("{$g['tmp_path']}/config.cache"))
|
307 |
|
|
unlink("{$g['tmp_path']}/config.cache");
|
308 |
8ff5ffcc
|
Matthew Grooms
|
$config = parse_config(true);
|
309 |
1390b049
|
Scott Ullrich
|
/* extract out rrd items, unset from $confgi when done */
|
310 |
|
|
if($config['rrddata']) {
|
311 |
|
|
foreach($config['rrddata']['rrddatafile'] as $rrd) {
|
312 |
|
|
$rrd_fd = fopen("{$g['vardb_path']}/rrd/{$rrd['filename']}", "w");
|
313 |
5dd4db17
|
Scott Ullrich
|
fwrite($rrd_fd, base64_decode($rrd['data']));
|
314 |
1390b049
|
Scott Ullrich
|
fclose($rrd_fd);
|
315 |
|
|
}
|
316 |
a2b8f7b2
|
Scott Ullrich
|
unset($config['rrddata']);
|
317 |
da17d77e
|
Ermal Lu?i
|
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
318 |
a2b8f7b2
|
Scott Ullrich
|
write_config();
|
319 |
3420028c
|
Scott Ullrich
|
add_base_packages_menu_items();
|
320 |
d442e4e2
|
Scott Ullrich
|
convert_config();
|
321 |
a2b8f7b2
|
Scott Ullrich
|
conf_mount_ro();
|
322 |
1390b049
|
Scott Ullrich
|
}
|
323 |
8ff5ffcc
|
Matthew Grooms
|
if($m0n0wall_upgrade == true) {
|
324 |
|
|
if($config['system']['gateway'] <> "")
|
325 |
|
|
$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
|
326 |
|
|
unset($config['shaper']);
|
327 |
|
|
/* optional if list */
|
328 |
|
|
$ifdescrs = get_configured_interface_list(true, true);
|
329 |
|
|
/* remove special characters from interface descriptions */
|
330 |
|
|
if(is_array($ifdescrs))
|
331 |
|
|
foreach($ifdescrs as $iface)
|
332 |
|
|
$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
|
333 |
b6db8ea3
|
sullrich
|
/* check for interface names with an alias */
|
334 |
|
|
if(is_array($ifdescrs)) {
|
335 |
|
|
foreach($ifdescrs as $iface) {
|
336 |
|
|
if(is_alias($config['interfaces'][$iface]['descr'])) {
|
337 |
|
|
// Firewall rules
|
338 |
|
|
$origname = $config['interfaces'][$iface]['descr'];
|
339 |
|
|
$newname = $config['interfaces'][$iface]['descr'] . "Alias";
|
340 |
978fd2e8
|
Scott Ullrich
|
update_alias_names_upon_change('filter', 'rule', 'source', 'address', $newname, $origname);
|
341 |
|
|
update_alias_names_upon_change('filter', 'rule', 'destination', 'address', $newname, $origname);
|
342 |
b6db8ea3
|
sullrich
|
// NAT Rules
|
343 |
978fd2e8
|
Scott Ullrich
|
update_alias_names_upon_change('nat', 'rule', 'target', '', $newname, $origname);
|
344 |
|
|
update_alias_names_upon_change('nat', 'rule', 'external-port', '', $newname, $origname);
|
345 |
|
|
update_alias_names_upon_change('nat', 'rule', 'local-port', '', $newname, $origname);
|
346 |
b6db8ea3
|
sullrich
|
// Alias in an alias
|
347 |
978fd2e8
|
Scott Ullrich
|
update_alias_names_upon_change('aliases', 'alias', 'address', '', $newname, $origname);
|
348 |
b6db8ea3
|
sullrich
|
}
|
349 |
|
|
}
|
350 |
|
|
}
|
351 |
da17d77e
|
Ermal Lu?i
|
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
352 |
888e7a27
|
Scott Ullrich
|
// Reset configuration version to something low
|
353 |
|
|
// in order to force the config upgrade code to
|
354 |
|
|
// run through with all steps that are required.
|
355 |
|
|
$config['system']['version'] = "1.0";
|
356 |
798cb31a
|
Scott Ullrich
|
// Deal with descriptions longer than 63 characters
|
357 |
|
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
358 |
|
|
if(count($config['filter']['rule'][$i]['descr']) > 63)
|
359 |
|
|
$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
|
360 |
|
|
}
|
361 |
|
|
// Move interface from ipsec to enc0
|
362 |
|
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
363 |
|
|
if($config['filter']['rule'][$i]['interface'] == "ipsec")
|
364 |
|
|
$config['filter']['rule'][$i]['interface'] = "enc0";
|
365 |
|
|
}
|
366 |
|
|
// Convert icmp types
|
367 |
|
|
// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
|
368 |
|
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
369 |
|
|
if($config["filter"]["rule"][$i]['icmptype']) {
|
370 |
|
|
switch($config["filter"]["rule"][$i]['icmptype']) {
|
371 |
|
|
case "echo":
|
372 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
|
373 |
|
|
break;
|
374 |
|
|
case "unreach":
|
375 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "unreach";
|
376 |
|
|
break;
|
377 |
|
|
case "echorep":
|
378 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "echorep";
|
379 |
|
|
break;
|
380 |
|
|
case "squench":
|
381 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "squench";
|
382 |
|
|
break;
|
383 |
|
|
case "redir":
|
384 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "redir";
|
385 |
|
|
break;
|
386 |
|
|
case "timex":
|
387 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "timex";
|
388 |
|
|
break;
|
389 |
|
|
case "paramprob":
|
390 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
|
391 |
|
|
break;
|
392 |
|
|
case "timest":
|
393 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "timereq";
|
394 |
|
|
break;
|
395 |
|
|
case "timestrep":
|
396 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "timerep";
|
397 |
|
|
break;
|
398 |
|
|
case "inforeq":
|
399 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
|
400 |
|
|
break;
|
401 |
|
|
case "inforep":
|
402 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "inforep";
|
403 |
|
|
break;
|
404 |
|
|
case "maskreq":
|
405 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
|
406 |
|
|
break;
|
407 |
|
|
case "maskrep":
|
408 |
|
|
$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
|
409 |
|
|
break;
|
410 |
|
|
}
|
411 |
|
|
}
|
412 |
dec5cb85
|
Scott Ullrich
|
}
|
413 |
|
|
$config['diag']['ipv6nat'] = true;
|
414 |
8ff5ffcc
|
Matthew Grooms
|
write_config();
|
415 |
3420028c
|
Scott Ullrich
|
add_base_packages_menu_items();
|
416 |
d442e4e2
|
Scott Ullrich
|
convert_config();
|
417 |
8ff5ffcc
|
Matthew Grooms
|
conf_mount_ro();
|
418 |
343bb325
|
sullrich
|
$savemsg = "The m0n0wall configuration has been restored and upgraded to pfSense.";
|
419 |
da17d77e
|
Ermal Lu?i
|
mark_subsystem_dirty("restore");
|
420 |
8ff5ffcc
|
Matthew Grooms
|
}
|
421 |
|
|
if(isset($config['captiveportal']['enable'])) {
|
422 |
|
|
/* for some reason ipfw doesn't init correctly except on bootup sequence */
|
423 |
da17d77e
|
Ermal Lu?i
|
mark_subsystem_dirty("restore");
|
424 |
8ff5ffcc
|
Matthew Grooms
|
}
|
425 |
|
|
setup_serial_port();
|
426 |
|
|
if(is_interface_mismatch() == true) {
|
427 |
|
|
touch("/var/run/interface_mismatch_reboot_needed");
|
428 |
da17d77e
|
Ermal Lu?i
|
clear_subsystem_dirty("restore");
|
429 |
f5a57bb0
|
Scott Ullrich
|
convert_config();
|
430 |
8ff5ffcc
|
Matthew Grooms
|
header("Location: interfaces_assign.php");
|
431 |
bafaf123
|
Scott Ullrich
|
exit;
|
432 |
8ff5ffcc
|
Matthew Grooms
|
}
|
433 |
|
|
} else {
|
434 |
|
|
$input_errors[] = "The configuration could not be restored.";
|
435 |
db3996df
|
Scott Ullrich
|
}
|
436 |
9c72b993
|
Scott Ullrich
|
}
|
437 |
181462b5
|
Scott Ullrich
|
}
|
438 |
8ff5ffcc
|
Matthew Grooms
|
} else {
|
439 |
|
|
$input_errors[] = "The configuration could not be restored (file upload error).";
|
440 |
db3996df
|
Scott Ullrich
|
}
|
441 |
5b237745
|
Scott Ullrich
|
}
|
442 |
8ff5ffcc
|
Matthew Grooms
|
}
|
443 |
|
|
|
444 |
|
|
if ($mode == "reinstallpackages") {
|
445 |
|
|
|
446 |
8ccc8f1a
|
Scott Ullrich
|
header("Location: pkg_mgr_install.php?mode=reinstallall");
|
447 |
|
|
exit;
|
448 |
7cf03119
|
Bill Marquette
|
} else if ($mode == "restore_ver") {
|
449 |
|
|
$input_errors[] = "XXX - this feature may hose your config (do NOT backrev configs!) - billm";
|
450 |
|
|
if ($ver2restore <> "") {
|
451 |
|
|
$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
|
452 |
343bb325
|
sullrich
|
if (config_install($conf_file) == 0) {
|
453 |
|
|
mark_subsystem_dirty("restore");
|
454 |
7cf03119
|
Bill Marquette
|
} else {
|
455 |
343bb325
|
sullrich
|
$input_errors[] = "The configuration could not be restored.";
|
456 |
7cf03119
|
Bill Marquette
|
}
|
457 |
343bb325
|
sullrich
|
} else {
|
458 |
|
|
$input_errors[] = "No version selected.";
|
459 |
|
|
}
|
460 |
5b237745
|
Scott Ullrich
|
}
|
461 |
|
|
}
|
462 |
|
|
}
|
463 |
6a1e6651
|
Bill Marquette
|
|
464 |
02e1170d
|
Scott Ullrich
|
$id = rand() . '.' . time();
|
465 |
|
|
|
466 |
|
|
$mth = ini_get('upload_progress_meter.store_method');
|
467 |
|
|
$dir = ini_get('upload_progress_meter.file.filename_template');
|
468 |
|
|
|
469 |
d88c6a9f
|
Scott Ullrich
|
$pgtitle = array("Diagnostics","Backup/restore");
|
470 |
b63695db
|
Scott Ullrich
|
include("head.inc");
|
471 |
|
|
|
472 |
5b237745
|
Scott Ullrich
|
?>
|
473 |
|
|
|
474 |
|
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
475 |
|
|
<?php include("fbegin.inc"); ?>
|
476 |
8ff5ffcc
|
Matthew Grooms
|
<script language="JavaScript">
|
477 |
|
|
<!--
|
478 |
|
|
|
479 |
|
|
function encrypt_change() {
|
480 |
|
|
|
481 |
|
|
if (!document.iform.encrypt.checked)
|
482 |
|
|
document.getElementById("encrypt_opts").style.display="none";
|
483 |
|
|
else
|
484 |
|
|
document.getElementById("encrypt_opts").style.display="";
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
function decrypt_change() {
|
488 |
|
|
|
489 |
|
|
if (!document.iform.decrypt.checked)
|
490 |
|
|
document.getElementById("decrypt_opts").style.display="none";
|
491 |
|
|
else
|
492 |
|
|
document.getElementById("decrypt_opts").style.display="";
|
493 |
|
|
}
|
494 |
|
|
|
495 |
a1003d57
|
Ermal Lu?i
|
function backuparea_change(obj) {
|
496 |
|
|
|
497 |
|
|
if (obj.value == "")
|
498 |
|
|
document.getElementById("dotnotbackuprrd").checked = false;
|
499 |
|
|
else
|
500 |
|
|
document.getElementById("dotnotbackuprrd").checked = true;
|
501 |
|
|
}
|
502 |
8ff5ffcc
|
Matthew Grooms
|
//-->
|
503 |
|
|
</script>
|
504 |
344c68b2
|
sullrich
|
|
505 |
9e2a4fce
|
Erik Kristensen
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
506 |
|
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
507 |
da17d77e
|
Ermal Lu?i
|
<?php if (is_subsystem_dirty('restore')): ?><p>
|
508 |
344c68b2
|
sullrich
|
<form action="reboot.php" method="post">
|
509 |
|
|
<input name="Submit" type="hidden" value=" Yes ">
|
510 |
7a7f3af1
|
sullrich
|
<?php print_info_box("The firewall configuration has been changed.<br/>The firewall is now rebooting.");?><br>
|
511 |
344c68b2
|
sullrich
|
</form>
|
512 |
da17d77e
|
Ermal Lu?i
|
<?php endif; ?>
|
513 |
344c68b2
|
sullrich
|
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
|
514 |
9e2a4fce
|
Erik Kristensen
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
515 |
|
|
<tr>
|
516 |
|
|
<td>
|
517 |
12af52d9
|
Scott Ullrich
|
<?php
|
518 |
9e2a4fce
|
Erik Kristensen
|
$tab_array = array();
|
519 |
2dfdb028
|
Chris Buechler
|
$tab_array[0] = array("Config History", false, "diag_confbak.php");
|
520 |
|
|
$tab_array[1] = array("Backup/Restore", true, "diag_backup.php");
|
521 |
9e2a4fce
|
Erik Kristensen
|
display_top_tabs($tab_array);
|
522 |
645ec835
|
Scott Ullrich
|
?>
|
523 |
9e2a4fce
|
Erik Kristensen
|
</td>
|
524 |
|
|
</tr>
|
525 |
|
|
<tr>
|
526 |
|
|
<td>
|
527 |
|
|
<div id="mainarea">
|
528 |
|
|
<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
|
529 |
|
|
<tr>
|
530 |
|
|
<td colspan="2" class="listtopic">Backup configuration</td>
|
531 |
|
|
</tr>
|
532 |
|
|
<tr>
|
533 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
534 |
|
|
<td width="78%" class="vtable">
|
535 |
3244aa21
|
Scott Ullrich
|
<p>Click this button to download the system configuration in XML format.<br /><br /> Backup area: <?php spit_out_select_items("backuparea", false); ?></p>
|
536 |
8ff5ffcc
|
Matthew Grooms
|
<table>
|
537 |
|
|
<tr>
|
538 |
|
|
<td>
|
539 |
|
|
<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">
|
540 |
|
|
</td>
|
541 |
|
|
<td>
|
542 |
|
|
<span class="vexpl">Do not backup package information.</span>
|
543 |
|
|
</td>
|
544 |
|
|
</tr>
|
545 |
|
|
</table>
|
546 |
|
|
<table>
|
547 |
|
|
<tr>
|
548 |
|
|
<td>
|
549 |
|
|
<input name="encrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="encrypt_change()">
|
550 |
|
|
</td>
|
551 |
|
|
<td>
|
552 |
|
|
<span class="vexpl">Encrypt this configuration file.</span>
|
553 |
|
|
</td>
|
554 |
|
|
</tr>
|
555 |
1390b049
|
Scott Ullrich
|
<tr>
|
556 |
|
|
<td>
|
557 |
|
|
<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd">
|
558 |
|
|
</td>
|
559 |
|
|
<td>
|
560 |
|
|
<span class="vexpl">Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)</span>
|
561 |
|
|
</td>
|
562 |
|
|
</tr>
|
563 |
8ff5ffcc
|
Matthew Grooms
|
</table>
|
564 |
|
|
<table id="encrypt_opts">
|
565 |
|
|
<tr>
|
566 |
|
|
<td>
|
567 |
|
|
<span class="vexpl">Password :</span>
|
568 |
|
|
</td>
|
569 |
|
|
<td>
|
570 |
|
|
<input name="encrypt_password" type="password" class="formfld pwd" size="20" value="" />
|
571 |
|
|
</td>
|
572 |
|
|
</tr>
|
573 |
|
|
<tr>
|
574 |
|
|
<td>
|
575 |
|
|
<span class="vexpl">confirm :</span>
|
576 |
|
|
</td>
|
577 |
|
|
<td>
|
578 |
|
|
<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
|
579 |
|
|
</td>
|
580 |
|
|
</tr>
|
581 |
|
|
</table>
|
582 |
9e2a4fce
|
Erik Kristensen
|
<p><input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration"></p>
|
583 |
|
|
</td>
|
584 |
|
|
</tr>
|
585 |
|
|
<tr>
|
586 |
|
|
<td colspan="2" class="list" height="12"> </td>
|
587 |
5b237745
|
Scott Ullrich
|
</tr>
|
588 |
8ccc8f1a
|
Scott Ullrich
|
<tr>
|
589 |
9e2a4fce
|
Erik Kristensen
|
<td colspan="2" class="listtopic">Restore configuration</td>
|
590 |
|
|
</tr>
|
591 |
|
|
<tr>
|
592 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
593 |
|
|
<td width="78%" class="vtable">
|
594 |
3244aa21
|
Scott Ullrich
|
Open a <?=$g['[product_name']?> configuration XML file and click the button below to restore the configuration. <br /><br /> Restore area: <?php spit_out_select_items("restorearea", true); ?>
|
595 |
b5c78501
|
Seth Mos
|
<p><input name="conffile" type="file" class="formfld unknown" id="conffile" size="40"></p>
|
596 |
8ff5ffcc
|
Matthew Grooms
|
<table>
|
597 |
|
|
<tr>
|
598 |
|
|
<td>
|
599 |
|
|
<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="decrypt_change()">
|
600 |
|
|
</td>
|
601 |
|
|
<td>
|
602 |
|
|
<span class="vexpl">Configuration file is encrypted.</span>
|
603 |
|
|
</td>
|
604 |
|
|
</tr>
|
605 |
|
|
</table>
|
606 |
|
|
<table id="decrypt_opts">
|
607 |
|
|
<tr>
|
608 |
|
|
<td>
|
609 |
|
|
<span class="vexpl">Password :</span>
|
610 |
|
|
</td>
|
611 |
|
|
<td>
|
612 |
|
|
<input name="decrypt_password" type="password" class="formfld pwd" size="20" value="" />
|
613 |
|
|
</td>
|
614 |
|
|
</tr>
|
615 |
|
|
<tr>
|
616 |
|
|
<td>
|
617 |
|
|
<span class="vexpl">confirm :</span>
|
618 |
|
|
</td>
|
619 |
|
|
<td>
|
620 |
|
|
<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
|
621 |
|
|
</td>
|
622 |
|
|
</tr>
|
623 |
|
|
</table>
|
624 |
9e2a4fce
|
Erik Kristensen
|
<p><input name="Submit" type="submit" class="formbtn" id="restore" value="Restore configuration"></p>
|
625 |
7a7f3af1
|
sullrich
|
<p><strong><span class="red">Note:</span></strong><br />The firewall will reboot after restoring the configuration.<br /></p>
|
626 |
9e2a4fce
|
Erik Kristensen
|
</td>
|
627 |
|
|
</tr>
|
628 |
|
|
<?php if($config['installedpackages']['package'] != "") { ?>
|
629 |
|
|
<tr>
|
630 |
|
|
<td colspan="2" class="list" height="12"> </td>
|
631 |
|
|
</tr>
|
632 |
|
|
<tr>
|
633 |
|
|
<td colspan="2" class="listtopic">Reinstall packages</td>
|
634 |
|
|
</tr>
|
635 |
|
|
<tr>
|
636 |
|
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
637 |
|
|
<td width="78%" class="vtable">
|
638 |
|
|
<p>Click this button to reinstall all system packages. This may take a while. <br /><br />
|
639 |
|
|
<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="Reinstall packages">
|
640 |
|
|
</td>
|
641 |
|
|
</tr>
|
642 |
|
|
<?php } ?>
|
643 |
|
|
</table>
|
644 |
|
|
</div>
|
645 |
b24bf37b
|
Colin Smith
|
</td>
|
646 |
9e2a4fce
|
Erik Kristensen
|
</tr>
|
647 |
|
|
</table>
|
648 |
|
|
</form>
|
649 |
|
|
|
650 |
8ff5ffcc
|
Matthew Grooms
|
<script language="JavaScript">
|
651 |
|
|
<!--
|
652 |
|
|
encrypt_change();
|
653 |
|
|
decrypt_change();
|
654 |
|
|
//-->
|
655 |
|
|
</script>
|
656 |
|
|
|
657 |
5b237745
|
Scott Ullrich
|
<?php include("fend.inc"); ?>
|
658 |
|
|
</body>
|
659 |
38d48421
|
Colin Smith
|
</html>
|
660 |
7a7f3af1
|
sullrich
|
<?php
|
661 |
|
|
|
662 |
|
|
if (is_subsystem_dirty('restore'))
|
663 |
|
|
exec("/etc/rc.reboot");
|
664 |
|
|
|
665 |
a1003d57
|
Ermal Lu?i
|
?>
|