Project

General

Profile

Download (23.1 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 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 ($_POST['restore']) {
176
		$mode = "restore";
177
	} else if ($_POST['reinstallpackages']) {
178
		$mode = "reinstallpackages";
179
	} else if ($_POST['clearpackagelock']) {
180
		$mode = "clearpackagelock";
181
	} else if ($_POST['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(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea']));
312
									convert_config();
313
									conf_mount_ro();
314
								}
315
								filter_configure();
316
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
317
							}
318
						}
319
					} else {
320
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
321
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
322
						} else {
323
							/* restore the entire configuration */
324
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
325
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
326
								/* this will be picked up by /index.php */
327
								conf_mount_rw();
328
								mark_subsystem_dirty("restore");
329
								touch("/conf/needs_package_sync_after_reboot");
330
								/* remove cache, we will force a config reboot */
331
								if (file_exists("{$g['tmp_path']}/config.cache")) {
332
									unlink("{$g['tmp_path']}/config.cache");
333
								}
334
								$config = parse_config(true);
335
								if (file_exists("/boot/loader.conf")) {
336
									$loaderconf = file_get_contents("/boot/loader.conf");
337
									if (strpos($loaderconf, "console=\"comconsole")) {
338
										$config['system']['enableserial'] = true;
339
										write_config(gettext("Restore serial console enabling in configuration."));
340
									}
341
									unset($loaderconf);
342
								}
343
								/* extract out rrd items, unset from $config when done */
344
								if ($config['rrddata']) {
345
									restore_rrddata();
346
									unset($config['rrddata']);
347
									unlink_if_exists("{$g['tmp_path']}/config.cache");
348
									write_config(gettext("Unset RRD data from configuration after restoring full configuration"));
349
									convert_config();
350
									conf_mount_ro();
351
								}
352
								if ($m0n0wall_upgrade == true) {
353
									if ($config['system']['gateway'] <> "") {
354
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
355
									}
356
									unset($config['shaper']);
357
									/* optional if list */
358
									$ifdescrs = get_configured_interface_list(true, true);
359
									/* remove special characters from interface descriptions */
360
									if (is_array($ifdescrs)) {
361
										foreach ($ifdescrs as $iface) {
362
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
363
										}
364
									}
365
									/* check for interface names with an alias */
366
									if (is_array($ifdescrs)) {
367
										foreach ($ifdescrs as $iface) {
368
											if (is_alias($config['interfaces'][$iface]['descr'])) {
369
												$origname = $config['interfaces'][$iface]['descr'];
370
												update_alias_name($origname . "Alias", $origname);
371
											}
372
										}
373
									}
374
									unlink_if_exists("{$g['tmp_path']}/config.cache");
375
									// Reset configuration version to something low
376
									// in order to force the config upgrade code to
377
									// run through with all steps that are required.
378
									$config['system']['version'] = "1.0";
379
									// Deal with descriptions longer than 63 characters
380
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
381
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
382
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
383
										}
384
									}
385
									// Move interface from ipsec to enc0
386
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
387
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
388
											$config['filter']['rule'][$i]['interface'] = "enc0";
389
										}
390
									}
391
									// Convert icmp types
392
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
393
									$convert = array('echo' => 'echoreq', 'timest' => 'timereq', 'timestrep' => 'timerep');
394
									foreach ($config["filter"]["rule"] as $ruleid => &$ruledata) {
395
										if ($convert[$ruledata['icmptype']]) {
396
											$ruledata['icmptype'] = $convert[$ruledata['icmptype']];
397
										}
398
									}
399
									$config['diag']['ipv6nat'] = true;
400
									write_config(gettext("Imported m0n0wall configuration"));
401
									convert_config();
402
									conf_mount_ro();
403
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
404
									mark_subsystem_dirty("restore");
405
								}
406
								if (is_array($config['captiveportal'])) {
407
									foreach ($config['captiveportal'] as $cp) {
408
										if (isset($cp['enable'])) {
409
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
410
											mark_subsystem_dirty("restore");
411
											break;
412
										}
413
									}
414
								}
415
								setup_serial_port();
416
								if (is_interface_mismatch() == true) {
417
									touch("/var/run/interface_mismatch_reboot_needed");
418
									clear_subsystem_dirty("restore");
419
									convert_config();
420
									header("Location: interfaces_assign.php");
421
									exit;
422
								}
423
								if (is_interface_vlan_mismatch() == true) {
424
									touch("/var/run/interface_mismatch_reboot_needed");
425
									clear_subsystem_dirty("restore");
426
									convert_config();
427
									header("Location: interfaces_assign.php");
428
									exit;
429
								}
430
							} else {
431
								$input_errors[] = gettext("The configuration could not be restored.");
432
							}
433
						}
434
					}
435
				} else {
436
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
437
				}
438
			}
439
		}
440

    
441
		if ($mode == "reinstallpackages") {
442
			header("Location: pkg_mgr_install.php?mode=reinstallall");
443
			exit;
444
		} else if ($mode == "clearpackagelock") {
445
			clear_subsystem_dirty('packagelock');
446
			$savemsg = "Package lock cleared.";
447
		} else if ($mode == "restore_ver") {
448
			$input_errors[] = gettext("XXX - this feature may hose the config (do NOT backrev configs!) - billm");
449
			if ($ver2restore <> "") {
450
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
451
				if (config_install($conf_file) == 0) {
452
					mark_subsystem_dirty("restore");
453
				} else {
454
					$input_errors[] = gettext("The configuration could not be restored.");
455
				}
456
			} else {
457
				$input_errors[] = gettext("No version selected.");
458
			}
459
		}
460
	}
461
}
462

    
463
$id = rand() . '.' . time();
464

    
465
$mth = ini_get('upload_progress_meter.store_method');
466
$dir = ini_get('upload_progress_meter.file.filename_template');
467

    
468
function build_area_list($showall) {
469
	global $config;
470

    
471
	$areas = array(
472
		"aliases" => gettext("Aliases"),
473
		"captiveportal" => gettext("Captive Portal"),
474
		"voucher" => gettext("Captive Portal Vouchers"),
475
		"dnsmasq" => gettext("DNS Forwarder"),
476
		"unbound" => gettext("DNS Resolver"),
477
		"dhcpd" => gettext("DHCP Server"),
478
		"dhcpdv6" => gettext("DHCPv6 Server"),
479
		"filter" => gettext("Firewall Rules"),
480
		"interfaces" => gettext("Interfaces"),
481
		"ipsec" => gettext("IPSEC"),
482
		"nat" => gettext("NAT"),
483
		"openvpn" => gettext("OpenVPN"),
484
		"installedpackages" => gettext("Package Manager"),
485
		"rrddata" => gettext("RRD Data"),
486
		"cron" => gettext("Scheduled Tasks"),
487
		"syslog" => gettext("Syslog"),
488
		"system" => gettext("System"),
489
		"staticroutes" => gettext("Static routes"),
490
		"sysctl" => gettext("System tunables"),
491
		"snmpd" => gettext("SNMP Server"),
492
		"shaper" => gettext("Traffic Shaper"),
493
		"vlans" => gettext("VLANS"),
494
		"wol" => gettext("Wake-on-LAN")
495
		);
496

    
497
	$list = array("" => gettext("All"));
498

    
499
	if ($showall) {
500
		return($list + $areas);
501
	} else {
502
		foreach ($areas as $area => $areaname) {
503
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
504
				$list[$area] = $areaname;
505
			}
506
		}
507

    
508
		return($list);
509
	}
510
}
511

    
512
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
513
$pglinks = array("", "@self", "@self");
514
include("head.inc");
515

    
516
if ($input_errors) {
517
	print_input_errors($input_errors);
518
}
519

    
520
if ($savemsg) {
521
	print_info_box($savemsg, 'success');
522
}
523

    
524
if (is_subsystem_dirty('restore')):
525
?>
526
	<br/>
527
	<form action="diag_reboot.php" method="post">
528
		<input name="Submit" type="hidden" value="Yes" />
529
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
530
		<br />
531
	</form>
532
<?php
533
endif;
534

    
535
$tab_array = array();
536
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
537
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
538
display_top_tabs($tab_array);
539

    
540
$form = new Form(false);
541
$form->setMultipartEncoding();	// Allow file uploads
542

    
543
$section = new Form_Section('Backup Configuration');
544

    
545
$section->addInput(new Form_Select(
546
	'backuparea',
547
	'Backup area',
548
	'',
549
	build_area_list(false)
550
));
551

    
552
$section->addInput(new Form_Checkbox(
553
	'nopackages',
554
	'Skip packages',
555
	'Do not backup package information.',
556
	false
557
));
558

    
559
$section->addInput(new Form_Checkbox(
560
	'donotbackuprrd',
561
	'Skip RRD data',
562
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
563
	true
564
));
565

    
566
$section->addInput(new Form_Checkbox(
567
	'encrypt',
568
	'Encryption',
569
	'Encrypt this configuration file.',
570
	false
571
));
572

    
573
$section->addInput(new Form_Input(
574
	'encrypt_password',
575
	'Password',
576
	'password',
577
	null
578
));
579

    
580
$group = new Form_Group('');
581
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
582
$group->add(new Form_Button(
583
	'download',
584
	'Download configuration as XML',
585
	null,
586
	'fa-download'
587
))->setAttribute('id')->addClass('btn-primary');
588

    
589
$section->add($group);
590
$form->add($section);
591

    
592
$section = new Form_Section('Restore Backup');
593

    
594
$section->addInput(new Form_StaticText(
595
	null,
596
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
597
));
598

    
599
$section->addInput(new Form_Select(
600
	'restorearea',
601
	'Restore area',
602
	'',
603
	build_area_list(true)
604
));
605

    
606
$section->addInput(new Form_Input(
607
	'conffile',
608
	'Configuration file',
609
	'file',
610
	null
611
));
612

    
613
$section->addInput(new Form_Checkbox(
614
	'decrypt',
615
	'Encryption',
616
	'Configuration file is encrypted.',
617
	false
618
));
619

    
620
$section->addInput(new Form_Input(
621
	'decrypt_password',
622
	'Password',
623
	'password',
624
	null,
625
	['placeholder' => 'Password']
626
));
627

    
628
$group = new Form_Group('');
629
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
630
$group->add(new Form_Button(
631
	'restore',
632
	'Restore Configuration',
633
	null,
634
	'fa-undo'
635
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
636

    
637
$section->add($group);
638

    
639
$form->add($section);
640

    
641
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
642
	$section = new Form_Section('Package Functions');
643

    
644
	if ($config['installedpackages']['package'] != "") {
645
		$group = new Form_Group('');
646
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
647
		$group->add(new Form_Button(
648
			'reinstallpackages',
649
			'Reinstall Packages',
650
			null,
651
			'fa-retweet'
652
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
653

    
654
		$section->add($group);
655
	}
656

    
657
	if (is_subsystem_dirty("packagelock")) {
658
		$group = new Form_Group('');
659
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
660
		$group->add(new Form_Button(
661
			'clearpackagelock',
662
			'Clear Package Lock',
663
			null,
664
			'fa-wrench'
665
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
666

    
667
		$section->add($group);
668
	}
669

    
670
	$form->add($section);
671
}
672

    
673
print($form);
674
?>
675
<script type="text/javascript">
676
//<![CDATA[
677
events.push(function() {
678

    
679
	// ------- Show/hide sections based on checkbox settings --------------------------------------
680

    
681
	function hideSections(hide) {
682
		hidePasswords();
683
	}
684

    
685
	function hidePasswords() {
686

    
687
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
688
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
689

    
690
		hideInput('encrypt_password', encryptHide);
691
		hideInput('encrypt_password_confirm', encryptHide);
692
		hideInput('decrypt_password', decryptHide);
693
		hideInput('decrypt_password_confirm', decryptHide);
694
	}
695

    
696
	// ---------- Click handlers ------------------------------------------------------------------
697

    
698
	$('input[name="encrypt"]').on('change', function() {
699
		hidePasswords();
700
	});
701

    
702
	$('input[name="decrypt"]').on('change', function() {
703
		hidePasswords();
704
	});
705

    
706
	$('#conffile').change(function () {
707
		if (document.getElementById("conffile").value) {
708
			$('.restore').prop('disabled', false);
709
		} else {
710
			$('.restore').prop('disabled', true);
711
		}
712
    });
713
	// ---------- On initial page load ------------------------------------------------------------
714

    
715
	hideSections();
716
	$('.restore').prop('disabled', true);
717
});
718
//]]>
719
</script>
720

    
721
<?php
722
include("foot.inc");
723

    
724
if (is_subsystem_dirty('restore')) {
725
	system_reboot();
726
}
(6-6/225)