Project

General

Profile

Download (24.8 KB) Statistics
| Branch: | Tag: | Revision:
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
 * 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
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23
 *
24
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28
 *
29
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33
 *
34
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37
 *
38
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40
 *
41
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43
 *
44
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56
 */
57

    
58
##|+PRIV
59
##|*IDENT=page-diagnostics-backup-restore
60
##|*NAME=Diagnostics: Backup & Restore
61
##|*DESCR=Allow access to the 'Diagnostics: Backup & Restore' page.
62
##|*MATCH=diag_backup.php*
63
##|-PRIV
64

    
65
/* Allow additional execution time 0 = no limit. */
66
ini_set('max_execution_time', '0');
67
ini_set('max_input_time', '0');
68

    
69
/* omit no-cache headers because it confuses IE with file downloads */
70
$omit_nocacheheaders = true;
71
require_once("guiconfig.inc");
72
require_once("functions.inc");
73
require_once("filter.inc");
74
require_once("shaper.inc");
75

    
76
$rrddbpath = "/var/db/rrd";
77
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
78

    
79
function rrd_data_xml() {
80
	global $rrddbpath;
81
	global $rrdtool;
82

    
83
	$result = "\t<rrddata>\n";
84
	$rrd_files = glob("{$rrddbpath}/*.rrd");
85
	$xml_files = array();
86
	foreach ($rrd_files as $rrd_file) {
87
		$basename = basename($rrd_file);
88
		$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
89
		exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
90
		$xml_data = file_get_contents($xml_file);
91
		unlink($xml_file);
92
		if ($xml_data !== false) {
93
			$result .= "\t\t<rrddatafile>\n";
94
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
95
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
96
			$result .= "\t\t</rrddatafile>\n";
97
		}
98
	}
99
	$result .= "\t</rrddata>\n";
100
	return $result;
101
}
102

    
103
function restore_rrddata() {
104
	global $config, $g, $rrdtool, $input_errors;
105
	foreach ($config['rrddata']['rrddatafile'] as $rrd) {
106
		if ($rrd['xmldata']) {
107
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
108
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
109
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
110
				log_error(sprintf(gettext("Cannot write %s"), $xml_file));
111
				continue;
112
			}
113
			$output = array();
114
			$status = null;
115
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
116
			if ($status) {
117
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
118
				continue;
119
			}
120
			unlink($xml_file);
121
		} else if ($rrd['data']) {
122
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
123
			$rrd_fd = fopen($rrd_file, "w");
124
			if (!$rrd_fd) {
125
				log_error(sprintf(gettext("Cannot write %s"), $rrd_file));
126
				continue;
127
			}
128
			$data = base64_decode($rrd['data']);
129
			/* Try to decompress the data. */
130
			$dcomp = @gzinflate($data);
131
			if ($dcomp) {
132
				/* If the decompression worked, write the decompressed data */
133
				if (fwrite($rrd_fd, $dcomp) === false) {
134
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
135
					continue;
136
				}
137
			} else {
138
				/* If the decompression failed, it wasn't compressed, so write raw data */
139
				if (fwrite($rrd_fd, $data) === false) {
140
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
141
					continue;
142
				}
143
			}
144
			if (fclose($rrd_fd) === false) {
145
				log_error(sprintf(gettext("fclose %s failed"), $rrd_file));
146
				continue;
147
			}
148
		}
149
	}
150
}
151

    
152
function add_base_packages_menu_items() {
153
	global $g, $config;
154
	$base_packages = explode(",", $g['base_packages']);
155
	$modified_config = false;
156
	foreach ($base_packages as $bp) {
157
		$basepkg_path = "/usr/local/pkg/{$bp}";
158
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
159
		if ($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
160
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
161
			if ($pkg_config['menu'] != "") {
162
				if (is_array($pkg_config['menu'])) {
163
					foreach ($pkg_config['menu'] as $menu) {
164
						if (is_array($config['installedpackages']['menu'])) {
165
							foreach ($config['installedpackages']['menu'] as $amenu) {
166
								if ($amenu['name'] == $menu['name']) {
167
									continue;
168
								}
169
							}
170
						}
171
						$config['installedpackages']['menu'][] = $menu;
172
						$modified_config = true;
173
					}
174
				}
175
			}
176
		}
177
	}
178
	if ($modified_config) {
179
		write_config(gettext("Restored base_package menus after configuration restore."));
180
		$config = parse_config(true);
181
	}
182
}
183

    
184
function remove_bad_chars($string) {
185
	return preg_replace('/[^a-z_0-9]/i', '', $string);
186
}
187

    
188
function check_and_returnif_section_exists($section) {
189
	global $config;
190
	if (is_array($config[$section])) {
191
		return true;
192
	}
193
	return false;
194
}
195

    
196
if ($_POST['apply']) {
197
	ob_flush();
198
	flush();
199
	conf_mount_rw();
200
	clear_subsystem_dirty("restore");
201
	conf_mount_ro();
202
	exit;
203
}
204

    
205
if ($_POST) {
206
	unset($input_errors);
207
	if (stristr($_POST['Submit'], gettext("Restore configuration"))) {
208
		$mode = "restore";
209
	} else if (stristr($_POST['Submit'], gettext("Reinstall"))) {
210
		$mode = "reinstallpackages";
211
	} else if (stristr($_POST['Submit'], gettext("Clear Package Lock"))) {
212
		$mode = "clearpackagelock";
213
	} else if (stristr($_POST['Submit'], gettext("Download"))) {
214
		$mode = "download";
215
	} else if (stristr($_POST['Submit'], gettext("Restore version"))) {
216
		$mode = "restore_ver";
217
	}
218
	if ($_POST["nopackages"] <> "") {
219
		$options = "nopackages";
220
	}
221
	if ($_POST["ver"] <> "") {
222
		$ver2restore = $_POST["ver"];
223
	}
224
	if ($mode) {
225
		if ($mode == "download") {
226
			if ($_POST['encrypt']) {
227
				if (!$_POST['encrypt_password']) {
228
					$input_errors[] = gettext("A password for encryption must be supplied and confirmed.");
229
				}
230
			}
231

    
232
			if (!$input_errors) {
233

    
234
				//$lockbckp = lock('config');
235

    
236
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
237
				$name = "config-{$host}-".date("YmdHis").".xml";
238
				$data = "";
239

    
240
				if ($options == "nopackages") {
241
					if (!$_POST['backuparea']) {
242
						/* backup entire configuration */
243
						$data = file_get_contents("{$g['conf_path']}/config.xml");
244
					} else {
245
						/* backup specific area of configuration */
246
						$data = backup_config_section($_POST['backuparea']);
247
						$name = "{$_POST['backuparea']}-{$name}";
248
					}
249
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
250
					file_put_contents($sfn, $data);
251
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
252
					$data = file_get_contents($sfn . "-new");
253
				} else {
254
					if (!$_POST['backuparea']) {
255
						/* backup entire configuration */
256
						$data = file_get_contents("{$g['conf_path']}/config.xml");
257
					} else if ($_POST['backuparea'] === "rrddata") {
258
						$data = rrd_data_xml();
259
						$name = "{$_POST['backuparea']}-{$name}";
260
					} else {
261
						/* backup specific area of configuration */
262
						$data = backup_config_section($_POST['backuparea']);
263
						$name = "{$_POST['backuparea']}-{$name}";
264
					}
265
				}
266

    
267
				//unlock($lockbckp);
268

    
269
				/*
270
				 *	Backup RRD Data
271
				 */
272
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
273
					$rrd_data_xml = rrd_data_xml();
274
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
275
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
276
				}
277

    
278
				if ($_POST['encrypt']) {
279
					$data = encrypt_data($data, $_POST['encrypt_password']);
280
					tagfile_reformat($data, $data, "config.xml");
281
				}
282

    
283
				$size = strlen($data);
284
				header("Content-Type: application/octet-stream");
285
				header("Content-Disposition: attachment; filename={$name}");
286
				header("Content-Length: $size");
287
				if (isset($_SERVER['HTTPS'])) {
288
					header('Pragma: ');
289
					header('Cache-Control: ');
290
				} else {
291
					header("Pragma: private");
292
					header("Cache-Control: private, must-revalidate");
293
				}
294
				echo $data;
295

    
296
				exit;
297
			}
298
		}
299

    
300
		if ($mode == "restore") {
301
			if ($_POST['decrypt']) {
302
				if (!$_POST['decrypt_password']) {
303
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
304
				}
305
			}
306

    
307
			if (!$input_errors) {
308
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
309

    
310
					/* read the file contents */
311
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
312
					if (!$data) {
313
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
314
						return 1;
315
					}
316

    
317
					if ($_POST['decrypt']) {
318
						if (!tagfile_deformat($data, $data, "config.xml")) {
319
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
320
							return 1;
321
						}
322
						$data = decrypt_data($data, $_POST['decrypt_password']);
323
					}
324

    
325
					if (stristr($data, "<m0n0wall>")) {
326
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
327
						/* m0n0wall was found in config.  convert it. */
328
						$data = str_replace("m0n0wall", "pfsense", $data);
329
						$m0n0wall_upgrade = true;
330
					}
331
					if ($_POST['restorearea']) {
332
						/* restore a specific area of the configuration */
333
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
334
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
335
						} else {
336
							if (!restore_config_section($_POST['restorearea'], $data)) {
337
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
338
							} else {
339
								if ($config['rrddata']) {
340
									restore_rrddata();
341
									unset($config['rrddata']);
342
									unlink_if_exists("{$g['tmp_path']}/config.cache");
343
									write_config();
344
									add_base_packages_menu_items();
345
									convert_config();
346
									conf_mount_ro();
347
								}
348
								filter_configure();
349
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
350
							}
351
						}
352
					} else {
353
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
354
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
355
						} else {
356
							/* restore the entire configuration */
357
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
358
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
359
								/* this will be picked up by /index.php */
360
								conf_mount_rw();
361
								mark_subsystem_dirty("restore");
362
								touch("/conf/needs_package_sync_after_reboot");
363
								/* remove cache, we will force a config reboot */
364
								if (file_exists("{$g['tmp_path']}/config.cache")) {
365
									unlink("{$g['tmp_path']}/config.cache");
366
								}
367
								$config = parse_config(true);
368
								if (file_exists("/boot/loader.conf")) {
369
									$loaderconf = file_get_contents("/boot/loader.conf");
370
									if (strpos($loaderconf, "console=\"comconsole")) {
371
										$config['system']['enableserial'] = true;
372
										write_config(gettext("Restore serial console enabling in configuration."));
373
									}
374
									unset($loaderconf);
375
								}
376
								/* extract out rrd items, unset from $config when done */
377
								if ($config['rrddata']) {
378
									restore_rrddata();
379
									unset($config['rrddata']);
380
									unlink_if_exists("{$g['tmp_path']}/config.cache");
381
									write_config();
382
									add_base_packages_menu_items();
383
									convert_config();
384
									conf_mount_ro();
385
								}
386
								if ($m0n0wall_upgrade == true) {
387
									if ($config['system']['gateway'] <> "") {
388
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
389
									}
390
									unset($config['shaper']);
391
									/* optional if list */
392
									$ifdescrs = get_configured_interface_list(true, true);
393
									/* remove special characters from interface descriptions */
394
									if (is_array($ifdescrs)) {
395
										foreach ($ifdescrs as $iface) {
396
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
397
										}
398
									}
399
									/* check for interface names with an alias */
400
									if (is_array($ifdescrs)) {
401
										foreach ($ifdescrs as $iface) {
402
											if (is_alias($config['interfaces'][$iface]['descr'])) {
403
												// Firewall rules
404
												$origname = $config['interfaces'][$iface]['descr'];
405
												$newname = $config['interfaces'][$iface]['descr'] . "Alias";
406
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
407
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
408
												// NAT Rules
409
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
410
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
411
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
412
												// Alias in an alias
413
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
414
											}
415
										}
416
									}
417
									unlink_if_exists("{$g['tmp_path']}/config.cache");
418
									// Reset configuration version to something low
419
									// in order to force the config upgrade code to
420
									// run through with all steps that are required.
421
									$config['system']['version'] = "1.0";
422
									// Deal with descriptions longer than 63 characters
423
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
424
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
425
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
426
										}
427
									}
428
									// Move interface from ipsec to enc0
429
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
430
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
431
											$config['filter']['rule'][$i]['interface'] = "enc0";
432
										}
433
									}
434
									// Convert icmp types
435
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
436
									$convert = array('echo' => 'echoreq', 'timest' => 'timereq', 'timestrep' => 'timerep');
437
									foreach ($config["filter"]["rule"] as $ruleid => &$ruledata) {
438
										if ($convert[$ruledata['icmptype']]) {
439
											$ruledata['icmptype'] = $convert[$ruledata['icmptype']];
440
										}
441
									}
442
									$config['diag']['ipv6nat'] = true;
443
									write_config();
444
									add_base_packages_menu_items();
445
									convert_config();
446
									conf_mount_ro();
447
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
448
									mark_subsystem_dirty("restore");
449
								}
450
								if (is_array($config['captiveportal'])) {
451
									foreach ($config['captiveportal'] as $cp) {
452
										if (isset($cp['enable'])) {
453
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
454
											mark_subsystem_dirty("restore");
455
											break;
456
										}
457
									}
458
								}
459
								setup_serial_port();
460
								if (is_interface_mismatch() == true) {
461
									touch("/var/run/interface_mismatch_reboot_needed");
462
									clear_subsystem_dirty("restore");
463
									convert_config();
464
									header("Location: interfaces_assign.php");
465
									exit;
466
								}
467
								if (is_interface_vlan_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
							} else {
475
								$input_errors[] = gettext("The configuration could not be restored.");
476
							}
477
						}
478
					}
479
				} else {
480
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
481
				}
482
			}
483
		}
484

    
485
		if ($mode == "reinstallpackages") {
486
			header("Location: pkg_mgr_install.php?mode=reinstallall");
487
			exit;
488
		} else if ($mode == "clearpackagelock") {
489
			clear_subsystem_dirty('packagelock');
490
			$savemsg = "Package lock cleared.";
491
		} else if ($mode == "restore_ver") {
492
			$input_errors[] = gettext("XXX - this feature may hose the config (do NOT backrev configs!) - billm");
493
			if ($ver2restore <> "") {
494
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
495
				if (config_install($conf_file) == 0) {
496
					mark_subsystem_dirty("restore");
497
				} else {
498
					$input_errors[] = gettext("The configuration could not be restored.");
499
				}
500
			} else {
501
				$input_errors[] = gettext("No version selected.");
502
			}
503
		}
504
	}
505
}
506

    
507
$id = rand() . '.' . time();
508

    
509
$mth = ini_get('upload_progress_meter.store_method');
510
$dir = ini_get('upload_progress_meter.file.filename_template');
511

    
512
function build_area_list($showall) {
513
	global $config;
514

    
515
	$areas = array(
516
		"aliases" => gettext("Aliases"),
517
		"captiveportal" => gettext("Captive Portal"),
518
		"voucher" => gettext("Captive Portal Vouchers"),
519
		"dnsmasq" => gettext("DNS Forwarder"),
520
		"unbound" => gettext("DNS Resolver"),
521
		"dhcpd" => gettext("DHCP Server"),
522
		"dhcpdv6" => gettext("DHCPv6 Server"),
523
		"filter" => gettext("Firewall Rules"),
524
		"interfaces" => gettext("Interfaces"),
525
		"ipsec" => gettext("IPSEC"),
526
		"nat" => gettext("NAT"),
527
		"openvpn" => gettext("OpenVPN"),
528
		"installedpackages" => gettext("Package Manager"),
529
		"rrddata" => gettext("RRD Data"),
530
		"cron" => gettext("Scheduled Tasks"),
531
		"syslog" => gettext("Syslog"),
532
		"system" => gettext("System"),
533
		"staticroutes" => gettext("Static routes"),
534
		"sysctl" => gettext("System tunables"),
535
		"snmpd" => gettext("SNMP Server"),
536
		"shaper" => gettext("Traffic Shaper"),
537
		"vlans" => gettext("VLANS"),
538
		"wol" => gettext("Wake-on-LAN")
539
		);
540

    
541
	$list = array("" => gettext("All"));
542

    
543
	if ($showall) {
544
		return($list + $areas);
545
	} else {
546
		foreach ($areas as $area => $areaname) {
547
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
548
				$list[$area] = $areaname;
549
			}
550
		}
551

    
552
		return($list);
553
	}
554
}
555

    
556
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
557
include("head.inc");
558

    
559
if ($input_errors) {
560
	print_input_errors($input_errors);
561
}
562

    
563
if ($savemsg) {
564
	print_info_box($savemsg, 'success');
565
}
566

    
567
if (is_subsystem_dirty('restore')):
568
?>
569
	<br/>
570
	<form action="diag_reboot.php" method="post">
571
		<input name="Submit" type="hidden" value="Yes" />
572
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
573
		<br />
574
	</form>
575
<?php
576
endif;
577

    
578
$tab_array = array();
579
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
580
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
581
display_top_tabs($tab_array);
582

    
583
$form = new Form(false);
584
$form->setMultipartEncoding();	// Allow file uploads
585

    
586
$section = new Form_Section('Backup Configuration');
587

    
588
$section->addInput(new Form_Select(
589
	'backuparea',
590
	'Backup area',
591
	'',
592
	build_area_list(false)
593
));
594

    
595
$section->addInput(new Form_Checkbox(
596
	'nopackages',
597
	'Skip packages',
598
	'Do not backup package information.',
599
	false
600
));
601

    
602
$section->addInput(new Form_Checkbox(
603
	'donotbackuprrd',
604
	'Skip RRD data',
605
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
606
	true
607
));
608

    
609
$section->addInput(new Form_Checkbox(
610
	'encrypt',
611
	'Encryption',
612
	'Encrypt this configuration file.',
613
	false
614
));
615

    
616
$section->addInput(new Form_Input(
617
	'encrypt_password',
618
	'Password',
619
	'password',
620
	null
621
));
622

    
623
$group = new Form_Group('');
624
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
625
$group->add(new Form_Button(
626
	'Submit',
627
	'Download configuration as XML',
628
	null,
629
	'fa-download'
630
))->setAttribute('id')->addClass('btn-primary');
631

    
632
$section->add($group);
633
$form->add($section);
634

    
635
$section = new Form_Section('Restore Backup');
636

    
637
$section->addInput(new Form_StaticText(
638
	null,
639
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
640
));
641

    
642
$section->addInput(new Form_Select(
643
	'restorearea',
644
	'Restore area',
645
	'',
646
	build_area_list(true)
647
));
648

    
649
$section->addInput(new Form_Input(
650
	'conffile',
651
	'Configuration file',
652
	'file',
653
	null
654
));
655

    
656
$section->addInput(new Form_Checkbox(
657
	'decrypt',
658
	'Encryption',
659
	'Configuration file is encrypted.',
660
	false
661
));
662

    
663
$section->addInput(new Form_Input(
664
	'decrypt_password',
665
	'Password',
666
	'password',
667
	null,
668
	['placeholder' => 'Password']
669
));
670

    
671
$group = new Form_Group('');
672
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
673
$group->add(new Form_Button(
674
	'Submit',
675
	'Restore Configuration',
676
	null,
677
	'fa-undo'
678
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
679

    
680
$section->add($group);
681

    
682
$form->add($section);
683

    
684
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
685
	$section = new Form_Section('Package Functions');
686

    
687
	if ($config['installedpackages']['package'] != "") {
688
		$group = new Form_Group('');
689
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
690
		$group->add(new Form_Button(
691
			'Submit',
692
			'Reinstall Packages',
693
			null,
694
			'fa-retweet'
695
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
696

    
697
		$section->add($group);
698
	}
699

    
700
	if (is_subsystem_dirty("packagelock")) {
701
		$group = new Form_Group('');
702
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
703
		$group->add(new Form_Button(
704
			'Submit',
705
			'Clear Package Lock',
706
			null,
707
			'fa-wrench'
708
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
709

    
710
		$section->add($group);
711
	}
712

    
713
	$form->add($section);
714
}
715

    
716
print($form);
717
?>
718
<script type="text/javascript">
719
//<![CDATA[
720
events.push(function() {
721

    
722
	// ------- Show/hide sections based on checkbox settings --------------------------------------
723

    
724
	function hideSections(hide) {
725
		hidePasswords();
726
	}
727

    
728
	function hidePasswords() {
729

    
730
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
731
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
732

    
733
		hideInput('encrypt_password', encryptHide);
734
		hideInput('encrypt_password_confirm', encryptHide);
735
		hideInput('decrypt_password', decryptHide);
736
		hideInput('decrypt_password_confirm', decryptHide);
737
	}
738

    
739
	// ---------- Click handlers ------------------------------------------------------------------
740

    
741
	$('input[name="encrypt"]').on('change', function() {
742
		hidePasswords();
743
	});
744

    
745
	$('input[name="decrypt"]').on('change', function() {
746
		hidePasswords();
747
	});
748

    
749
	$('#conffile').change(function () {
750
		if (document.getElementById("conffile").value) {
751
			$('.restore').prop('disabled', false);
752
		} else {
753
			$('.restore').prop('disabled', true);
754
		}
755
    });
756
	// ---------- On initial page load ------------------------------------------------------------
757

    
758
	hideSections();
759
	$('.restore').prop('disabled', true);
760
});
761
//]]>
762
</script>
763

    
764
<?php
765
include("foot.inc");
766

    
767
if (is_subsystem_dirty('restore')) {
768
	system_reboot();
769
}
(6-6/227)