Project

General

Profile

Download (22.2 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-2020 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'] || ($_POST['encrypt_password'] != $_POST['encrypt_password_confirm'])) {
161
					$input_errors[] = gettext("Supplied password and confirmation do not match.");
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
				send_user_download('data', $data, $name);
220
			}
221
		}
222

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
663
	function hidePasswords() {
664

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

    
668
		hideInput('encrypt_password', encryptHide);
669
		hideInput('decrypt_password', decryptHide);
670
	}
671

    
672
	// ---------- Click handlers ------------------------------------------------------------------
673

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

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

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

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

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

    
700
if (is_subsystem_dirty('restore')) {
701
	system_reboot();
702
}
(10-10/227)