Project

General

Profile

Download (22.5 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-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8
 * Copyright (c) 2014-2019 Rubicon Communications, LLC (Netgate)
9
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27

    
28
##|+PRIV
29
##|*IDENT=page-diagnostics-backup-restore
30
##|*NAME=Diagnostics: Backup & Restore
31
##|*DESCR=Allow access to the 'Diagnostics: Backup & Restore' page.
32
##|*WARN=standard-warning-root
33
##|*MATCH=diag_backup.php*
34
##|-PRIV
35

    
36
/* Allow additional execution time 0 = no limit. */
37
ini_set('max_execution_time', '0');
38
ini_set('max_input_time', '0');
39

    
40
/* omit no-cache headers because it confuses IE with file downloads */
41
$omit_nocacheheaders = true;
42
require_once("guiconfig.inc");
43
require_once("functions.inc");
44
require_once("filter.inc");
45
require_once("shaper.inc");
46
require_once("pkg-utils.inc");
47

    
48
$rrddbpath = "/var/db/rrd";
49
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
50

    
51
function rrd_data_xml() {
52
	global $rrddbpath;
53
	global $rrdtool;
54

    
55
	$result = "\t<rrddata>\n";
56
	$rrd_files = glob("{$rrddbpath}/*.rrd");
57
	$xml_files = array();
58
	foreach ($rrd_files as $rrd_file) {
59
		$basename = basename($rrd_file);
60
		$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
61
		exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
62
		$xml_data = file_get_contents($xml_file);
63
		unlink($xml_file);
64
		if ($xml_data !== false) {
65
			$result .= "\t\t<rrddatafile>\n";
66
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
67
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
68
			$result .= "\t\t</rrddatafile>\n";
69
		}
70
	}
71
	$result .= "\t</rrddata>\n";
72
	return $result;
73
}
74

    
75
function restore_rrddata() {
76
	global $config, $g, $rrdtool, $input_errors;
77
	foreach ($config['rrddata']['rrddatafile'] as $rrd) {
78
		if ($rrd['xmldata']) {
79
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
80
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
81
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
82
				log_error(sprintf(gettext("Cannot write %s"), $xml_file));
83
				continue;
84
			}
85
			$output = array();
86
			$status = null;
87
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
88
			if ($status) {
89
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
90
				continue;
91
			}
92
			unlink($xml_file);
93
		} else if ($rrd['data']) {
94
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
95
			$rrd_fd = fopen($rrd_file, "w");
96
			if (!$rrd_fd) {
97
				log_error(sprintf(gettext("Cannot write %s"), $rrd_file));
98
				continue;
99
			}
100
			$data = base64_decode($rrd['data']);
101
			/* Try to decompress the data. */
102
			$dcomp = @gzinflate($data);
103
			if ($dcomp) {
104
				/* If the decompression worked, write the decompressed data */
105
				if (fwrite($rrd_fd, $dcomp) === false) {
106
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
107
					continue;
108
				}
109
			} else {
110
				/* If the decompression failed, it wasn't compressed, so write raw data */
111
				if (fwrite($rrd_fd, $data) === false) {
112
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
113
					continue;
114
				}
115
			}
116
			if (fclose($rrd_fd) === false) {
117
				log_error(sprintf(gettext("fclose %s failed"), $rrd_file));
118
				continue;
119
			}
120
		}
121
	}
122
}
123

    
124
function remove_bad_chars($string) {
125
	return preg_replace('/[^a-z_0-9]/i', '', $string);
126
}
127

    
128
function check_and_returnif_section_exists($section) {
129
	global $config;
130
	if (is_array($config[$section])) {
131
		return true;
132
	}
133
	return false;
134
}
135

    
136
if ($_POST['apply']) {
137
	ob_flush();
138
	flush();
139
	clear_subsystem_dirty("restore");
140
	exit;
141
}
142

    
143
if ($_POST) {
144
	unset($input_errors);
145
	if ($_POST['restore']) {
146
		$mode = "restore";
147
	} else if ($_POST['reinstallpackages']) {
148
		$mode = "reinstallpackages";
149
	} else if ($_POST['clearpackagelock']) {
150
		$mode = "clearpackagelock";
151
	} else if ($_POST['download']) {
152
		$mode = "download";
153
	}
154
	if ($_POST["nopackages"] <> "") {
155
		$options = "nopackages";
156
	}
157
	if ($mode) {
158
		if ($mode == "download") {
159
			if ($_POST['encrypt']) {
160
				if (!$_POST['encrypt_password']) {
161
					$input_errors[] = gettext("A password for encryption must be supplied and confirmed.");
162
				}
163
			}
164

    
165
			if (!$input_errors) {
166

    
167
				//$lockbckp = lock('config');
168

    
169
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
170
				$name = "config-{$host}-".date("YmdHis").".xml";
171
				$data = "";
172

    
173
				if ($options == "nopackages") {
174
					if (!$_POST['backuparea']) {
175
						/* backup entire configuration */
176
						$data = file_get_contents("{$g['conf_path']}/config.xml");
177
					} else {
178
						/* backup specific area of configuration */
179
						$data = backup_config_section($_POST['backuparea']);
180
						$name = "{$_POST['backuparea']}-{$name}";
181
					}
182
					$data = preg_replace('/\t*<installedpackages>.*<\/installedpackages>\n/sm', '', $data);
183
				} else {
184
					if (!$_POST['backuparea']) {
185
						/* backup entire configuration */
186
						$data = file_get_contents("{$g['conf_path']}/config.xml");
187
					} else if ($_POST['backuparea'] === "rrddata") {
188
						$data = rrd_data_xml();
189
						$name = "{$_POST['backuparea']}-{$name}";
190
					} else {
191
						/* backup specific area of configuration */
192
						$data = backup_config_section($_POST['backuparea']);
193
						$name = "{$_POST['backuparea']}-{$name}";
194
					}
195
				}
196

    
197
				//unlock($lockbckp);
198

    
199
				/*
200
				 *	Backup RRD Data
201
				 */
202
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
203
					$rrd_data_xml = rrd_data_xml();
204
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
205

    
206
					/* If the config on disk had rrddata tags already, remove that section first.
207
					 * See https://redmine.pfsense.org/issues/8994 */
208
					$data = preg_replace("/<rrddata>.*<\\/rrddata>/", "", $data);
209
					$data = preg_replace("/<rrddata\\/>/", "", $data);
210

    
211
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
212
				}
213

    
214
				if ($_POST['encrypt']) {
215
					$data = encrypt_data($data, $_POST['encrypt_password']);
216
					tagfile_reformat($data, $data, "config.xml");
217
				}
218

    
219
				$size = strlen($data);
220
				header("Content-Type: application/octet-stream");
221
				header("Content-Disposition: attachment; filename={$name}");
222
				header("Content-Length: $size");
223
				if (isset($_SERVER['HTTPS'])) {
224
					header('Pragma: ');
225
					header('Cache-Control: ');
226
				} else {
227
					header("Pragma: private");
228
					header("Cache-Control: private, must-revalidate");
229
				}
230

    
231
				while (ob_get_level()) {
232
					@ob_end_clean();
233
				}
234
				echo $data;
235
				@ob_end_flush();
236
				exit;
237
			}
238
		}
239

    
240
		if ($mode == "restore") {
241
			if ($_POST['decrypt']) {
242
				if (!$_POST['decrypt_password']) {
243
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
244
				}
245
			}
246

    
247
			if (!$input_errors) {
248
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
249

    
250
					/* read the file contents */
251
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
252
					if (!$data) {
253
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
254
						return 1;
255
					}
256

    
257
					if ($_POST['decrypt']) {
258
						if (!tagfile_deformat($data, $data, "config.xml")) {
259
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
260
							return 1;
261
						}
262
						$data = decrypt_data($data, $_POST['decrypt_password']);
263
					}
264

    
265
					if (stristr($data, "<m0n0wall>")) {
266
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
267
						/* m0n0wall was found in config.  convert it. */
268
						$data = str_replace("m0n0wall", "pfsense", $data);
269
						$m0n0wall_upgrade = true;
270
					}
271

    
272
					/* If the config on disk had empty rrddata tags, remove them to
273
					 * avoid an XML parsing error.
274
					 * See https://redmine.pfsense.org/issues/8994 */
275
					$data = preg_replace("/<rrddata><\\/rrddata>/", "", $data);
276
					$data = preg_replace("/<rrddata\\/>/", "", $data);
277

    
278
					if ($_POST['restorearea']) {
279
						/* restore a specific area of the configuration */
280
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
281
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
282
						} else {
283
							if (!restore_config_section($_POST['restorearea'], $data)) {
284
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
285
							} else {
286
								if ($config['rrddata']) {
287
									restore_rrddata();
288
									unset($config['rrddata']);
289
									unlink_if_exists("{$g['tmp_path']}/config.cache");
290
									write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea']));
291
									convert_config();
292
								}
293
								filter_configure();
294
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
295
							}
296
						}
297
					} else {
298
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
299
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
300
						} else {
301
							/* restore the entire configuration */
302
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
303
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
304
								/* Save current pkg repo to re-add on new config */
305
								unset($pkg_repo_conf_path);
306
								if (isset($config['system']['pkg_repo_conf_path'])) {
307
									$pkg_repo_conf_path = $config['system']['pkg_repo_conf_path'];
308
								}
309

    
310
								/* this will be picked up by /index.php */
311
								mark_subsystem_dirty("restore");
312
								touch("/conf/needs_package_sync");
313
								/* remove cache, we will force a config reboot */
314
								if (file_exists("{$g['tmp_path']}/config.cache")) {
315
									unlink("{$g['tmp_path']}/config.cache");
316
								}
317
								$config = parse_config(true);
318

    
319
								/* Restore previously pkg repo configured */
320
								$pkg_repo_restored = false;
321
								if (isset($pkg_repo_conf_path)) {
322
									$config['system']['pkg_repo_conf_path'] =
323
									    $pkg_repo_conf_path;
324
									$pkg_repo_restored = true;
325
								} elseif (isset($config['system']['pkg_repo_conf_path'])) {
326
									unset($config['system']['pkg_repo_conf_path']);
327
									$pkg_repo_restored = true;
328
								}
329

    
330
								if ($pkg_repo_restored) {
331
									write_config(gettext("Removing pkg repository set after restoring full configuration"));
332
									pkg_update(true);
333
								}
334

    
335
								if (file_exists("/boot/loader.conf")) {
336
									$loaderconf = file_get_contents("/boot/loader.conf");
337
									if (strpos($loaderconf, "console=\"comconsole") ||
338
									    strpos($loaderconf, "boot_serial=\"YES")) {
339
										$config['system']['enableserial'] = true;
340
										write_config(gettext("Restore serial console enabling in configuration."));
341
									}
342
									unset($loaderconf);
343
								}
344
								if (file_exists("/boot/loader.conf.local")) {
345
									$loaderconf = file_get_contents("/boot/loader.conf.local");
346
									if (strpos($loaderconf, "console=\"comconsole") ||
347
									    strpos($loaderconf, "boot_serial=\"YES")) {
348
										$config['system']['enableserial'] = true;
349
										write_config(gettext("Restore serial console enabling in configuration."));
350
									}
351
									unset($loaderconf);
352
								}
353
								/* extract out rrd items, unset from $config when done */
354
								if ($config['rrddata']) {
355
									restore_rrddata();
356
									unset($config['rrddata']);
357
									unlink_if_exists("{$g['tmp_path']}/config.cache");
358
									write_config(gettext("Unset RRD data from configuration after restoring full configuration"));
359
									convert_config();
360
								}
361
								if ($m0n0wall_upgrade == true) {
362
									if ($config['system']['gateway'] <> "") {
363
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
364
									}
365
									unset($config['shaper']);
366
									/* optional if list */
367
									$ifdescrs = get_configured_interface_list(true);
368
									/* remove special characters from interface descriptions */
369
									if (is_array($ifdescrs)) {
370
										foreach ($ifdescrs as $iface) {
371
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
372
										}
373
									}
374
									/* check for interface names with an alias */
375
									if (is_array($ifdescrs)) {
376
										foreach ($ifdescrs as $iface) {
377
											if (is_alias($config['interfaces'][$iface]['descr'])) {
378
												$origname = $config['interfaces'][$iface]['descr'];
379
												update_alias_name($origname . "Alias", $origname);
380
											}
381
										}
382
									}
383
									unlink_if_exists("{$g['tmp_path']}/config.cache");
384
									// Reset configuration version to something low
385
									// in order to force the config upgrade code to
386
									// run through with all steps that are required.
387
									$config['system']['version'] = "1.0";
388
									// Deal with descriptions longer than 63 characters
389
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
390
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
391
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
392
										}
393
									}
394
									// Move interface from ipsec to enc0
395
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
396
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
397
											$config['filter']['rule'][$i]['interface'] = "enc0";
398
										}
399
									}
400
									// Convert icmp types
401
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
402
									$convert = array('echo' => 'echoreq', 'timest' => 'timereq', 'timestrep' => 'timerep');
403
									foreach ($config["filter"]["rule"] as $ruleid => &$ruledata) {
404
										if ($convert[$ruledata['icmptype']]) {
405
											$ruledata['icmptype'] = $convert[$ruledata['icmptype']];
406
										}
407
									}
408
									$config['diag']['ipv6nat'] = true;
409
									write_config(gettext("Imported m0n0wall configuration"));
410
									convert_config();
411
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
412
									mark_subsystem_dirty("restore");
413
								}
414
								if (is_array($config['captiveportal'])) {
415
									foreach ($config['captiveportal'] as $cp) {
416
										if (isset($cp['enable'])) {
417
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
418
											mark_subsystem_dirty("restore");
419
											break;
420
										}
421
									}
422
								}
423
								console_configure();
424
								if (is_interface_mismatch() == true) {
425
									touch("/var/run/interface_mismatch_reboot_needed");
426
									clear_subsystem_dirty("restore");
427
									convert_config();
428
									header("Location: interfaces_assign.php");
429
									exit;
430
								}
431
								if (is_interface_vlan_mismatch() == true) {
432
									touch("/var/run/interface_mismatch_reboot_needed");
433
									clear_subsystem_dirty("restore");
434
									convert_config();
435
									header("Location: interfaces_assign.php");
436
									exit;
437
								}
438
							} else {
439
								$input_errors[] = gettext("The configuration could not be restored.");
440
							}
441
						}
442
					}
443
				} else {
444
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
445
				}
446
			}
447
		}
448

    
449
		if ($mode == "reinstallpackages") {
450
			header("Location: pkg_mgr_install.php?mode=reinstallall");
451
			exit;
452
		} else if ($mode == "clearpackagelock") {
453
			clear_subsystem_dirty('packagelock');
454
			$savemsg = "Package lock cleared.";
455
		}
456
	}
457
}
458

    
459
$id = rand() . '.' . time();
460

    
461
$mth = ini_get('upload_progress_meter.store_method');
462
$dir = ini_get('upload_progress_meter.file.filename_template');
463

    
464
function build_area_list($showall) {
465
	global $config;
466

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

    
493
	$list = array("" => gettext("All"));
494

    
495
	if ($showall) {
496
		return($list + $areas);
497
	} else {
498
		foreach ($areas as $area => $areaname) {
499
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
500
				$list[$area] = $areaname;
501
			}
502
		}
503

    
504
		return($list);
505
	}
506
}
507

    
508
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
509
$pglinks = array("", "@self", "@self");
510
include("head.inc");
511

    
512
if ($input_errors) {
513
	print_input_errors($input_errors);
514
}
515

    
516
if ($savemsg) {
517
	print_info_box($savemsg, 'success');
518
}
519

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

    
531
$tab_array = array();
532
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
533
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
534
display_top_tabs($tab_array);
535

    
536
$form = new Form(false);
537
$form->setMultipartEncoding();	// Allow file uploads
538

    
539
$section = new Form_Section('Backup Configuration');
540

    
541
$section->addInput(new Form_Select(
542
	'backuparea',
543
	'Backup area',
544
	'',
545
	build_area_list(false)
546
));
547

    
548
$section->addInput(new Form_Checkbox(
549
	'nopackages',
550
	'Skip packages',
551
	'Do not backup package information.',
552
	false
553
));
554

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

    
562
$section->addInput(new Form_Checkbox(
563
	'encrypt',
564
	'Encryption',
565
	'Encrypt this configuration file.',
566
	false
567
));
568

    
569
$section->addInput(new Form_Input(
570
	'encrypt_password',
571
	'Password',
572
	'password',
573
	null
574
));
575

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

    
585
$section->add($group);
586
$form->add($section);
587

    
588
$section = new Form_Section('Restore Backup');
589

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

    
595
$section->addInput(new Form_Select(
596
	'restorearea',
597
	'Restore area',
598
	'',
599
	build_area_list(true)
600
));
601

    
602
$section->addInput(new Form_Input(
603
	'conffile',
604
	'Configuration file',
605
	'file',
606
	null
607
));
608

    
609
$section->addInput(new Form_Checkbox(
610
	'decrypt',
611
	'Encryption',
612
	'Configuration file is encrypted.',
613
	false
614
));
615

    
616
$section->addInput(new Form_Input(
617
	'decrypt_password',
618
	'Password',
619
	'password',
620
	null,
621
	['placeholder' => 'Password']
622
));
623

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

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

    
635
$form->add($section);
636

    
637
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
638
	$section = new Form_Section('Package Functions');
639

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

    
650
		$section->add($group);
651
	}
652

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

    
663
		$section->add($group);
664
	}
665

    
666
	$form->add($section);
667
}
668

    
669
print($form);
670
?>
671
<script type="text/javascript">
672
//<![CDATA[
673
events.push(function() {
674

    
675
	// ------- Show/hide sections based on checkbox settings --------------------------------------
676

    
677
	function hideSections(hide) {
678
		hidePasswords();
679
	}
680

    
681
	function hidePasswords() {
682

    
683
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
684
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
685

    
686
		hideInput('encrypt_password', encryptHide);
687
		hideInput('encrypt_password_confirm', encryptHide);
688
		hideInput('decrypt_password', decryptHide);
689
		hideInput('decrypt_password_confirm', decryptHide);
690
	}
691

    
692
	// ---------- Click handlers ------------------------------------------------------------------
693

    
694
	$('input[name="encrypt"]').on('change', function() {
695
		hidePasswords();
696
	});
697

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

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

    
711
	hideSections();
712
	$('.restore').prop('disabled', true);
713
});
714
//]]>
715
</script>
716

    
717
<?php
718
include("foot.inc");
719

    
720
if (is_subsystem_dirty('restore')) {
721
	system_reboot();
722
}
(10-10/227)