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-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

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

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

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

    
220
				send_user_download('data', $data, $name);
221
			}
222
		}
223

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
477
	$list = array("" => gettext("All"));
478

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

    
488
		return($list);
489
	}
490
}
491

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

    
496
if ($input_errors) {
497
	print_input_errors($input_errors);
498
}
499

    
500
if ($savemsg) {
501
	print_info_box($savemsg, 'success');
502
}
503

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

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

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

    
523
$section = new Form_Section('Backup Configuration');
524

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

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

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

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

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

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

    
569
$section->add($group);
570
$form->add($section);
571

    
572
$section = new Form_Section('Restore Backup');
573

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

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

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

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

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

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

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

    
619
$form->add($section);
620

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

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

    
634
		$section->add($group);
635
	}
636

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

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

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

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

    
659
	// ------- Show/hide sections based on checkbox settings --------------------------------------
660

    
661
	function hideSections(hide) {
662
		hidePasswords();
663
	}
664

    
665
	function hidePasswords() {
666

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

    
670
		hideInput('encrypt_password', encryptHide);
671
		hideInput('decrypt_password', decryptHide);
672
	}
673

    
674
	// ---------- Click handlers ------------------------------------------------------------------
675

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

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

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

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

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

    
702
if (is_subsystem_dirty('restore')) {
703
	system_reboot();
704
}
(10-10/228)