Project

General

Profile

Download (22.4 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-2019 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
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
201
					$rrd_data_xml = rrd_data_xml();
202
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
203

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

    
209
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
210
				}
211

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

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

    
230
				exit;
231
			}
232
		}
233

    
234
		if ($mode == "restore") {
235
			if ($_POST['decrypt']) {
236
				if (!$_POST['decrypt_password']) {
237
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
238
				}
239
			}
240

    
241
			if (!$input_errors) {
242
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
243

    
244
					/* read the file contents */
245
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
246
					if (!$data) {
247
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
248
						return 1;
249
					}
250

    
251
					if ($_POST['decrypt']) {
252
						if (!tagfile_deformat($data, $data, "config.xml")) {
253
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
254
							return 1;
255
						}
256
						$data = decrypt_data($data, $_POST['decrypt_password']);
257
					}
258

    
259
					if (stristr($data, "<m0n0wall>")) {
260
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
261
						/* m0n0wall was found in config.  convert it. */
262
						$data = str_replace("m0n0wall", "pfsense", $data);
263
						$m0n0wall_upgrade = true;
264
					}
265

    
266
					/* If the config on disk had empty rrddata tags, remove them to
267
					 * avoid an XML parsing error.
268
					 * See https://redmine.pfsense.org/issues/8994 */
269
					$data = preg_replace("/<rrddata><\\/rrddata>/", "", $data);
270
					$data = preg_replace("/<rrddata\\/>/", "", $data);
271

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

    
304
								/* this will be picked up by /index.php */
305
								mark_subsystem_dirty("restore");
306
								touch("/conf/needs_package_sync");
307
								/* remove cache, we will force a config reboot */
308
								if (file_exists("{$g['tmp_path']}/config.cache")) {
309
									unlink("{$g['tmp_path']}/config.cache");
310
								}
311
								$config = parse_config(true);
312

    
313
								/* Restore previously pkg repo configured */
314
								$pkg_repo_restored = false;
315
								if (isset($pkg_repo_conf_path)) {
316
									$config['system']['pkg_repo_conf_path'] =
317
									    $pkg_repo_conf_path;
318
									$pkg_repo_restored = true;
319
								} elseif (isset($config['system']['pkg_repo_conf_path'])) {
320
									unset($config['system']['pkg_repo_conf_path']);
321
									$pkg_repo_restored = true;
322
								}
323

    
324
								if ($pkg_repo_restored) {
325
									write_config(gettext("Removing pkg repository set after restoring full configuration"));
326
									pkg_update(true);
327
								}
328

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

    
443
		if ($mode == "reinstallpackages") {
444
			header("Location: pkg_mgr_install.php?mode=reinstallall");
445
			exit;
446
		} else if ($mode == "clearpackagelock") {
447
			clear_subsystem_dirty('packagelock');
448
			$savemsg = "Package lock cleared.";
449
		}
450
	}
451
}
452

    
453
$id = rand() . '.' . time();
454

    
455
$mth = ini_get('upload_progress_meter.store_method');
456
$dir = ini_get('upload_progress_meter.file.filename_template');
457

    
458
function build_area_list($showall) {
459
	global $config;
460

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

    
487
	$list = array("" => gettext("All"));
488

    
489
	if ($showall) {
490
		return($list + $areas);
491
	} else {
492
		foreach ($areas as $area => $areaname) {
493
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
494
				$list[$area] = $areaname;
495
			}
496
		}
497

    
498
		return($list);
499
	}
500
}
501

    
502
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
503
$pglinks = array("", "@self", "@self");
504
include("head.inc");
505

    
506
if ($input_errors) {
507
	print_input_errors($input_errors);
508
}
509

    
510
if ($savemsg) {
511
	print_info_box($savemsg, 'success');
512
}
513

    
514
if (is_subsystem_dirty('restore')):
515
?>
516
	<br/>
517
	<form action="diag_reboot.php" method="post">
518
		<input name="Submit" type="hidden" value="Yes" />
519
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
520
		<br />
521
	</form>
522
<?php
523
endif;
524

    
525
$tab_array = array();
526
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
527
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
528
display_top_tabs($tab_array);
529

    
530
$form = new Form(false);
531
$form->setMultipartEncoding();	// Allow file uploads
532

    
533
$section = new Form_Section('Backup Configuration');
534

    
535
$section->addInput(new Form_Select(
536
	'backuparea',
537
	'Backup area',
538
	'',
539
	build_area_list(false)
540
));
541

    
542
$section->addInput(new Form_Checkbox(
543
	'nopackages',
544
	'Skip packages',
545
	'Do not backup package information.',
546
	false
547
));
548

    
549
$section->addInput(new Form_Checkbox(
550
	'donotbackuprrd',
551
	'Skip RRD data',
552
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
553
	true
554
));
555

    
556
$section->addInput(new Form_Checkbox(
557
	'encrypt',
558
	'Encryption',
559
	'Encrypt this configuration file.',
560
	false
561
));
562

    
563
$section->addInput(new Form_Input(
564
	'encrypt_password',
565
	'Password',
566
	'password',
567
	null
568
));
569

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

    
579
$section->add($group);
580
$form->add($section);
581

    
582
$section = new Form_Section('Restore Backup');
583

    
584
$section->addInput(new Form_StaticText(
585
	null,
586
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
587
));
588

    
589
$section->addInput(new Form_Select(
590
	'restorearea',
591
	'Restore area',
592
	'',
593
	build_area_list(true)
594
));
595

    
596
$section->addInput(new Form_Input(
597
	'conffile',
598
	'Configuration file',
599
	'file',
600
	null
601
));
602

    
603
$section->addInput(new Form_Checkbox(
604
	'decrypt',
605
	'Encryption',
606
	'Configuration file is encrypted.',
607
	false
608
));
609

    
610
$section->addInput(new Form_Input(
611
	'decrypt_password',
612
	'Password',
613
	'password',
614
	null,
615
	['placeholder' => 'Password']
616
));
617

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

    
627
$section->add($group);
628

    
629
$form->add($section);
630

    
631
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
632
	$section = new Form_Section('Package Functions');
633

    
634
	if ($config['installedpackages']['package'] != "") {
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
			'reinstallpackages',
639
			'Reinstall Packages',
640
			null,
641
			'fa-retweet'
642
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
643

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

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

    
657
		$section->add($group);
658
	}
659

    
660
	$form->add($section);
661
}
662

    
663
print($form);
664
?>
665
<script type="text/javascript">
666
//<![CDATA[
667
events.push(function() {
668

    
669
	// ------- Show/hide sections based on checkbox settings --------------------------------------
670

    
671
	function hideSections(hide) {
672
		hidePasswords();
673
	}
674

    
675
	function hidePasswords() {
676

    
677
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
678
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
679

    
680
		hideInput('encrypt_password', encryptHide);
681
		hideInput('encrypt_password_confirm', encryptHide);
682
		hideInput('decrypt_password', decryptHide);
683
		hideInput('decrypt_password_confirm', decryptHide);
684
	}
685

    
686
	// ---------- Click handlers ------------------------------------------------------------------
687

    
688
	$('input[name="encrypt"]').on('change', function() {
689
		hidePasswords();
690
	});
691

    
692
	$('input[name="decrypt"]').on('change', function() {
693
		hidePasswords();
694
	});
695

    
696
	$('#conffile').change(function () {
697
		if (document.getElementById("conffile").value) {
698
			$('.restore').prop('disabled', false);
699
		} else {
700
			$('.restore').prop('disabled', true);
701
		}
702
    });
703
	// ---------- On initial page load ------------------------------------------------------------
704

    
705
	hideSections();
706
	$('.restore').prop('disabled', true);
707
});
708
//]]>
709
</script>
710

    
711
<?php
712
include("foot.inc");
713

    
714
if (is_subsystem_dirty('restore')) {
715
	system_reboot();
716
}
(9-9/234)