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