Project

General

Profile

Download (22.3 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-2020 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
require_once("pkg-utils.inc");
45

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

    
49
function rrd_data_xml() {
50
	global $rrddbpath;
51
	global $rrdtool;
52

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

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

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

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

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

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

    
163
			if (!$input_errors) {
164

    
165
				//$lockbckp = lock('config');
166

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

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

    
195
				//unlock($lockbckp);
196

    
197
				/*
198
				 *	Backup RRD Data
199
				 */
200

    
201
				/* If the config on disk had rrddata tags already, remove that section first.
202
				 * See https://redmine.pfsense.org/issues/8994 and
203
				 *     https://redmine.pfsense.org/issues/10508 */
204
				$data = preg_replace("/[[:blank:]]*<rrddata>.*<\\/rrddata>[[:blank:]]*\n*/s", "", $data);
205
				$data = preg_replace("/[[:blank:]]*<rrddata\\/>[[:blank:]]*\n*/", "", $data);
206

    
207
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
208
					$rrd_data_xml = rrd_data_xml();
209
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
210
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
211
				}
212

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

    
218
				send_user_download('data', $data, $name);
219
			}
220
		}
221

    
222
		if ($mode == "restore") {
223
			if ($_POST['decrypt']) {
224
				if (!$_POST['decrypt_password']) {
225
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
226
				}
227
			}
228

    
229
			if (!$input_errors) {
230
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
231

    
232
					/* read the file contents */
233
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
234
					if (!$data) {
235
						$input_errors[] = gettext("Warning, could not read file {$_FILES['conffile']['tmp_name']}");
236
					} elseif ($_POST['decrypt']) {
237
						if (!tagfile_deformat($data, $data, "config.xml")) {
238
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
239
						} else {
240
							$data = decrypt_data($data, $_POST['decrypt_password']);
241
							if (empty($data)) {
242
								$input_errors[] = gettext("File decryption failed. Incorrect password or file is invalid.");
243
							}
244
						}
245
					}
246
					if (stristr($data, "<m0n0wall>")) {
247
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
248
						/* m0n0wall was found in config.  convert it. */
249
						$data = str_replace("m0n0wall", "pfsense", $data);
250
						$m0n0wall_upgrade = true;
251
					}
252

    
253
					/* If the config on disk had empty rrddata tags, remove them to
254
					 * avoid an XML parsing error.
255
					 * See https://redmine.pfsense.org/issues/8994 */
256
					$data = preg_replace("/<rrddata><\\/rrddata>/", "", $data);
257
					$data = preg_replace("/<rrddata\\/>/", "", $data);
258

    
259
					if ($_POST['restorearea'] && !$input_errors) {
260
						/* restore a specific area of the configuration */
261
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
262
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
263
						} else {
264
							if (!restore_config_section($_POST['restorearea'], $data)) {
265
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
266
							} else {
267
								if ($config['rrddata']) {
268
									restore_rrddata();
269
									unset($config['rrddata']);
270
									unlink_if_exists("{$g['tmp_path']}/config.cache");
271
									write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea']));
272
									convert_config();
273
								}
274
								filter_configure();
275
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
276
							}
277
						}
278
					} elseif (!$input_errors) {
279
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
280
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
281
						} else {
282
							/* restore the entire configuration */
283
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
284
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
285
								/* Save current pkg repo to re-add on new config */
286
								unset($pkg_repo_conf_path);
287
								if (isset($config['system']['pkg_repo_conf_path'])) {
288
									$pkg_repo_conf_path = $config['system']['pkg_repo_conf_path'];
289
								}
290

    
291
								/* this will be picked up by /index.php */
292
								mark_subsystem_dirty("restore");
293
								touch("/conf/needs_package_sync");
294
								/* remove cache, we will force a config reboot */
295
								if (file_exists("{$g['tmp_path']}/config.cache")) {
296
									unlink("{$g['tmp_path']}/config.cache");
297
								}
298
								$config = parse_config(true);
299

    
300
								/* Restore previously pkg repo configured */
301
								$pkg_repo_restored = false;
302
								if (isset($pkg_repo_conf_path)) {
303
									$config['system']['pkg_repo_conf_path'] =
304
									    $pkg_repo_conf_path;
305
									$pkg_repo_restored = true;
306
								} elseif (isset($config['system']['pkg_repo_conf_path'])) {
307
									unset($config['system']['pkg_repo_conf_path']);
308
									$pkg_repo_restored = true;
309
								}
310

    
311
								if ($pkg_repo_restored) {
312
									write_config(gettext("Removing pkg repository set after restoring full configuration"));
313
									pkg_update(true);
314
								}
315

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

    
430
		if ($mode == "reinstallpackages") {
431
			header("Location: pkg_mgr_install.php?mode=reinstallall");
432
			exit;
433
		} else if ($mode == "clearpackagelock") {
434
			clear_subsystem_dirty('packagelock');
435
			$savemsg = "Package lock cleared.";
436
		}
437
	}
438
}
439

    
440
$id = rand() . '.' . time();
441

    
442
$mth = ini_get('upload_progress_meter.store_method');
443
$dir = ini_get('upload_progress_meter.file.filename_template');
444

    
445
function build_area_list($showall) {
446
	global $config;
447

    
448
	$areas = array(
449
		"aliases" => gettext("Aliases"),
450
		"captiveportal" => gettext("Captive Portal"),
451
		"voucher" => gettext("Captive Portal Vouchers"),
452
		"dnsmasq" => gettext("DNS Forwarder"),
453
		"unbound" => gettext("DNS Resolver"),
454
		"dhcpd" => gettext("DHCP Server"),
455
		"dhcpdv6" => gettext("DHCPv6 Server"),
456
		"filter" => gettext("Firewall Rules"),
457
		"interfaces" => gettext("Interfaces"),
458
		"ipsec" => gettext("IPSEC"),
459
		"nat" => gettext("NAT"),
460
		"openvpn" => gettext("OpenVPN"),
461
		"installedpackages" => gettext("Package Manager"),
462
		"rrddata" => gettext("RRD Data"),
463
		"cron" => gettext("Scheduled Tasks"),
464
		"syslog" => gettext("Syslog"),
465
		"system" => gettext("System"),
466
		"staticroutes" => gettext("Static routes"),
467
		"sysctl" => gettext("System tunables"),
468
		"snmpd" => gettext("SNMP Server"),
469
		"shaper" => gettext("Traffic Shaper"),
470
		"vlans" => gettext("VLANS"),
471
		"wol" => gettext("Wake-on-LAN")
472
		);
473

    
474
	$list = array("" => gettext("All"));
475

    
476
	if ($showall) {
477
		return($list + $areas);
478
	} else {
479
		foreach ($areas as $area => $areaname) {
480
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
481
				$list[$area] = $areaname;
482
			}
483
		}
484

    
485
		return($list);
486
	}
487
}
488

    
489
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
490
$pglinks = array("", "@self", "@self");
491
include("head.inc");
492

    
493
if ($input_errors) {
494
	print_input_errors($input_errors);
495
}
496

    
497
if ($savemsg) {
498
	print_info_box($savemsg, 'success');
499
}
500

    
501
if (is_subsystem_dirty('restore')):
502
?>
503
	<br/>
504
	<form action="diag_reboot.php" method="post">
505
		<input name="Submit" type="hidden" value="Yes" />
506
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
507
		<br />
508
	</form>
509
<?php
510
endif;
511

    
512
$tab_array = array();
513
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
514
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
515
display_top_tabs($tab_array);
516

    
517
$form = new Form(false);
518
$form->setMultipartEncoding();	// Allow file uploads
519

    
520
$section = new Form_Section('Backup Configuration');
521

    
522
$section->addInput(new Form_Select(
523
	'backuparea',
524
	'Backup area',
525
	'',
526
	build_area_list(false)
527
));
528

    
529
$section->addInput(new Form_Checkbox(
530
	'nopackages',
531
	'Skip packages',
532
	'Do not backup package information.',
533
	false
534
));
535

    
536
$section->addInput(new Form_Checkbox(
537
	'donotbackuprrd',
538
	'Skip RRD data',
539
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
540
	true
541
));
542

    
543
$section->addInput(new Form_Checkbox(
544
	'encrypt',
545
	'Encryption',
546
	'Encrypt this configuration file.',
547
	false
548
));
549

    
550
$section->addInput(new Form_Input(
551
	'encrypt_password',
552
	'Password',
553
	'password',
554
	null
555
));
556

    
557
$group = new Form_Group('');
558
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
559
$group->add(new Form_Button(
560
	'download',
561
	'Download configuration as XML',
562
	null,
563
	'fa-download'
564
))->setAttribute('id')->addClass('btn-primary');
565

    
566
$section->add($group);
567
$form->add($section);
568

    
569
$section = new Form_Section('Restore Backup');
570

    
571
$section->addInput(new Form_StaticText(
572
	null,
573
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
574
));
575

    
576
$section->addInput(new Form_Select(
577
	'restorearea',
578
	'Restore area',
579
	'',
580
	build_area_list(true)
581
));
582

    
583
$section->addInput(new Form_Input(
584
	'conffile',
585
	'Configuration file',
586
	'file',
587
	null
588
));
589

    
590
$section->addInput(new Form_Checkbox(
591
	'decrypt',
592
	'Encryption',
593
	'Configuration file is encrypted.',
594
	false
595
));
596

    
597
$section->addInput(new Form_Input(
598
	'decrypt_password',
599
	'Password',
600
	'password',
601
	null,
602
	['placeholder' => 'Password']
603
));
604

    
605
$group = new Form_Group('');
606
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
607
$group->add(new Form_Button(
608
	'restore',
609
	'Restore Configuration',
610
	null,
611
	'fa-undo'
612
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
613

    
614
$section->add($group);
615

    
616
$form->add($section);
617

    
618
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
619
	$section = new Form_Section('Package Functions');
620

    
621
	if ($config['installedpackages']['package'] != "") {
622
		$group = new Form_Group('');
623
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
624
		$group->add(new Form_Button(
625
			'reinstallpackages',
626
			'Reinstall Packages',
627
			null,
628
			'fa-retweet'
629
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
630

    
631
		$section->add($group);
632
	}
633

    
634
	if (is_subsystem_dirty("packagelock")) {
635
		$group = new Form_Group('');
636
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
637
		$group->add(new Form_Button(
638
			'clearpackagelock',
639
			'Clear Package Lock',
640
			null,
641
			'fa-wrench'
642
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
643

    
644
		$section->add($group);
645
	}
646

    
647
	$form->add($section);
648
}
649

    
650
print($form);
651
?>
652
<script type="text/javascript">
653
//<![CDATA[
654
events.push(function() {
655

    
656
	// ------- Show/hide sections based on checkbox settings --------------------------------------
657

    
658
	function hideSections(hide) {
659
		hidePasswords();
660
	}
661

    
662
	function hidePasswords() {
663

    
664
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
665
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
666

    
667
		hideInput('encrypt_password', encryptHide);
668
		hideInput('encrypt_password_confirm', encryptHide);
669
		hideInput('decrypt_password', decryptHide);
670
		hideInput('decrypt_password_confirm', decryptHide);
671
	}
672

    
673
	// ---------- Click handlers ------------------------------------------------------------------
674

    
675
	$('input[name="encrypt"]').on('change', function() {
676
		hidePasswords();
677
	});
678

    
679
	$('input[name="decrypt"]').on('change', function() {
680
		hidePasswords();
681
	});
682

    
683
	$('#conffile').change(function () {
684
		if (document.getElementById("conffile").value) {
685
			$('.restore').prop('disabled', false);
686
		} else {
687
			$('.restore').prop('disabled', true);
688
		}
689
    });
690
	// ---------- On initial page load ------------------------------------------------------------
691

    
692
	hideSections();
693
	$('.restore').prop('disabled', true);
694
});
695
//]]>
696
</script>
697

    
698
<?php
699
include("foot.inc");
700

    
701
if (is_subsystem_dirty('restore')) {
702
	system_reboot();
703
}
(10-10/235)