1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
diag_backup.php
|
5
|
Copyright (C) 2004-2009 Scott Ullrich
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
All rights reserved.
|
8
|
|
9
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
10
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
11
|
All rights reserved.
|
12
|
|
13
|
Redistribution and use in source and binary forms, with or without
|
14
|
modification, are permitted provided that the following conditions are met:
|
15
|
|
16
|
1. Redistributions of source code must retain the above copyright notice,
|
17
|
this list of conditions and the following disclaimer.
|
18
|
|
19
|
2. Redistributions in binary form must reproduce the above copyright
|
20
|
notice, this list of conditions and the following disclaimer in the
|
21
|
documentation and/or other materials provided with the distribution.
|
22
|
|
23
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
24
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
25
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
26
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
27
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
POSSIBILITY OF SUCH DAMAGE.
|
33
|
*/
|
34
|
|
35
|
/*
|
36
|
pfSense_BUILDER_BINARIES: /sbin/shutdown
|
37
|
pfSense_MODULE: backup
|
38
|
*/
|
39
|
|
40
|
##|+PRIV
|
41
|
##|*IDENT=page-diagnostics-backup/restore
|
42
|
##|*NAME=Diagnostics: Backup/restore page
|
43
|
##|*DESCR=Allow access to the 'Diagnostics: Backup/restore' page.
|
44
|
##|*MATCH=diag_backup.php*
|
45
|
##|-PRIV
|
46
|
|
47
|
/* Allow additional execution time 0 = no limit. */
|
48
|
ini_set('max_execution_time', '0');
|
49
|
ini_set('max_input_time', '0');
|
50
|
|
51
|
/* omit no-cache headers because it confuses IE with file downloads */
|
52
|
$omit_nocacheheaders = true;
|
53
|
$nocsrf = true;
|
54
|
require("guiconfig.inc");
|
55
|
require_once("functions.inc");
|
56
|
require_once("filter.inc");
|
57
|
require_once("shaper.inc");
|
58
|
|
59
|
$rrddbpath = "/var/db/rrd";
|
60
|
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
|
61
|
|
62
|
function rrd_data_xml() {
|
63
|
global $rrddbpath;
|
64
|
global $rrdtool;
|
65
|
|
66
|
$result = "\t<rrddata>\n";
|
67
|
$rrd_files = glob("{$rrddbpath}/*.rrd");
|
68
|
$xml_files = array();
|
69
|
foreach ($rrd_files as $rrd_file) {
|
70
|
$basename = basename($rrd_file);
|
71
|
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
|
72
|
exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
|
73
|
$xml_data = file_get_contents($xml_file);
|
74
|
unlink($xml_file);
|
75
|
if ($xml_data !== false) {
|
76
|
$result .= "\t\t<rrddatafile>\n";
|
77
|
$result .= "\t\t\t<filename>{$basename}</filename>\n";
|
78
|
$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
|
79
|
$result .= "\t\t</rrddatafile>\n";
|
80
|
}
|
81
|
}
|
82
|
$result .= "\t</rrddata>\n";
|
83
|
return $result;
|
84
|
}
|
85
|
|
86
|
function restore_rrddata() {
|
87
|
global $config, $g, $rrdtool, $input_errors;
|
88
|
foreach($config['rrddata']['rrddatafile'] as $rrd) {
|
89
|
if ($rrd['xmldata']) {
|
90
|
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
|
91
|
$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
|
92
|
if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
|
93
|
log_error("Cannot write $xml_file");
|
94
|
continue;
|
95
|
}
|
96
|
$output = array();
|
97
|
$status = null;
|
98
|
exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
|
99
|
if ($status) {
|
100
|
log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
|
101
|
continue;
|
102
|
}
|
103
|
unlink($xml_file);
|
104
|
}
|
105
|
else if ($rrd['data']) {
|
106
|
$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
|
107
|
$rrd_fd = fopen($rrd_file, "w");
|
108
|
if (!$rrd_fd) {
|
109
|
log_error("Cannot write $rrd_file");
|
110
|
continue;
|
111
|
}
|
112
|
$data = base64_decode($rrd['data']);
|
113
|
/* Try to decompress the data. */
|
114
|
$dcomp = @gzinflate($data);
|
115
|
if ($dcomp) {
|
116
|
/* If the decompression worked, write the decompressed data */
|
117
|
if (fwrite($rrd_fd, $dcomp) === false) {
|
118
|
log_error("fwrite $rrd_file failed");
|
119
|
continue;
|
120
|
}
|
121
|
} else {
|
122
|
/* If the decompression failed, it wasn't compressed, so write raw data */
|
123
|
if (fwrite($rrd_fd, $data) === false) {
|
124
|
log_error("fwrite $rrd_file failed");
|
125
|
continue;
|
126
|
}
|
127
|
}
|
128
|
if (fclose($rrd_fd) === false) {
|
129
|
log_error("fclose $rrd_file failed");
|
130
|
continue;
|
131
|
}
|
132
|
}
|
133
|
}
|
134
|
}
|
135
|
|
136
|
function add_base_packages_menu_items() {
|
137
|
global $g, $config;
|
138
|
$base_packages = explode(",", $g['base_packages']);
|
139
|
$modified_config = false;
|
140
|
foreach($base_packages as $bp) {
|
141
|
$basepkg_path = "/usr/local/pkg/{$bp}";
|
142
|
$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
|
143
|
if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
|
144
|
$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
|
145
|
if($pkg_config['menu'] != "") {
|
146
|
if(is_array($pkg_config['menu'])) {
|
147
|
foreach($pkg_config['menu'] as $menu) {
|
148
|
if(is_array($config['installedpackages']['menu']))
|
149
|
foreach($config['installedpackages']['menu'] as $amenu)
|
150
|
if($amenu['name'] == $menu['name'])
|
151
|
continue;
|
152
|
$config['installedpackages']['menu'][] = $menu;
|
153
|
$modified_config = true;
|
154
|
}
|
155
|
}
|
156
|
$static_output .= "done.\n";
|
157
|
update_output_window($static_output);
|
158
|
}
|
159
|
}
|
160
|
}
|
161
|
if($modified_config) {
|
162
|
write_config(gettext("Restored base_package menus after configuration restore."));
|
163
|
$config = parse_config(true);
|
164
|
}
|
165
|
}
|
166
|
|
167
|
function remove_bad_chars($string) {
|
168
|
return preg_replace('/[^a-z_0-9]/i','',$string);
|
169
|
}
|
170
|
|
171
|
function check_and_returnif_section_exists($section) {
|
172
|
global $config;
|
173
|
if(is_array($config[$section]))
|
174
|
return true;
|
175
|
return false;
|
176
|
}
|
177
|
|
178
|
function spit_out_select_items($name, $showall) {
|
179
|
global $config;
|
180
|
|
181
|
$areas = array(
|
182
|
"aliases" => gettext("Aliases"),
|
183
|
"captiveportal" => gettext("Captive Portal"),
|
184
|
"voucher" => gettext("Captive Portal Vouchers"),
|
185
|
"dnsmasq" => gettext("DNS Forwarder"),
|
186
|
"dhcpd" => gettext("DHCP Server"),
|
187
|
"dhcpdv6" => gettext("DHCPv6 Server"),
|
188
|
"filter" => gettext("Firewall Rules"),
|
189
|
"interfaces" => gettext("Interfaces"),
|
190
|
"ipsec" => gettext("IPSEC"),
|
191
|
"nat" => gettext("NAT"),
|
192
|
"openvpn" => gettext("OpenVPN"),
|
193
|
"installedpackages" => gettext("Package Manager"),
|
194
|
"pptpd" => gettext("PPTP Server"),
|
195
|
"rrddata" => gettext("RRD Data"),
|
196
|
"cron" => gettext("Scheduled Tasks"),
|
197
|
"syslog" => gettext("Syslog"),
|
198
|
"system" => gettext("System"),
|
199
|
"staticroutes" => gettext("Static routes"),
|
200
|
"sysctl" => gettext("System tunables"),
|
201
|
"snmpd" => gettext("SNMP Server"),
|
202
|
"shaper" => gettext("Traffic Shaper"),
|
203
|
"vlans" => gettext("VLANS"),
|
204
|
"wol" => gettext("Wake on LAN")
|
205
|
);
|
206
|
|
207
|
$select = "<select name=\"{$name}\" id=\"{$name}\">";
|
208
|
$select .= "<option value=\"\">" . gettext("ALL") . "</option>";
|
209
|
|
210
|
if($showall == true)
|
211
|
foreach($areas as $area => $areaname)
|
212
|
$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
|
213
|
else
|
214
|
foreach($areas as $area => $areaname)
|
215
|
if($area === "rrddata" || check_and_returnif_section_exists($area) == true)
|
216
|
$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
|
217
|
|
218
|
$select .= "</select>\n";
|
219
|
|
220
|
echo $select;
|
221
|
}
|
222
|
|
223
|
if ($_POST['apply']) {
|
224
|
ob_flush();
|
225
|
flush();
|
226
|
conf_mount_rw();
|
227
|
clear_subsystem_dirty("restore");
|
228
|
conf_mount_ro();
|
229
|
exit;
|
230
|
}
|
231
|
|
232
|
if ($_POST) {
|
233
|
unset($input_errors);
|
234
|
if (stristr($_POST['Submit'], gettext("Restore configuration")))
|
235
|
$mode = "restore";
|
236
|
else if (stristr($_POST['Submit'], gettext("Reinstall")))
|
237
|
$mode = "reinstallpackages";
|
238
|
else if (stristr($_POST['Submit'], gettext("Clear Package Lock")))
|
239
|
$mode = "clearpackagelock";
|
240
|
else if (stristr($_POST['Submit'], gettext("Download")))
|
241
|
$mode = "download";
|
242
|
else if (stristr($_POST['Submit'], gettext("Restore version")))
|
243
|
$mode = "restore_ver";
|
244
|
|
245
|
if ($_POST["nopackages"] <> "")
|
246
|
$options = "nopackages";
|
247
|
|
248
|
if ($_POST["ver"] <> "")
|
249
|
$ver2restore = $_POST["ver"];
|
250
|
|
251
|
if ($mode) {
|
252
|
|
253
|
if ($mode == "download") {
|
254
|
|
255
|
if ($_POST['encrypt']) {
|
256
|
if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
|
257
|
$input_errors[] = gettext("You must supply and confirm the password for encryption.");
|
258
|
if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
|
259
|
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
|
260
|
}
|
261
|
|
262
|
if (!$input_errors) {
|
263
|
|
264
|
//$lockbckp = lock('config');
|
265
|
|
266
|
$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
|
267
|
$name = "config-{$host}-".date("YmdHis").".xml";
|
268
|
$data = "";
|
269
|
|
270
|
if($options == "nopackages") {
|
271
|
if(!$_POST['backuparea']) {
|
272
|
/* backup entire configuration */
|
273
|
$data = file_get_contents("{$g['conf_path']}/config.xml");
|
274
|
} else {
|
275
|
/* backup specific area of configuration */
|
276
|
$data = backup_config_section($_POST['backuparea']);
|
277
|
$name = "{$_POST['backuparea']}-{$name}";
|
278
|
}
|
279
|
$sfn = "{$g['tmp_path']}/config.xml.nopkg";
|
280
|
file_put_contents($sfn, $data);
|
281
|
exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
|
282
|
$data = file_get_contents($sfn . "-new");
|
283
|
} else {
|
284
|
if(!$_POST['backuparea']) {
|
285
|
/* backup entire configuration */
|
286
|
$data = file_get_contents("{$g['conf_path']}/config.xml");
|
287
|
} else if ($_POST['backuparea'] === "rrddata") {
|
288
|
$data = rrd_data_xml();
|
289
|
$name = "{$_POST['backuparea']}-{$name}";
|
290
|
} else {
|
291
|
/* backup specific area of configuration */
|
292
|
$data = backup_config_section($_POST['backuparea']);
|
293
|
$name = "{$_POST['backuparea']}-{$name}";
|
294
|
}
|
295
|
}
|
296
|
|
297
|
//unlock($lockbckp);
|
298
|
|
299
|
/*
|
300
|
* Backup RRD Data
|
301
|
*/
|
302
|
if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
|
303
|
$rrd_data_xml = rrd_data_xml();
|
304
|
$closing_tag = "</" . $g['xml_rootobj'] . ">";
|
305
|
$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
|
306
|
}
|
307
|
|
308
|
if ($_POST['encrypt']) {
|
309
|
$data = encrypt_data($data, $_POST['encrypt_password']);
|
310
|
tagfile_reformat($data, $data, "config.xml");
|
311
|
}
|
312
|
|
313
|
$size = strlen($data);
|
314
|
header("Content-Type: application/octet-stream");
|
315
|
header("Content-Disposition: attachment; filename={$name}");
|
316
|
header("Content-Length: $size");
|
317
|
if (isset($_SERVER['HTTPS'])) {
|
318
|
header('Pragma: ');
|
319
|
header('Cache-Control: ');
|
320
|
} else {
|
321
|
header("Pragma: private");
|
322
|
header("Cache-Control: private, must-revalidate");
|
323
|
}
|
324
|
echo $data;
|
325
|
|
326
|
exit;
|
327
|
}
|
328
|
}
|
329
|
|
330
|
if ($mode == "restore") {
|
331
|
|
332
|
if ($_POST['decrypt']) {
|
333
|
if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
|
334
|
$input_errors[] = gettext("You must supply and confirm the password for decryption.");
|
335
|
if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
|
336
|
$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
|
337
|
}
|
338
|
|
339
|
if (!$input_errors) {
|
340
|
|
341
|
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
|
342
|
|
343
|
/* read the file contents */
|
344
|
$data = file_get_contents($_FILES['conffile']['tmp_name']);
|
345
|
if(!$data) {
|
346
|
log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
|
347
|
return 1;
|
348
|
}
|
349
|
|
350
|
if ($_POST['decrypt']) {
|
351
|
if (!tagfile_deformat($data, $data, "config.xml")) {
|
352
|
$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
|
353
|
return 1;
|
354
|
}
|
355
|
$data = decrypt_data($data, $_POST['decrypt_password']);
|
356
|
}
|
357
|
|
358
|
if(stristr($data, "<m0n0wall>")) {
|
359
|
log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
|
360
|
/* m0n0wall was found in config. convert it. */
|
361
|
$data = str_replace("m0n0wall", "pfsense", $data);
|
362
|
$m0n0wall_upgrade = true;
|
363
|
}
|
364
|
if($_POST['restorearea']) {
|
365
|
/* restore a specific area of the configuration */
|
366
|
if(!stristr($data, "<" . $_POST['restorearea'] . ">")) {
|
367
|
$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
|
368
|
} else {
|
369
|
if (!restore_config_section($_POST['restorearea'], $data)) {
|
370
|
$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
|
371
|
} else {
|
372
|
if ($config['rrddata']) {
|
373
|
restore_rrddata();
|
374
|
unset($config['rrddata']);
|
375
|
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
376
|
write_config();
|
377
|
add_base_packages_menu_items();
|
378
|
convert_config();
|
379
|
conf_mount_ro();
|
380
|
}
|
381
|
filter_configure();
|
382
|
$savemsg = gettext("The configuration area has been restored. You may need to reboot the firewall.");
|
383
|
}
|
384
|
}
|
385
|
} else {
|
386
|
if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
|
387
|
$input_errors[] = sprintf(gettext("You have selected to restore the full configuration but we could not locate a %s tag."), $g['xml_rootobj']);
|
388
|
} else {
|
389
|
/* restore the entire configuration */
|
390
|
file_put_contents($_FILES['conffile']['tmp_name'], $data);
|
391
|
if (config_install($_FILES['conffile']['tmp_name']) == 0) {
|
392
|
/* this will be picked up by /index.php */
|
393
|
conf_mount_rw();
|
394
|
mark_subsystem_dirty("restore");
|
395
|
touch("/conf/needs_package_sync");
|
396
|
/* remove cache, we will force a config reboot */
|
397
|
if(file_exists("{$g['tmp_path']}/config.cache"))
|
398
|
unlink("{$g['tmp_path']}/config.cache");
|
399
|
$config = parse_config(true);
|
400
|
if (file_exists("/boot/loader.conf")) {
|
401
|
$loaderconf = file_get_contents("/boot/loader.conf");
|
402
|
if (strpos($loaderconf, "console=\"comconsole")) {
|
403
|
$config['system']['enableserial'] = true;
|
404
|
write_config("Restore serial console enabling in configuration.");
|
405
|
}
|
406
|
unset($loaderconf);
|
407
|
}
|
408
|
/* extract out rrd items, unset from $config when done */
|
409
|
if($config['rrddata']) {
|
410
|
restore_rrddata();
|
411
|
unset($config['rrddata']);
|
412
|
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
413
|
write_config();
|
414
|
add_base_packages_menu_items();
|
415
|
convert_config();
|
416
|
conf_mount_ro();
|
417
|
}
|
418
|
if($m0n0wall_upgrade == true) {
|
419
|
if($config['system']['gateway'] <> "")
|
420
|
$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
|
421
|
unset($config['shaper']);
|
422
|
/* optional if list */
|
423
|
$ifdescrs = get_configured_interface_list(true, true);
|
424
|
/* remove special characters from interface descriptions */
|
425
|
if(is_array($ifdescrs))
|
426
|
foreach($ifdescrs as $iface)
|
427
|
$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
|
428
|
/* check for interface names with an alias */
|
429
|
if(is_array($ifdescrs)) {
|
430
|
foreach($ifdescrs as $iface) {
|
431
|
if(is_alias($config['interfaces'][$iface]['descr'])) {
|
432
|
// Firewall rules
|
433
|
$origname = $config['interfaces'][$iface]['descr'];
|
434
|
$newname = $config['interfaces'][$iface]['descr'] . "Alias";
|
435
|
update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
|
436
|
update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
|
437
|
// NAT Rules
|
438
|
update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
|
439
|
update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
|
440
|
update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
|
441
|
// Alias in an alias
|
442
|
update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
|
443
|
}
|
444
|
}
|
445
|
}
|
446
|
unlink_if_exists("{$g['tmp_path']}/config.cache");
|
447
|
// Reset configuration version to something low
|
448
|
// in order to force the config upgrade code to
|
449
|
// run through with all steps that are required.
|
450
|
$config['system']['version'] = "1.0";
|
451
|
// Deal with descriptions longer than 63 characters
|
452
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
453
|
if(count($config['filter']['rule'][$i]['descr']) > 63)
|
454
|
$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
|
455
|
}
|
456
|
// Move interface from ipsec to enc0
|
457
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
458
|
if($config['filter']['rule'][$i]['interface'] == "ipsec")
|
459
|
$config['filter']['rule'][$i]['interface'] = "enc0";
|
460
|
}
|
461
|
// Convert icmp types
|
462
|
// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
|
463
|
for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
|
464
|
if($config["filter"]["rule"][$i]['icmptype']) {
|
465
|
switch($config["filter"]["rule"][$i]['icmptype']) {
|
466
|
case "echo":
|
467
|
$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
|
468
|
break;
|
469
|
case "unreach":
|
470
|
$config["filter"]["rule"][$i]['icmptype'] = "unreach";
|
471
|
break;
|
472
|
case "echorep":
|
473
|
$config["filter"]["rule"][$i]['icmptype'] = "echorep";
|
474
|
break;
|
475
|
case "squench":
|
476
|
$config["filter"]["rule"][$i]['icmptype'] = "squench";
|
477
|
break;
|
478
|
case "redir":
|
479
|
$config["filter"]["rule"][$i]['icmptype'] = "redir";
|
480
|
break;
|
481
|
case "timex":
|
482
|
$config["filter"]["rule"][$i]['icmptype'] = "timex";
|
483
|
break;
|
484
|
case "paramprob":
|
485
|
$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
|
486
|
break;
|
487
|
case "timest":
|
488
|
$config["filter"]["rule"][$i]['icmptype'] = "timereq";
|
489
|
break;
|
490
|
case "timestrep":
|
491
|
$config["filter"]["rule"][$i]['icmptype'] = "timerep";
|
492
|
break;
|
493
|
case "inforeq":
|
494
|
$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
|
495
|
break;
|
496
|
case "inforep":
|
497
|
$config["filter"]["rule"][$i]['icmptype'] = "inforep";
|
498
|
break;
|
499
|
case "maskreq":
|
500
|
$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
|
501
|
break;
|
502
|
case "maskrep":
|
503
|
$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
|
504
|
break;
|
505
|
}
|
506
|
}
|
507
|
}
|
508
|
$config['diag']['ipv6nat'] = true;
|
509
|
write_config();
|
510
|
add_base_packages_menu_items();
|
511
|
convert_config();
|
512
|
conf_mount_ro();
|
513
|
$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
|
514
|
mark_subsystem_dirty("restore");
|
515
|
}
|
516
|
if(is_array($config['captiveportal'])) {
|
517
|
foreach($config['captiveportal'] as $cp) {
|
518
|
if (isset($cp['enable'])) {
|
519
|
/* for some reason ipfw doesn't init correctly except on bootup sequence */
|
520
|
mark_subsystem_dirty("restore");
|
521
|
break;
|
522
|
}
|
523
|
}
|
524
|
}
|
525
|
setup_serial_port();
|
526
|
if(is_interface_mismatch() == true) {
|
527
|
touch("/var/run/interface_mismatch_reboot_needed");
|
528
|
clear_subsystem_dirty("restore");
|
529
|
convert_config();
|
530
|
header("Location: interfaces_assign.php");
|
531
|
exit;
|
532
|
}
|
533
|
if (is_interface_vlan_mismatch() == true) {
|
534
|
touch("/var/run/interface_mismatch_reboot_needed");
|
535
|
clear_subsystem_dirty("restore");
|
536
|
convert_config();
|
537
|
header("Location: interfaces_assign.php");
|
538
|
exit;
|
539
|
}
|
540
|
} else {
|
541
|
$input_errors[] = gettext("The configuration could not be restored.");
|
542
|
}
|
543
|
}
|
544
|
}
|
545
|
} else {
|
546
|
$input_errors[] = gettext("The configuration could not be restored (file upload error).");
|
547
|
}
|
548
|
}
|
549
|
}
|
550
|
|
551
|
if ($mode == "reinstallpackages") {
|
552
|
|
553
|
header("Location: pkg_mgr_install.php?mode=reinstallall");
|
554
|
exit;
|
555
|
} else if ($mode == "clearpackagelock") {
|
556
|
clear_subsystem_dirty('packagelock');
|
557
|
$savemsg = "Package Lock Cleared";
|
558
|
} else if ($mode == "restore_ver") {
|
559
|
$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
|
560
|
if ($ver2restore <> "") {
|
561
|
$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
|
562
|
if (config_install($conf_file) == 0) {
|
563
|
mark_subsystem_dirty("restore");
|
564
|
} else {
|
565
|
$input_errors[] = gettext("The configuration could not be restored.");
|
566
|
}
|
567
|
} else {
|
568
|
$input_errors[] = gettext("No version selected.");
|
569
|
}
|
570
|
}
|
571
|
}
|
572
|
}
|
573
|
|
574
|
$id = rand() . '.' . time();
|
575
|
|
576
|
$mth = ini_get('upload_progress_meter.store_method');
|
577
|
$dir = ini_get('upload_progress_meter.file.filename_template');
|
578
|
|
579
|
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
|
580
|
include("head.inc");
|
581
|
|
582
|
?>
|
583
|
<?php if ($input_errors) print_input_errors($input_errors)?>
|
584
|
<?php if ($savemsg) print_info_box($savemsg)?>
|
585
|
<?php if (is_subsystem_dirty('restore')):?><br/>
|
586
|
<form action="reboot.php" method="post">
|
587
|
<input name="Submit" type="hidden" value="Yes" />
|
588
|
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting."))?><br />
|
589
|
</form>
|
590
|
<?php endif?>
|
591
|
<?php
|
592
|
$tab_array = array();
|
593
|
$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
|
594
|
$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
|
595
|
display_top_tabs($tab_array);
|
596
|
?>
|
597
|
<div id="container">
|
598
|
<form class="form-horizontal" action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
|
599
|
<h2><?=gettext("Backup configuration"); ?></h2>
|
600
|
<div class="form-group">
|
601
|
<label for="backuparea" class="col-sm-2 control-label"><?=gettext("Backup area"); ?></label>
|
602
|
<div class="col-sm-10">
|
603
|
<?php spit_out_select_items("backuparea", false)?>
|
604
|
</div>
|
605
|
</div>
|
606
|
|
607
|
<div class="form-group">
|
608
|
<label for="nopackages" class="col-sm-2 control-label"><?=gettext("Skip packages")?></label>
|
609
|
<div class="col-sm-10">
|
610
|
<input name="nopackages" type="checkbox" /> <?=gettext("Do not backup package information.")?>
|
611
|
</div>
|
612
|
</div>
|
613
|
|
614
|
<div class="form-group">
|
615
|
<label for="donotbackuprrd" class="col-sm-2 control-label"><?=gettext("Skip RRD data")?></label>
|
616
|
<div class="col-sm-10">
|
617
|
<input name="donotbackuprrd" type="checkbox" checked="checked" /> <?=gettext("Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)")?>
|
618
|
</div>
|
619
|
</div>
|
620
|
|
621
|
<div class="form-group">
|
622
|
<label for="encrypt" class="col-sm-2 control-label"><?=gettext("Encryption")?></label>
|
623
|
<div class="col-sm-10">
|
624
|
<input name="encrypt" type="checkbox" data-toggle="collapse" href="#encryptOptions" aria-expanded="false" aria-controls="encryptOptions" />
|
625
|
<?=gettext("Encrypt this configuration file.")?>
|
626
|
</div>
|
627
|
</div>
|
628
|
|
629
|
<div class="form-group collapse" id="encryptOptions">
|
630
|
<label for="donotbackuprrd" class="col-sm-2 control-label"><?=gettext("Password")?></label>
|
631
|
<div class="col-sm-10">
|
632
|
<input name="encrypt_password" type="password" class="form-control" placeholder="Password" /><br/>
|
633
|
<input name="encrypt_passconf" type="password" class="form-control" placeholder="Confirm password" />
|
634
|
</div>
|
635
|
</div>
|
636
|
|
637
|
<div class="form-group">
|
638
|
<div class="col-sm-offset-2 col-sm-10">
|
639
|
<input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Download configuration as XML")?>" />
|
640
|
</div>
|
641
|
</div>
|
642
|
</form>
|
643
|
|
644
|
<form class="form-horizontal" action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
|
645
|
<h2><?=gettext("Restore configuration"); ?></h2>
|
646
|
<?=gettext("Open a")?><?=$g['[product_name']?><?=gettext("configuration XML file and click the button below to restore the configuration.")?>
|
647
|
|
648
|
<div class="form-group">
|
649
|
<label for="restorearea" class="col-sm-2 control-label"><?=gettext("Restore area"); ?></label>
|
650
|
<div class="col-sm-10">
|
651
|
<?php spit_out_select_items("restorearea", false)?>
|
652
|
</div>
|
653
|
</div>
|
654
|
|
655
|
<div class="form-group">
|
656
|
<label for="conffile" class="col-sm-2 control-label"><?=gettext("Configuration file"); ?></label>
|
657
|
<div class="col-sm-10">
|
658
|
<input name="conffile" type="file" class="form-control" />
|
659
|
</div>
|
660
|
</div>
|
661
|
|
662
|
<div class="form-group">
|
663
|
<label for="encrypt" class="col-sm-2 control-label"><?=gettext("Encryption")?></label>
|
664
|
<div class="col-sm-10">
|
665
|
<input name="encrypt" type="checkbox" data-toggle="collapse" href="#decryptOptions" aria-expanded="false" aria-controls="decryptOptions" />
|
666
|
<?=gettext("Decrypt this configuration file.")?>
|
667
|
</div>
|
668
|
</div>
|
669
|
|
670
|
<div class="form-group collapse" id="decryptOptions">
|
671
|
<label for="decrypt_password" class="col-sm-2 control-label"><?=gettext("Password")?></label>
|
672
|
<div class="col-sm-10">
|
673
|
<input name="decrypt_password" type="password" class="form-control" placeholder="Password" /><br/>
|
674
|
<input name="decrypt_passconf" type="password" class="form-control" placeholder="Confirm password" />
|
675
|
</div>
|
676
|
</div>
|
677
|
|
678
|
<div class="form-group">
|
679
|
<div class="col-sm-offset-2 col-sm-10">
|
680
|
<input name="Submit" type="submit" class="btn btn-danger" value="<?=gettext("Restore configuration")?>" />
|
681
|
<p><?=gettext("Note:")?><br /><?=gettext("The firewall will reboot after restoring the configuration.")?></p>
|
682
|
</div>
|
683
|
</div>
|
684
|
</form>
|
685
|
|
686
|
<?php if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {?>
|
687
|
<form class="form-horizontal" action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
|
688
|
<h2><?=gettext("Package Functions")?></h2>
|
689
|
|
690
|
<?php if ($config['installedpackages']['package'] != ""): ?>
|
691
|
<div class="form-group">
|
692
|
<div class="col-sm-offset-2 col-sm-10">
|
693
|
<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="<?=gettext("Reinstall packages")?>" />
|
694
|
<p><?=gettext("Click this button to reinstall all system packages. This may take a while.")?><br /><br />
|
695
|
</div>
|
696
|
</div>
|
697
|
<?php endif; ?>
|
698
|
|
699
|
<?php if (is_subsystem_dirty("packagelock")): ?>
|
700
|
<div class="form-group">
|
701
|
<div class="col-sm-offset-2 col-sm-10">
|
702
|
<input name="Submit" type="submit" class="formbtn" id="clearpackagelock" value="<?=gettext("Clear Package Lock")?>" />
|
703
|
<p><?=gettext("Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.")?><br /><br />
|
704
|
</div>
|
705
|
</div>
|
706
|
<?php endif; ?>
|
707
|
</form>
|
708
|
<?php }?>
|
709
|
</div>
|
710
|
<?php include("foot.inc")?>
|
711
|
<?php
|
712
|
|
713
|
if (is_subsystem_dirty('restore'))
|
714
|
system_reboot();
|
715
|
?>
|