Project

General

Profile

Download (25.3 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_backup.php
5
*/
6
/* ====================================================================
7
 *	Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
8
 *	Copyright (c)  2004, 2005 Scott Ullrich
9
 *
10
 *	Redistribution and use in source and binary forms, with or without modification,
11
 *	are permitted provided that the following conditions are met:
12
 *
13
 *	1. Redistributions of source code must retain the above copyright notice,
14
 *		this list of conditions and the following disclaimer.
15
 *
16
 *	2. Redistributions in binary form must reproduce the above copyright
17
 *		notice, this list of conditions and the following disclaimer in
18
 *		the documentation and/or other materials provided with the
19
 *		distribution.
20
 *
21
 *	3. All advertising materials mentioning features or use of this software
22
 *		must display the following acknowledgment:
23
 *		"This product includes software developed by the pfSense Project
24
 *		 for use in the pfSense software distribution. (http://www.pfsense.org/).
25
 *
26
 *	4. The names "pfSense" and "pfSense Project" must not be used to
27
 *		 endorse or promote products derived from this software without
28
 *		 prior written permission. For written permission, please contact
29
 *		 coreteam@pfsense.org.
30
 *
31
 *	5. Products derived from this software may not be called "pfSense"
32
 *		nor may "pfSense" appear in their names without prior written
33
 *		permission of the Electric Sheep Fencing, LLC.
34
 *
35
 *	6. Redistributions of any form whatsoever must retain the following
36
 *		acknowledgment:
37
 *
38
 *	"This product includes software developed by the pfSense Project
39
 *	for use in the pfSense software distribution (http://www.pfsense.org/).
40
  *
41
 *	THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 *	EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 *	IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 *	PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 *	ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 *	SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 *	NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 *	HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 *	STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 *	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 *	OF THE POSSIBILITY OF SUCH DAMAGE.
53
 *
54
 *	====================================================================
55
 *
56
 */
57

    
58
/*
59
	pfSense_BUILDER_BINARIES:	/sbin/shutdown
60
	pfSense_MODULE: backup
61
*/
62

    
63
##|+PRIV
64
##|*IDENT=page-diagnostics-backup/restore
65
##|*NAME=Diagnostics: Backup/restore page
66
##|*DESCR=Allow access to the 'Diagnostics: Backup/restore' page.
67
##|*MATCH=diag_backup.php*
68
##|-PRIV
69

    
70
/* Allow additional execution time 0 = no limit. */
71
ini_set('max_execution_time', '0');
72
ini_set('max_input_time', '0');
73

    
74
/* omit no-cache headers because it confuses IE with file downloads */
75
$omit_nocacheheaders = true;
76
$nocsrf = true;
77
require("guiconfig.inc");
78
require_once("functions.inc");
79
require_once("filter.inc");
80
require_once("shaper.inc");
81

    
82
$rrddbpath = "/var/db/rrd";
83
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
84

    
85
function rrd_data_xml() {
86
	global $rrddbpath;
87
	global $rrdtool;
88

    
89
	$result = "\t<rrddata>\n";
90
	$rrd_files = glob("{$rrddbpath}/*.rrd");
91
	$xml_files = array();
92
	foreach ($rrd_files as $rrd_file) {
93
		$basename = basename($rrd_file);
94
		$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
95
		exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
96
		$xml_data = file_get_contents($xml_file);
97
		unlink($xml_file);
98
		if ($xml_data !== false) {
99
			$result .= "\t\t<rrddatafile>\n";
100
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
101
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
102
			$result .= "\t\t</rrddatafile>\n";
103
		}
104
	}
105
	$result .= "\t</rrddata>\n";
106
	return $result;
107
}
108

    
109
function restore_rrddata() {
110
	global $config, $g, $rrdtool, $input_errors;
111
	foreach ($config['rrddata']['rrddatafile'] as $rrd) {
112
		if ($rrd['xmldata']) {
113
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
114
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
115
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
116
				log_error("Cannot write $xml_file");
117
				continue;
118
			}
119
			$output = array();
120
			$status = null;
121
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
122
			if ($status) {
123
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
124
				continue;
125
			}
126
			unlink($xml_file);
127
		} else if ($rrd['data']) {
128
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
129
			$rrd_fd = fopen($rrd_file, "w");
130
			if (!$rrd_fd) {
131
				log_error("Cannot write $rrd_file");
132
				continue;
133
			}
134
			$data = base64_decode($rrd['data']);
135
			/* Try to decompress the data. */
136
			$dcomp = @gzinflate($data);
137
			if ($dcomp) {
138
				/* If the decompression worked, write the decompressed data */
139
				if (fwrite($rrd_fd, $dcomp) === false) {
140
					log_error("fwrite $rrd_file failed");
141
					continue;
142
				}
143
			} else {
144
				/* If the decompression failed, it wasn't compressed, so write raw data */
145
				if (fwrite($rrd_fd, $data) === false) {
146
					log_error("fwrite $rrd_file failed");
147
					continue;
148
				}
149
			}
150
			if (fclose($rrd_fd) === false) {
151
				log_error("fclose $rrd_file failed");
152
				continue;
153
			}
154
		}
155
	}
156
}
157

    
158
function add_base_packages_menu_items() {
159
	global $g, $config;
160
	$base_packages = explode(",", $g['base_packages']);
161
	$modified_config = false;
162
	foreach ($base_packages as $bp) {
163
		$basepkg_path = "/usr/local/pkg/{$bp}";
164
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
165
		if ($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
166
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
167
			if ($pkg_config['menu'] != "") {
168
				if (is_array($pkg_config['menu'])) {
169
					foreach ($pkg_config['menu'] as $menu) {
170
						if (is_array($config['installedpackages']['menu'])) {
171
							foreach ($config['installedpackages']['menu'] as $amenu) {
172
								if ($amenu['name'] == $menu['name']) {
173
									continue;
174
								}
175
							}
176
						}
177
						$config['installedpackages']['menu'][] = $menu;
178
						$modified_config = true;
179
					}
180
				}
181
				$static_output .= "done.\n";
182
				update_output_window($static_output);
183
			}
184
		}
185
	}
186
	if ($modified_config) {
187
		write_config(gettext("Restored base_package menus after configuration restore."));
188
		$config = parse_config(true);
189
	}
190
}
191

    
192
function remove_bad_chars($string) {
193
	return preg_replace('/[^a-z_0-9]/i', '', $string);
194
}
195

    
196
function check_and_returnif_section_exists($section) {
197
	global $config;
198
	if (is_array($config[$section])) {
199
		return true;
200
	}
201
	return false;
202
}
203

    
204
if ($_POST['apply']) {
205
	ob_flush();
206
	flush();
207
	conf_mount_rw();
208
	clear_subsystem_dirty("restore");
209
	conf_mount_ro();
210
	exit;
211
}
212

    
213
if ($_POST) {
214
	unset($input_errors);
215
	if (stristr($_POST['Submit'], gettext("Restore configuration"))) {
216
		$mode = "restore";
217
	} else if (stristr($_POST['Submit'], gettext("Reinstall"))) {
218
		$mode = "reinstallpackages";
219
	} else if (stristr($_POST['Submit'], gettext("Clear Package Lock"))) {
220
		$mode = "clearpackagelock";
221
	} else if (stristr($_POST['Submit'], gettext("Download"))) {
222
		$mode = "download";
223
	} else if (stristr($_POST['Submit'], gettext("Restore version"))) {
224
		$mode = "restore_ver";
225
	}
226
	if ($_POST["nopackages"] <> "") {
227
		$options = "nopackages";
228
	}
229
	if ($_POST["ver"] <> "") {
230
		$ver2restore = $_POST["ver"];
231
	}
232
	if ($mode) {
233
		if ($mode == "download") {
234
			if ($_POST['encrypt']) {
235
				if (!$_POST['encrypt_password'] || !$_POST['encrypt_passconf']) {
236
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
237
				}
238
				if ($_POST['encrypt_password'] != $_POST['encrypt_passconf']) {
239
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
240
				}
241
			}
242

    
243
			if (!$input_errors) {
244

    
245
				//$lockbckp = lock('config');
246

    
247
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
248
				$name = "config-{$host}-".date("YmdHis").".xml";
249
				$data = "";
250

    
251
				if ($options == "nopackages") {
252
					if (!$_POST['backuparea']) {
253
						/* backup entire configuration */
254
						$data = file_get_contents("{$g['conf_path']}/config.xml");
255
					} else {
256
						/* backup specific area of configuration */
257
						$data = backup_config_section($_POST['backuparea']);
258
						$name = "{$_POST['backuparea']}-{$name}";
259
					}
260
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
261
					file_put_contents($sfn, $data);
262
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
263
					$data = file_get_contents($sfn . "-new");
264
				} else {
265
					if (!$_POST['backuparea']) {
266
						/* backup entire configuration */
267
						$data = file_get_contents("{$g['conf_path']}/config.xml");
268
					} else if ($_POST['backuparea'] === "rrddata") {
269
						$data = rrd_data_xml();
270
						$name = "{$_POST['backuparea']}-{$name}";
271
					} else {
272
						/* backup specific area of configuration */
273
						$data = backup_config_section($_POST['backuparea']);
274
						$name = "{$_POST['backuparea']}-{$name}";
275
					}
276
				}
277

    
278
				//unlock($lockbckp);
279

    
280
				/*
281
				 *	Backup RRD Data
282
				 */
283
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
284
					$rrd_data_xml = rrd_data_xml();
285
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
286
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
287
				}
288

    
289
				if ($_POST['encrypt']) {
290
					$data = encrypt_data($data, $_POST['encrypt_password']);
291
					tagfile_reformat($data, $data, "config.xml");
292
				}
293

    
294
				$size = strlen($data);
295
				header("Content-Type: application/octet-stream");
296
				header("Content-Disposition: attachment; filename={$name}");
297
				header("Content-Length: $size");
298
				if (isset($_SERVER['HTTPS'])) {
299
					header('Pragma: ');
300
					header('Cache-Control: ');
301
				} else {
302
					header("Pragma: private");
303
					header("Cache-Control: private, must-revalidate");
304
				}
305
				echo $data;
306

    
307
				exit;
308
			}
309
		}
310

    
311
		if ($mode == "restore") {
312
			if ($_POST['decrypt']) {
313
				if (!$_POST['decrypt_password'] || !$_POST['decrypt_passconf']) {
314
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
315
				}
316
				if ($_POST['decrypt_password'] != $_POST['decrypt_passconf']) {
317
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
318
				}
319
			}
320

    
321
			if (!$input_errors) {
322
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
323

    
324
					/* read the file contents */
325
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
326
					if (!$data) {
327
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
328
						return 1;
329
					}
330

    
331
					if ($_POST['decrypt']) {
332
						if (!tagfile_deformat($data, $data, "config.xml")) {
333
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
334
							return 1;
335
						}
336
						$data = decrypt_data($data, $_POST['decrypt_password']);
337
					}
338

    
339
					if (stristr($data, "<m0n0wall>")) {
340
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
341
						/* m0n0wall was found in config.  convert it. */
342
						$data = str_replace("m0n0wall", "pfsense", $data);
343
						$m0n0wall_upgrade = true;
344
					}
345
					if ($_POST['restorearea']) {
346
						/* restore a specific area of the configuration */
347
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
348
							$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
349
						} else {
350
							if (!restore_config_section($_POST['restorearea'], $data)) {
351
								$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
352
							} else {
353
								if ($config['rrddata']) {
354
									restore_rrddata();
355
									unset($config['rrddata']);
356
									unlink_if_exists("{$g['tmp_path']}/config.cache");
357
									write_config();
358
									add_base_packages_menu_items();
359
									convert_config();
360
									conf_mount_ro();
361
								}
362
								filter_configure();
363
								$savemsg = gettext("The configuration area has been restored.  You may need to reboot the firewall.");
364
							}
365
						}
366
					} else {
367
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
368
							$input_errors[] = sprintf(gettext("You have selected to restore the full configuration but we could not locate a %s tag."), $g['xml_rootobj']);
369
						} else {
370
							/* restore the entire configuration */
371
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
372
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
373
								/* this will be picked up by /index.php */
374
								conf_mount_rw();
375
								mark_subsystem_dirty("restore");
376
								touch("/conf/needs_package_sync");
377
								/* remove cache, we will force a config reboot */
378
								if (file_exists("{$g['tmp_path']}/config.cache")) {
379
									unlink("{$g['tmp_path']}/config.cache");
380
								}
381
								$config = parse_config(true);
382
								if (file_exists("/boot/loader.conf")) {
383
									$loaderconf = file_get_contents("/boot/loader.conf");
384
									if (strpos($loaderconf, "console=\"comconsole")) {
385
										$config['system']['enableserial'] = true;
386
										write_config("Restore serial console enabling in configuration.");
387
									}
388
									unset($loaderconf);
389
								}
390
								/* extract out rrd items, unset from $config when done */
391
								if ($config['rrddata']) {
392
									restore_rrddata();
393
									unset($config['rrddata']);
394
									unlink_if_exists("{$g['tmp_path']}/config.cache");
395
									write_config();
396
									add_base_packages_menu_items();
397
									convert_config();
398
									conf_mount_ro();
399
								}
400
								if ($m0n0wall_upgrade == true) {
401
									if ($config['system']['gateway'] <> "") {
402
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
403
									}
404
									unset($config['shaper']);
405
									/* optional if list */
406
									$ifdescrs = get_configured_interface_list(true, true);
407
									/* remove special characters from interface descriptions */
408
									if (is_array($ifdescrs)) {
409
										foreach ($ifdescrs as $iface) {
410
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
411
										}
412
									}
413
									/* check for interface names with an alias */
414
									if (is_array($ifdescrs)) {
415
										foreach ($ifdescrs as $iface) {
416
											if (is_alias($config['interfaces'][$iface]['descr'])) {
417
												// Firewall rules
418
												$origname = $config['interfaces'][$iface]['descr'];
419
												$newname = $config['interfaces'][$iface]['descr'] . "Alias";
420
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
421
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
422
												// NAT Rules
423
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
424
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
425
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
426
												// Alias in an alias
427
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
428
											}
429
										}
430
									}
431
									unlink_if_exists("{$g['tmp_path']}/config.cache");
432
									// Reset configuration version to something low
433
									// in order to force the config upgrade code to
434
									// run through with all steps that are required.
435
									$config['system']['version'] = "1.0";
436
									// Deal with descriptions longer than 63 characters
437
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
438
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
439
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
440
										}
441
									}
442
									// Move interface from ipsec to enc0
443
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
444
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
445
											$config['filter']['rule'][$i]['interface'] = "enc0";
446
										}
447
									}
448
									// Convert icmp types
449
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
450
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
451
										if ($config["filter"]["rule"][$i]['icmptype']) {
452
											switch ($config["filter"]["rule"][$i]['icmptype']) {
453
												case "echo":
454
													$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
455
													break;
456
												case "unreach":
457
													$config["filter"]["rule"][$i]['icmptype'] = "unreach";
458
													break;
459
												case "echorep":
460
													$config["filter"]["rule"][$i]['icmptype'] = "echorep";
461
													break;
462
												case "squench":
463
													$config["filter"]["rule"][$i]['icmptype'] = "squench";
464
													break;
465
												case "redir":
466
													$config["filter"]["rule"][$i]['icmptype'] = "redir";
467
													break;
468
												case "timex":
469
													$config["filter"]["rule"][$i]['icmptype'] = "timex";
470
													break;
471
												case "paramprob":
472
													$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
473
													break;
474
												case "timest":
475
													$config["filter"]["rule"][$i]['icmptype'] = "timereq";
476
													break;
477
												case "timestrep":
478
													$config["filter"]["rule"][$i]['icmptype'] = "timerep";
479
													break;
480
												case "inforeq":
481
													$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
482
													break;
483
												case "inforep":
484
													$config["filter"]["rule"][$i]['icmptype'] = "inforep";
485
													break;
486
												case "maskreq":
487
													$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
488
													break;
489
												case "maskrep":
490
													$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
491
													break;
492
											}
493
										}
494
									}
495
									$config['diag']['ipv6nat'] = true;
496
									write_config();
497
									add_base_packages_menu_items();
498
									convert_config();
499
									conf_mount_ro();
500
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
501
									mark_subsystem_dirty("restore");
502
								}
503
								if (is_array($config['captiveportal'])) {
504
									foreach ($config['captiveportal'] as $cp) {
505
										if (isset($cp['enable'])) {
506
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
507
											mark_subsystem_dirty("restore");
508
											break;
509
										}
510
									}
511
								}
512
								setup_serial_port();
513
								if (is_interface_mismatch() == true) {
514
									touch("/var/run/interface_mismatch_reboot_needed");
515
									clear_subsystem_dirty("restore");
516
									convert_config();
517
									header("Location: interfaces_assign.php");
518
									exit;
519
								}
520
								if (is_interface_vlan_mismatch() == true) {
521
									touch("/var/run/interface_mismatch_reboot_needed");
522
									clear_subsystem_dirty("restore");
523
									convert_config();
524
									header("Location: interfaces_assign.php");
525
									exit;
526
								}
527
							} else {
528
								$input_errors[] = gettext("The configuration could not be restored.");
529
							}
530
						}
531
					}
532
				} else {
533
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
534
				}
535
			}
536
		}
537

    
538
		if ($mode == "reinstallpackages") {
539
			header("Location: pkg_mgr_install.php?mode=reinstallall");
540
			exit;
541
		} else if ($mode == "clearpackagelock") {
542
			clear_subsystem_dirty('packagelock');
543
			$savemsg = "Package Lock Cleared";
544
		} else if ($mode == "restore_ver") {
545
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
546
			if ($ver2restore <> "") {
547
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
548
				if (config_install($conf_file) == 0) {
549
					mark_subsystem_dirty("restore");
550
				} else {
551
					$input_errors[] = gettext("The configuration could not be restored.");
552
				}
553
			} else {
554
				$input_errors[] = gettext("No version selected.");
555
			}
556
		}
557
	}
558
}
559

    
560
$id = rand() . '.' . time();
561

    
562
$mth = ini_get('upload_progress_meter.store_method');
563
$dir = ini_get('upload_progress_meter.file.filename_template');
564

    
565
function build_area_list($showall) {
566
	global $config;
567

    
568
	$areas = array(
569
		"aliases" => gettext("Aliases"),
570
		"captiveportal" => gettext("Captive Portal"),
571
		"voucher" => gettext("Captive Portal Vouchers"),
572
		"dnsmasq" => gettext("DNS Forwarder"),
573
		"unbound" => gettext("DNS Resolver"),
574
		"dhcpd" => gettext("DHCP Server"),
575
		"dhcpdv6" => gettext("DHCPv6 Server"),
576
		"filter" => gettext("Firewall Rules"),
577
		"interfaces" => gettext("Interfaces"),
578
		"ipsec" => gettext("IPSEC"),
579
		"nat" => gettext("NAT"),
580
		"openvpn" => gettext("OpenVPN"),
581
		"installedpackages" => gettext("Package Manager"),
582
		"pptpd" => gettext("PPTP Server"),
583
		"rrddata" => gettext("RRD Data"),
584
		"cron" => gettext("Scheduled Tasks"),
585
		"syslog" => gettext("Syslog"),
586
		"system" => gettext("System"),
587
		"staticroutes" => gettext("Static routes"),
588
		"sysctl" => gettext("System tunables"),
589
		"snmpd" => gettext("SNMP Server"),
590
		"shaper" => gettext("Traffic Shaper"),
591
		"vlans" => gettext("VLANS"),
592
		"wol" => gettext("Wake on LAN")
593
		);
594

    
595
	$list = array("" => gettext("All"));
596

    
597
	if($showall)
598
		return($list + $areas);
599
	else {
600
		foreach ($areas as $area => $areaname) {
601
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
602
				$list[$area] = $areaname;
603
			}
604
		}
605

    
606
		return($list);
607
	}
608
}
609

    
610
$pgtitle = array(gettext("Diagnostics"), gettext("Backup/restore"));
611
include("head.inc");
612

    
613
if ($input_errors)
614
	print_input_errors($input_errors);
615

    
616
if ($savemsg)
617
	print_info_box($savemsg, 'success');
618

    
619
if (is_subsystem_dirty('restore')):
620
?>
621
	<br/>
622
	<form action="reboot.php" method="post">
623
		<input name="Submit" type="hidden" value="Yes" />
624
		<?=print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting."))?>
625
		<br />
626
	</form>
627
<?php
628
endif;
629

    
630
$tab_array = array();
631
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
632
$tab_array[] = array(gettext("Backup/Restore"), true, "diag_backup.php");
633
display_top_tabs($tab_array);
634

    
635
require('classes/Form.class.php');
636

    
637
$form = new Form(false);
638

    
639
$section = new Form_Section('Backup configuration');
640

    
641
$section->addInput(new Form_Select(
642
	'backuparea',
643
	'Backup area',
644
	'',
645
	build_area_list(false)
646
));
647

    
648
$section->addInput(new Form_Checkbox(
649
	'nopackages',
650
	'Skip packages',
651
	'Do not backup package information.',
652
	false
653
));
654

    
655
$section->addInput(new Form_Checkbox(
656
	'donotbackuprrd',
657
	'Skip RRD data',
658
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
659
	true
660
));
661

    
662
$section->addInput(new Form_Checkbox(
663
	'encrypt',
664
	'Encryption',
665
	'Encrypt this configuration file.',
666
	false
667
))->toggles('.toggle-passwords');;
668

    
669
$section->addInput(new Form_Input(
670
	'encrypt_password',
671
	null,
672
	'password',
673
	null,
674
	['placeholder' => 'Password']
675
))->addClass('toggle-passwords');
676

    
677
$section->addInput(new Form_Input(
678
	'encrypt_passconf',
679
	null,
680
	'password',
681
	null,
682
	['placeholder' => 'Confirm password']
683
))->addClass('toggle-passwords');
684

    
685
$group = new Form_Group('');
686
$group->add(new Form_Button(
687
	'Submit',
688
	'Download configuration as XML'
689
));
690

    
691
$section->add($group);
692
$form->add($section);
693

    
694
$section = new Form_Section('Restore backup');
695

    
696
$section->addInput(new Form_StaticText(
697
	null,
698
	gettext("Open a ") . $g['[product_name'] . gettext(" configuration XML file and click the button below to restore the configuration.")
699
));
700

    
701
$section->addInput(new Form_Select(
702
	'restorearea',
703
	'Restore area',
704
	'',
705
	build_area_list(false)
706
));
707

    
708
$section->addInput(new Form_Input(
709
	'conffile',
710
	'Configuration file',
711
	'file',
712
	null
713
));
714

    
715
$section->addInput(new Form_Checkbox(
716
	'encrypt',
717
	'Encryption',
718
	'Encrypt this configuration file.',
719
	false
720
))->toggles('.toggle-dpasswords');;
721

    
722
$section->addInput(new Form_Input(
723
	'decrypt_password',
724
	null,
725
	'password',
726
	null,
727
	['placeholder' => 'Password']
728
))->addClass('toggle-dpasswords');
729

    
730
$section->addInput(new Form_Input(
731
	'decrypt_passconf',
732
	null,
733
	'password',
734
	null,
735
	['placeholder' => 'Confirm password']
736
))->addClass('toggle-dpasswords');
737

    
738
$group = new Form_Group('');
739
$group->add(new Form_Button(
740
	'Submit',
741
	'Restore configuration'
742
))->setHelp('The firewall will reboot after restoring the configuration.')->removeClass('btn-primary')->addClass('btn-danger');
743

    
744
$section->add($group);
745

    
746
$form->add($section);
747

    
748
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
749
	$section = new Form_Section('Package functions');
750

    
751
	if ($config['installedpackages']['package'] != "") {
752
		$group = new Form_Group('');
753
		$group->add(new Form_Button(
754
			'Submit',
755
			'Reinstall packages'
756
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->removeClass('btn-primary')->addClass('btn-warning');
757

    
758
		$section->add($group);
759
	}
760

    
761
	if (is_subsystem_dirty("packagelock")) {
762
		$group = new Form_Group('');
763
		$group->add(new Form_Button(
764
			'Submit',
765
			'Clear Package Lock'
766
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->removeClass('btn-primary')->addClass('btn-warning');
767

    
768
		$section->add($group);
769
	}
770

    
771
	$form->add($section);
772
}
773

    
774
print($form);
775

    
776
include("foot.inc");
777

    
778
if (is_subsystem_dirty('restore')) {
779
	system_reboot();
780
}
(8-8/237)