Project

General

Profile

Download (21.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-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 remove_bad_chars($string) {
122
	return preg_replace('/[^a-z_0-9]/i', '', $string);
123
}
124

    
125
function check_and_returnif_section_exists($section) {
126
	global $config;
127
	if (is_array($config[$section])) {
128
		return true;
129
	}
130
	return false;
131
}
132

    
133
if ($_POST['apply']) {
134
	ob_flush();
135
	flush();
136
	clear_subsystem_dirty("restore");
137
	exit;
138
}
139

    
140
if ($_POST) {
141
	unset($input_errors);
142
	if ($_POST['restore']) {
143
		$mode = "restore";
144
	} else if ($_POST['reinstallpackages']) {
145
		$mode = "reinstallpackages";
146
	} else if ($_POST['clearpackagelock']) {
147
		$mode = "clearpackagelock";
148
	} else if ($_POST['download']) {
149
		$mode = "download";
150
	}
151
	if ($_POST["nopackages"] <> "") {
152
		$options = "nopackages";
153
	}
154
	if ($_POST["ver"] <> "") {
155
		$ver2restore = $_POST["ver"];
156
	}
157
	if ($mode) {
158
		if ($mode == "download") {
159
			if ($_POST['encrypt']) {
160
				if (!$_POST['encrypt_password']) {
161
					$input_errors[] = gettext("A password for encryption must be supplied and confirmed.");
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
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
183
					file_put_contents($sfn, $data);
184
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
185
					$data = file_get_contents($sfn . "-new");
186
				} else {
187
					if (!$_POST['backuparea']) {
188
						/* backup entire configuration */
189
						$data = file_get_contents("{$g['conf_path']}/config.xml");
190
					} else if ($_POST['backuparea'] === "rrddata") {
191
						$data = rrd_data_xml();
192
						$name = "{$_POST['backuparea']}-{$name}";
193
					} else {
194
						/* backup specific area of configuration */
195
						$data = backup_config_section($_POST['backuparea']);
196
						$name = "{$_POST['backuparea']}-{$name}";
197
					}
198
				}
199

    
200
				//unlock($lockbckp);
201

    
202
				/*
203
				 *	Backup RRD Data
204
				 */
205
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
206
					$rrd_data_xml = rrd_data_xml();
207
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
208
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
209
				}
210

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

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

    
229
				exit;
230
			}
231
		}
232

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

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

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

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

    
258
					if (stristr($data, "<m0n0wall>")) {
259
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
260
						/* m0n0wall was found in config.  convert it. */
261
						$data = str_replace("m0n0wall", "pfsense", $data);
262
						$m0n0wall_upgrade = true;
263
					}
264
					if ($_POST['restorearea']) {
265
						/* restore a specific area of the configuration */
266
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
267
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
268
						} else {
269
							if (!restore_config_section($_POST['restorearea'], $data)) {
270
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
271
							} else {
272
								if ($config['rrddata']) {
273
									restore_rrddata();
274
									unset($config['rrddata']);
275
									unlink_if_exists("{$g['tmp_path']}/config.cache");
276
									write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea']));
277
									convert_config();
278
								}
279
								filter_configure();
280
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
281
							}
282
						}
283
					} else {
284
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
285
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
286
						} else {
287
							/* restore the entire configuration */
288
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
289
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
290
								/* this will be picked up by /index.php */
291
								mark_subsystem_dirty("restore");
292
								touch("/conf/needs_package_sync_after_reboot");
293
								/* remove cache, we will force a config reboot */
294
								if (file_exists("{$g['tmp_path']}/config.cache")) {
295
									unlink("{$g['tmp_path']}/config.cache");
296
								}
297
								$config = parse_config(true);
298
								if (file_exists("/boot/loader.conf")) {
299
									$loaderconf = file_get_contents("/boot/loader.conf");
300
									if (strpos($loaderconf, "console=\"comconsole")) {
301
										$config['system']['enableserial'] = true;
302
										write_config(gettext("Restore serial console enabling in configuration."));
303
									}
304
									unset($loaderconf);
305
								}
306
								/* extract out rrd items, unset from $config when done */
307
								if ($config['rrddata']) {
308
									restore_rrddata();
309
									unset($config['rrddata']);
310
									unlink_if_exists("{$g['tmp_path']}/config.cache");
311
									write_config(gettext("Unset RRD data from configuration after restoring full configuration"));
312
									convert_config();
313
								}
314
								if ($m0n0wall_upgrade == true) {
315
									if ($config['system']['gateway'] <> "") {
316
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
317
									}
318
									unset($config['shaper']);
319
									/* optional if list */
320
									$ifdescrs = get_configured_interface_list(true, true);
321
									/* remove special characters from interface descriptions */
322
									if (is_array($ifdescrs)) {
323
										foreach ($ifdescrs as $iface) {
324
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
325
										}
326
									}
327
									/* check for interface names with an alias */
328
									if (is_array($ifdescrs)) {
329
										foreach ($ifdescrs as $iface) {
330
											if (is_alias($config['interfaces'][$iface]['descr'])) {
331
												// Firewall rules
332
												$origname = $config['interfaces'][$iface]['descr'];
333
												$newname = $config['interfaces'][$iface]['descr'] . "Alias";
334
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
335
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
336
												// NAT Rules
337
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
338
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
339
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
340
												// Alias in an alias
341
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
342
											}
343
										}
344
									}
345
									unlink_if_exists("{$g['tmp_path']}/config.cache");
346
									// Reset configuration version to something low
347
									// in order to force the config upgrade code to
348
									// run through with all steps that are required.
349
									$config['system']['version'] = "1.0";
350
									// Deal with descriptions longer than 63 characters
351
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
352
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
353
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
354
										}
355
									}
356
									// Move interface from ipsec to enc0
357
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
358
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
359
											$config['filter']['rule'][$i]['interface'] = "enc0";
360
										}
361
									}
362
									// Convert icmp types
363
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
364
									$convert = array('echo' => 'echoreq', 'timest' => 'timereq', 'timestrep' => 'timerep');
365
									foreach ($config["filter"]["rule"] as $ruleid => &$ruledata) {
366
										if ($convert[$ruledata['icmptype']]) {
367
											$ruledata['icmptype'] = $convert[$ruledata['icmptype']];
368
										}
369
									}
370
									$config['diag']['ipv6nat'] = true;
371
									write_config(gettext("Imported m0n0wall configuration"));
372
									convert_config();
373
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
374
									mark_subsystem_dirty("restore");
375
								}
376
								if (is_array($config['captiveportal'])) {
377
									foreach ($config['captiveportal'] as $cp) {
378
										if (isset($cp['enable'])) {
379
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
380
											mark_subsystem_dirty("restore");
381
											break;
382
										}
383
									}
384
								}
385
								setup_serial_port();
386
								if (is_interface_mismatch() == true) {
387
									touch("/var/run/interface_mismatch_reboot_needed");
388
									clear_subsystem_dirty("restore");
389
									convert_config();
390
									header("Location: interfaces_assign.php");
391
									exit;
392
								}
393
								if (is_interface_vlan_mismatch() == true) {
394
									touch("/var/run/interface_mismatch_reboot_needed");
395
									clear_subsystem_dirty("restore");
396
									convert_config();
397
									header("Location: interfaces_assign.php");
398
									exit;
399
								}
400
							} else {
401
								$input_errors[] = gettext("The configuration could not be restored.");
402
							}
403
						}
404
					}
405
				} else {
406
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
407
				}
408
			}
409
		}
410

    
411
		if ($mode == "reinstallpackages") {
412
			header("Location: pkg_mgr_install.php?mode=reinstallall");
413
			exit;
414
		} else if ($mode == "clearpackagelock") {
415
			clear_subsystem_dirty('packagelock');
416
			$savemsg = "Package lock cleared.";
417
		}
418
	}
419
}
420

    
421
$id = rand() . '.' . time();
422

    
423
$mth = ini_get('upload_progress_meter.store_method');
424
$dir = ini_get('upload_progress_meter.file.filename_template');
425

    
426
function build_area_list($showall) {
427
	global $config;
428

    
429
	$areas = array(
430
		"aliases" => gettext("Aliases"),
431
		"captiveportal" => gettext("Captive Portal"),
432
		"voucher" => gettext("Captive Portal Vouchers"),
433
		"dnsmasq" => gettext("DNS Forwarder"),
434
		"unbound" => gettext("DNS Resolver"),
435
		"dhcpd" => gettext("DHCP Server"),
436
		"dhcpdv6" => gettext("DHCPv6 Server"),
437
		"filter" => gettext("Firewall Rules"),
438
		"interfaces" => gettext("Interfaces"),
439
		"ipsec" => gettext("IPSEC"),
440
		"nat" => gettext("NAT"),
441
		"openvpn" => gettext("OpenVPN"),
442
		"installedpackages" => gettext("Package Manager"),
443
		"rrddata" => gettext("RRD Data"),
444
		"cron" => gettext("Scheduled Tasks"),
445
		"syslog" => gettext("Syslog"),
446
		"system" => gettext("System"),
447
		"staticroutes" => gettext("Static routes"),
448
		"sysctl" => gettext("System tunables"),
449
		"snmpd" => gettext("SNMP Server"),
450
		"shaper" => gettext("Traffic Shaper"),
451
		"vlans" => gettext("VLANS"),
452
		"wol" => gettext("Wake-on-LAN")
453
		);
454

    
455
	$list = array("" => gettext("All"));
456

    
457
	if ($showall) {
458
		return($list + $areas);
459
	} else {
460
		foreach ($areas as $area => $areaname) {
461
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
462
				$list[$area] = $areaname;
463
			}
464
		}
465

    
466
		return($list);
467
	}
468
}
469

    
470
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
471
$pglinks = array("", "@self", "@self");
472
include("head.inc");
473

    
474
if ($input_errors) {
475
	print_input_errors($input_errors);
476
}
477

    
478
if ($savemsg) {
479
	print_info_box($savemsg, 'success');
480
}
481

    
482
if (is_subsystem_dirty('restore')):
483
?>
484
	<br/>
485
	<form action="diag_reboot.php" method="post">
486
		<input name="Submit" type="hidden" value="Yes" />
487
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
488
		<br />
489
	</form>
490
<?php
491
endif;
492

    
493
$tab_array = array();
494
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
495
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
496
display_top_tabs($tab_array);
497

    
498
$form = new Form(false);
499
$form->setMultipartEncoding();	// Allow file uploads
500

    
501
$section = new Form_Section('Backup Configuration');
502

    
503
$section->addInput(new Form_Select(
504
	'backuparea',
505
	'Backup area',
506
	'',
507
	build_area_list(false)
508
));
509

    
510
$section->addInput(new Form_Checkbox(
511
	'nopackages',
512
	'Skip packages',
513
	'Do not backup package information.',
514
	false
515
));
516

    
517
$section->addInput(new Form_Checkbox(
518
	'donotbackuprrd',
519
	'Skip RRD data',
520
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
521
	true
522
));
523

    
524
$section->addInput(new Form_Checkbox(
525
	'encrypt',
526
	'Encryption',
527
	'Encrypt this configuration file.',
528
	false
529
));
530

    
531
$section->addInput(new Form_Input(
532
	'encrypt_password',
533
	'Password',
534
	'password',
535
	null
536
));
537

    
538
$group = new Form_Group('');
539
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
540
$group->add(new Form_Button(
541
	'download',
542
	'Download configuration as XML',
543
	null,
544
	'fa-download'
545
))->setAttribute('id')->addClass('btn-primary');
546

    
547
$section->add($group);
548
$form->add($section);
549

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

    
552
$section->addInput(new Form_StaticText(
553
	null,
554
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
555
));
556

    
557
$section->addInput(new Form_Select(
558
	'restorearea',
559
	'Restore area',
560
	'',
561
	build_area_list(true)
562
));
563

    
564
$section->addInput(new Form_Input(
565
	'conffile',
566
	'Configuration file',
567
	'file',
568
	null
569
));
570

    
571
$section->addInput(new Form_Checkbox(
572
	'decrypt',
573
	'Encryption',
574
	'Configuration file is encrypted.',
575
	false
576
));
577

    
578
$section->addInput(new Form_Input(
579
	'decrypt_password',
580
	'Password',
581
	'password',
582
	null,
583
	['placeholder' => 'Password']
584
));
585

    
586
$group = new Form_Group('');
587
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
588
$group->add(new Form_Button(
589
	'restore',
590
	'Restore Configuration',
591
	null,
592
	'fa-undo'
593
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
594

    
595
$section->add($group);
596

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

    
599
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
600
	$section = new Form_Section('Package Functions');
601

    
602
	if ($config['installedpackages']['package'] != "") {
603
		$group = new Form_Group('');
604
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
605
		$group->add(new Form_Button(
606
			'reinstallpackages',
607
			'Reinstall Packages',
608
			null,
609
			'fa-retweet'
610
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
611

    
612
		$section->add($group);
613
	}
614

    
615
	if (is_subsystem_dirty("packagelock")) {
616
		$group = new Form_Group('');
617
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
618
		$group->add(new Form_Button(
619
			'clearpackagelock',
620
			'Clear Package Lock',
621
			null,
622
			'fa-wrench'
623
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
624

    
625
		$section->add($group);
626
	}
627

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

    
631
print($form);
632
?>
633
<script type="text/javascript">
634
//<![CDATA[
635
events.push(function() {
636

    
637
	// ------- Show/hide sections based on checkbox settings --------------------------------------
638

    
639
	function hideSections(hide) {
640
		hidePasswords();
641
	}
642

    
643
	function hidePasswords() {
644

    
645
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
646
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
647

    
648
		hideInput('encrypt_password', encryptHide);
649
		hideInput('encrypt_password_confirm', encryptHide);
650
		hideInput('decrypt_password', decryptHide);
651
		hideInput('decrypt_password_confirm', decryptHide);
652
	}
653

    
654
	// ---------- Click handlers ------------------------------------------------------------------
655

    
656
	$('input[name="encrypt"]').on('change', function() {
657
		hidePasswords();
658
	});
659

    
660
	$('input[name="decrypt"]').on('change', function() {
661
		hidePasswords();
662
	});
663

    
664
	$('#conffile').change(function () {
665
		if (document.getElementById("conffile").value) {
666
			$('.restore').prop('disabled', false);
667
		} else {
668
			$('.restore').prop('disabled', true);
669
		}
670
    });
671
	// ---------- On initial page load ------------------------------------------------------------
672

    
673
	hideSections();
674
	$('.restore').prop('disabled', true);
675
});
676
//]]>
677
</script>
678

    
679
<?php
680
include("foot.inc");
681

    
682
if (is_subsystem_dirty('restore')) {
683
	system_reboot();
684
}
(6-6/223)