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