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