Project

General

Profile

Download (22.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_backup.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-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

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

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

    
245
			if (!$input_errors) {
246
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
247

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

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

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

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

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

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

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

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

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

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

    
457
$id = rand() . '.' . time();
458

    
459
$mth = ini_get('upload_progress_meter.store_method');
460
$dir = ini_get('upload_progress_meter.file.filename_template');
461

    
462
function build_area_list($showall) {
463
	global $config;
464

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

    
491
	$list = array("" => gettext("All"));
492

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

    
502
		return($list);
503
	}
504
}
505

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

    
510
if ($input_errors) {
511
	print_input_errors($input_errors);
512
}
513

    
514
if ($savemsg) {
515
	print_info_box($savemsg, 'success');
516
}
517

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

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

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

    
537
$section = new Form_Section('Backup Configuration');
538

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

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

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

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

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

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

    
583
$section->add($group);
584
$form->add($section);
585

    
586
$section = new Form_Section('Restore Backup');
587

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

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

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

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

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

    
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
	'restore',
626
	'Restore Configuration',
627
	null,
628
	'fa-undo'
629
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
630

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

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

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

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

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

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

    
661
		$section->add($group);
662
	}
663

    
664
	$form->add($section);
665
}
666

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

    
673
	// ------- Show/hide sections based on checkbox settings --------------------------------------
674

    
675
	function hideSections(hide) {
676
		hidePasswords();
677
	}
678

    
679
	function hidePasswords() {
680

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

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

    
690
	// ---------- Click handlers ------------------------------------------------------------------
691

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

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

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

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

    
715
<?php
716
include("foot.inc");
717

    
718
if (is_subsystem_dirty('restore')) {
719
	system_reboot();
720
}
(10-10/235)