Project

General

Profile

Download (23.1 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-2016 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

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

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

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

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

    
121
function add_base_packages_menu_items() {
122
	global $g, $config;
123
	$base_packages = explode(",", $g['base_packages']);
124
	$modified_config = false;
125
	foreach ($base_packages as $bp) {
126
		$basepkg_path = "/usr/local/pkg/{$bp}";
127
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
128
		if ($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
129
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
130
			if ($pkg_config['menu'] != "") {
131
				if (is_array($pkg_config['menu'])) {
132
					foreach ($pkg_config['menu'] as $menu) {
133
						if (is_array($config['installedpackages']['menu'])) {
134
							foreach ($config['installedpackages']['menu'] as $amenu) {
135
								if ($amenu['name'] == $menu['name']) {
136
									continue;
137
								}
138
							}
139
						}
140
						$config['installedpackages']['menu'][] = $menu;
141
						$modified_config = true;
142
					}
143
				}
144
			}
145
		}
146
	}
147
	if ($modified_config) {
148
		write_config(gettext("Restored base_package menus after configuration restore."));
149
		$config = parse_config(true);
150
	}
151
}
152

    
153
function remove_bad_chars($string) {
154
	return preg_replace('/[^a-z_0-9]/i', '', $string);
155
}
156

    
157
function check_and_returnif_section_exists($section) {
158
	global $config;
159
	if (is_array($config[$section])) {
160
		return true;
161
	}
162
	return false;
163
}
164

    
165
if ($_POST['apply']) {
166
	ob_flush();
167
	flush();
168
	clear_subsystem_dirty("restore");
169
	exit;
170
}
171

    
172
if ($_POST) {
173
	unset($input_errors);
174
	if (stristr($_POST['Submit'], gettext("Restore configuration"))) {
175
		$mode = "restore";
176
	} else if (stristr($_POST['Submit'], gettext("Reinstall"))) {
177
		$mode = "reinstallpackages";
178
	} else if (stristr($_POST['Submit'], gettext("Clear Package Lock"))) {
179
		$mode = "clearpackagelock";
180
	} else if (stristr($_POST['Submit'], gettext("Download"))) {
181
		$mode = "download";
182
	} else if (stristr($_POST['Submit'], gettext("Restore version"))) {
183
		$mode = "restore_ver";
184
	}
185
	if ($_POST["nopackages"] <> "") {
186
		$options = "nopackages";
187
	}
188
	if ($_POST["ver"] <> "") {
189
		$ver2restore = $_POST["ver"];
190
	}
191
	if ($mode) {
192
		if ($mode == "download") {
193
			if ($_POST['encrypt']) {
194
				if (!$_POST['encrypt_password']) {
195
					$input_errors[] = gettext("A password for encryption must be supplied and confirmed.");
196
				}
197
			}
198

    
199
			if (!$input_errors) {
200

    
201
				//$lockbckp = lock('config');
202

    
203
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
204
				$name = "config-{$host}-".date("YmdHis").".xml";
205
				$data = "";
206

    
207
				if ($options == "nopackages") {
208
					if (!$_POST['backuparea']) {
209
						/* backup entire configuration */
210
						$data = file_get_contents("{$g['conf_path']}/config.xml");
211
					} else {
212
						/* backup specific area of configuration */
213
						$data = backup_config_section($_POST['backuparea']);
214
						$name = "{$_POST['backuparea']}-{$name}";
215
					}
216
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
217
					file_put_contents($sfn, $data);
218
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
219
					$data = file_get_contents($sfn . "-new");
220
				} else {
221
					if (!$_POST['backuparea']) {
222
						/* backup entire configuration */
223
						$data = file_get_contents("{$g['conf_path']}/config.xml");
224
					} else if ($_POST['backuparea'] === "rrddata") {
225
						$data = rrd_data_xml();
226
						$name = "{$_POST['backuparea']}-{$name}";
227
					} else {
228
						/* backup specific area of configuration */
229
						$data = backup_config_section($_POST['backuparea']);
230
						$name = "{$_POST['backuparea']}-{$name}";
231
					}
232
				}
233

    
234
				//unlock($lockbckp);
235

    
236
				/*
237
				 *	Backup RRD Data
238
				 */
239
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
240
					$rrd_data_xml = rrd_data_xml();
241
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
242
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
243
				}
244

    
245
				if ($_POST['encrypt']) {
246
					$data = encrypt_data($data, $_POST['encrypt_password']);
247
					tagfile_reformat($data, $data, "config.xml");
248
				}
249

    
250
				$size = strlen($data);
251
				header("Content-Type: application/octet-stream");
252
				header("Content-Disposition: attachment; filename={$name}");
253
				header("Content-Length: $size");
254
				if (isset($_SERVER['HTTPS'])) {
255
					header('Pragma: ');
256
					header('Cache-Control: ');
257
				} else {
258
					header("Pragma: private");
259
					header("Cache-Control: private, must-revalidate");
260
				}
261
				echo $data;
262

    
263
				exit;
264
			}
265
		}
266

    
267
		if ($mode == "restore") {
268
			if ($_POST['decrypt']) {
269
				if (!$_POST['decrypt_password']) {
270
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
271
				}
272
			}
273

    
274
			if (!$input_errors) {
275
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
276

    
277
					/* read the file contents */
278
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
279
					if (!$data) {
280
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
281
						return 1;
282
					}
283

    
284
					if ($_POST['decrypt']) {
285
						if (!tagfile_deformat($data, $data, "config.xml")) {
286
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
287
							return 1;
288
						}
289
						$data = decrypt_data($data, $_POST['decrypt_password']);
290
					}
291

    
292
					if (stristr($data, "<m0n0wall>")) {
293
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
294
						/* m0n0wall was found in config.  convert it. */
295
						$data = str_replace("m0n0wall", "pfsense", $data);
296
						$m0n0wall_upgrade = true;
297
					}
298
					if ($_POST['restorearea']) {
299
						/* restore a specific area of the configuration */
300
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
301
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
302
						} else {
303
							if (!restore_config_section($_POST['restorearea'], $data)) {
304
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
305
							} else {
306
								if ($config['rrddata']) {
307
									restore_rrddata();
308
									unset($config['rrddata']);
309
									unlink_if_exists("{$g['tmp_path']}/config.cache");
310
									write_config();
311
									add_base_packages_menu_items();
312
									convert_config();
313
								}
314
								filter_configure();
315
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
316
							}
317
						}
318
					} else {
319
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
320
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
321
						} else {
322
							/* restore the entire configuration */
323
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
324
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
325
								/* this will be picked up by /index.php */
326
								mark_subsystem_dirty("restore");
327
								touch("/conf/needs_package_sync_after_reboot");
328
								/* remove cache, we will force a config reboot */
329
								if (file_exists("{$g['tmp_path']}/config.cache")) {
330
									unlink("{$g['tmp_path']}/config.cache");
331
								}
332
								$config = parse_config(true);
333
								if (file_exists("/boot/loader.conf")) {
334
									$loaderconf = file_get_contents("/boot/loader.conf");
335
									if (strpos($loaderconf, "console=\"comconsole")) {
336
										$config['system']['enableserial'] = true;
337
										write_config(gettext("Restore serial console enabling in configuration."));
338
									}
339
									unset($loaderconf);
340
								}
341
								/* extract out rrd items, unset from $config when done */
342
								if ($config['rrddata']) {
343
									restore_rrddata();
344
									unset($config['rrddata']);
345
									unlink_if_exists("{$g['tmp_path']}/config.cache");
346
									write_config();
347
									add_base_packages_menu_items();
348
									convert_config();
349
								}
350
								if ($m0n0wall_upgrade == true) {
351
									if ($config['system']['gateway'] <> "") {
352
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
353
									}
354
									unset($config['shaper']);
355
									/* optional if list */
356
									$ifdescrs = get_configured_interface_list(true, true);
357
									/* remove special characters from interface descriptions */
358
									if (is_array($ifdescrs)) {
359
										foreach ($ifdescrs as $iface) {
360
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
361
										}
362
									}
363
									/* check for interface names with an alias */
364
									if (is_array($ifdescrs)) {
365
										foreach ($ifdescrs as $iface) {
366
											if (is_alias($config['interfaces'][$iface]['descr'])) {
367
												// Firewall rules
368
												$origname = $config['interfaces'][$iface]['descr'];
369
												$newname = $config['interfaces'][$iface]['descr'] . "Alias";
370
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
371
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
372
												// NAT Rules
373
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
374
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
375
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
376
												// Alias in an alias
377
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $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();
408
									add_base_packages_menu_items();
409
									convert_config();
410
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
411
									mark_subsystem_dirty("restore");
412
								}
413
								if (is_array($config['captiveportal'])) {
414
									foreach ($config['captiveportal'] as $cp) {
415
										if (isset($cp['enable'])) {
416
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
417
											mark_subsystem_dirty("restore");
418
											break;
419
										}
420
									}
421
								}
422
								setup_serial_port();
423
								if (is_interface_mismatch() == true) {
424
									touch("/var/run/interface_mismatch_reboot_needed");
425
									clear_subsystem_dirty("restore");
426
									convert_config();
427
									header("Location: interfaces_assign.php");
428
									exit;
429
								}
430
								if (is_interface_vlan_mismatch() == true) {
431
									touch("/var/run/interface_mismatch_reboot_needed");
432
									clear_subsystem_dirty("restore");
433
									convert_config();
434
									header("Location: interfaces_assign.php");
435
									exit;
436
								}
437
							} else {
438
								$input_errors[] = gettext("The configuration could not be restored.");
439
							}
440
						}
441
					}
442
				} else {
443
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
444
				}
445
			}
446
		}
447

    
448
		if ($mode == "reinstallpackages") {
449
			header("Location: pkg_mgr_install.php?mode=reinstallall");
450
			exit;
451
		} else if ($mode == "clearpackagelock") {
452
			clear_subsystem_dirty('packagelock');
453
			$savemsg = "Package lock cleared.";
454
		} else if ($mode == "restore_ver") {
455
			$input_errors[] = gettext("XXX - this feature may hose the config (do NOT backrev configs!) - billm");
456
			if ($ver2restore <> "") {
457
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
458
				if (config_install($conf_file) == 0) {
459
					mark_subsystem_dirty("restore");
460
				} else {
461
					$input_errors[] = gettext("The configuration could not be restored.");
462
				}
463
			} else {
464
				$input_errors[] = gettext("No version selected.");
465
			}
466
		}
467
	}
468
}
469

    
470
$id = rand() . '.' . time();
471

    
472
$mth = ini_get('upload_progress_meter.store_method');
473
$dir = ini_get('upload_progress_meter.file.filename_template');
474

    
475
function build_area_list($showall) {
476
	global $config;
477

    
478
	$areas = array(
479
		"aliases" => gettext("Aliases"),
480
		"captiveportal" => gettext("Captive Portal"),
481
		"voucher" => gettext("Captive Portal Vouchers"),
482
		"dnsmasq" => gettext("DNS Forwarder"),
483
		"unbound" => gettext("DNS Resolver"),
484
		"dhcpd" => gettext("DHCP Server"),
485
		"dhcpdv6" => gettext("DHCPv6 Server"),
486
		"filter" => gettext("Firewall Rules"),
487
		"interfaces" => gettext("Interfaces"),
488
		"ipsec" => gettext("IPSEC"),
489
		"nat" => gettext("NAT"),
490
		"openvpn" => gettext("OpenVPN"),
491
		"installedpackages" => gettext("Package Manager"),
492
		"rrddata" => gettext("RRD Data"),
493
		"cron" => gettext("Scheduled Tasks"),
494
		"syslog" => gettext("Syslog"),
495
		"system" => gettext("System"),
496
		"staticroutes" => gettext("Static routes"),
497
		"sysctl" => gettext("System tunables"),
498
		"snmpd" => gettext("SNMP Server"),
499
		"shaper" => gettext("Traffic Shaper"),
500
		"vlans" => gettext("VLANS"),
501
		"wol" => gettext("Wake-on-LAN")
502
		);
503

    
504
	$list = array("" => gettext("All"));
505

    
506
	if ($showall) {
507
		return($list + $areas);
508
	} else {
509
		foreach ($areas as $area => $areaname) {
510
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
511
				$list[$area] = $areaname;
512
			}
513
		}
514

    
515
		return($list);
516
	}
517
}
518

    
519
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
520
$pglinks = array("", "@self", "@self");
521
include("head.inc");
522

    
523
if ($input_errors) {
524
	print_input_errors($input_errors);
525
}
526

    
527
if ($savemsg) {
528
	print_info_box($savemsg, 'success');
529
}
530

    
531
if (is_subsystem_dirty('restore')):
532
?>
533
	<br/>
534
	<form action="diag_reboot.php" method="post">
535
		<input name="Submit" type="hidden" value="Yes" />
536
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
537
		<br />
538
	</form>
539
<?php
540
endif;
541

    
542
$tab_array = array();
543
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
544
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
545
display_top_tabs($tab_array);
546

    
547
$form = new Form(false);
548
$form->setMultipartEncoding();	// Allow file uploads
549

    
550
$section = new Form_Section('Backup Configuration');
551

    
552
$section->addInput(new Form_Select(
553
	'backuparea',
554
	'Backup area',
555
	'',
556
	build_area_list(false)
557
));
558

    
559
$section->addInput(new Form_Checkbox(
560
	'nopackages',
561
	'Skip packages',
562
	'Do not backup package information.',
563
	false
564
));
565

    
566
$section->addInput(new Form_Checkbox(
567
	'donotbackuprrd',
568
	'Skip RRD data',
569
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
570
	true
571
));
572

    
573
$section->addInput(new Form_Checkbox(
574
	'encrypt',
575
	'Encryption',
576
	'Encrypt this configuration file.',
577
	false
578
));
579

    
580
$section->addInput(new Form_Input(
581
	'encrypt_password',
582
	'Password',
583
	'password',
584
	null
585
));
586

    
587
$group = new Form_Group('');
588
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
589
$group->add(new Form_Button(
590
	'Submit',
591
	'Download configuration as XML',
592
	null,
593
	'fa-download'
594
))->setAttribute('id')->addClass('btn-primary');
595

    
596
$section->add($group);
597
$form->add($section);
598

    
599
$section = new Form_Section('Restore Backup');
600

    
601
$section->addInput(new Form_StaticText(
602
	null,
603
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
604
));
605

    
606
$section->addInput(new Form_Select(
607
	'restorearea',
608
	'Restore area',
609
	'',
610
	build_area_list(true)
611
));
612

    
613
$section->addInput(new Form_Input(
614
	'conffile',
615
	'Configuration file',
616
	'file',
617
	null
618
));
619

    
620
$section->addInput(new Form_Checkbox(
621
	'decrypt',
622
	'Encryption',
623
	'Configuration file is encrypted.',
624
	false
625
));
626

    
627
$section->addInput(new Form_Input(
628
	'decrypt_password',
629
	'Password',
630
	'password',
631
	null,
632
	['placeholder' => 'Password']
633
));
634

    
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
	'Submit',
639
	'Restore Configuration',
640
	null,
641
	'fa-undo'
642
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
643

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

    
646
$form->add($section);
647

    
648
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
649
	$section = new Form_Section('Package Functions');
650

    
651
	if ($config['installedpackages']['package'] != "") {
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
			'Submit',
656
			'Reinstall Packages',
657
			null,
658
			'fa-retweet'
659
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
660

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

    
664
	if (is_subsystem_dirty("packagelock")) {
665
		$group = new Form_Group('');
666
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
667
		$group->add(new Form_Button(
668
			'Submit',
669
			'Clear Package Lock',
670
			null,
671
			'fa-wrench'
672
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
673

    
674
		$section->add($group);
675
	}
676

    
677
	$form->add($section);
678
}
679

    
680
print($form);
681
?>
682
<script type="text/javascript">
683
//<![CDATA[
684
events.push(function() {
685

    
686
	// ------- Show/hide sections based on checkbox settings --------------------------------------
687

    
688
	function hideSections(hide) {
689
		hidePasswords();
690
	}
691

    
692
	function hidePasswords() {
693

    
694
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
695
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
696

    
697
		hideInput('encrypt_password', encryptHide);
698
		hideInput('encrypt_password_confirm', encryptHide);
699
		hideInput('decrypt_password', decryptHide);
700
		hideInput('decrypt_password_confirm', decryptHide);
701
	}
702

    
703
	// ---------- Click handlers ------------------------------------------------------------------
704

    
705
	$('input[name="encrypt"]').on('change', function() {
706
		hidePasswords();
707
	});
708

    
709
	$('input[name="decrypt"]').on('change', function() {
710
		hidePasswords();
711
	});
712

    
713
	$('#conffile').change(function () {
714
		if (document.getElementById("conffile").value) {
715
			$('.restore').prop('disabled', false);
716
		} else {
717
			$('.restore').prop('disabled', true);
718
		}
719
    });
720
	// ---------- On initial page load ------------------------------------------------------------
721

    
722
	hideSections();
723
	$('.restore').prop('disabled', true);
724
});
725
//]]>
726
</script>
727

    
728
<?php
729
include("foot.inc");
730

    
731
if (is_subsystem_dirty('restore')) {
732
	system_reboot();
733
}
(6-6/225)