Project

General

Profile

Download (28 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	diag_backup.php
5
	Copyright (C) 2004-2009 Scott Ullrich
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7
	All rights reserved.
8

    
9
	originally part of m0n0wall (http://m0n0.ch/wall)
10
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
	All rights reserved.
12

    
13
	Redistribution and use in source and binary forms, with or without
14
	modification, are permitted provided that the following conditions are met:
15

    
16
	1. Redistributions of source code must retain the above copyright notice,
17
	   this list of conditions and the following disclaimer.
18

    
19
	2. Redistributions in binary form must reproduce the above copyright
20
	   notice, this list of conditions and the following disclaimer in the
21
	   documentation and/or other materials provided with the distribution.
22

    
23
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
27
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
	POSSIBILITY OF SUCH DAMAGE.
33
*/
34

    
35
/*
36
	pfSense_BUILDER_BINARIES:	/sbin/shutdown
37
	pfSense_MODULE:	backup
38
*/
39

    
40
##|+PRIV
41
##|*IDENT=page-diagnostics-backup/restore
42
##|*NAME=Diagnostics: Backup/restore page
43
##|*DESCR=Allow access to the 'Diagnostics: Backup/restore' page.
44
##|*MATCH=diag_backup.php*
45
##|-PRIV
46

    
47
/* Allow additional execution time 0 = no limit. */
48
ini_set('max_execution_time', '0');
49
ini_set('max_input_time', '0');
50

    
51
/* omit no-cache headers because it confuses IE with file downloads */
52
$omit_nocacheheaders = true;
53
$nocsrf = true;
54
require("guiconfig.inc");
55
require_once("functions.inc");
56
require_once("filter.inc");
57
require_once("shaper.inc");
58

    
59
$rrddbpath = "/var/db/rrd";
60
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
61

    
62
function rrd_data_xml() {
63
	global $rrddbpath;
64
	global $rrdtool;
65

    
66
	$result = "\t<rrddata>\n";
67
	$rrd_files = glob("{$rrddbpath}/*.rrd");
68
	$xml_files = array();
69
	foreach ($rrd_files as $rrd_file) {
70
		$basename = basename($rrd_file);
71
		$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
72
		exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
73
		$xml_data = file_get_contents($xml_file);
74
		unlink($xml_file);
75
		if ($xml_data !== false) {
76
			$result .= "\t\t<rrddatafile>\n";
77
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
78
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
79
			$result .= "\t\t</rrddatafile>\n";
80
		}
81
	}
82
	$result .= "\t</rrddata>\n";
83
	return $result;
84
}
85

    
86
function restore_rrddata() {
87
	global $config, $g, $rrdtool, $input_errors;
88
	foreach ($config['rrddata']['rrddatafile'] as $rrd) {
89
		if ($rrd['xmldata']) {
90
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
91
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
92
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
93
				log_error("Cannot write $xml_file");
94
				continue;
95
			}
96
			$output = array();
97
			$status = null;
98
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
99
			if ($status) {
100
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
101
				continue;
102
			}
103
			unlink($xml_file);
104
		} else if ($rrd['data']) {
105
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
106
			$rrd_fd = fopen($rrd_file, "w");
107
			if (!$rrd_fd) {
108
				log_error("Cannot write $rrd_file");
109
				continue;
110
			}
111
			$data = base64_decode($rrd['data']);
112
			/* Try to decompress the data. */
113
			$dcomp = @gzinflate($data);
114
			if ($dcomp) {
115
				/* If the decompression worked, write the decompressed data */
116
				if (fwrite($rrd_fd, $dcomp) === false) {
117
					log_error("fwrite $rrd_file failed");
118
					continue;
119
				}
120
			} else {
121
				/* If the decompression failed, it wasn't compressed, so write raw data */
122
				if (fwrite($rrd_fd, $data) === false) {
123
					log_error("fwrite $rrd_file failed");
124
					continue;
125
				}
126
			}
127
			if (fclose($rrd_fd) === false) {
128
				log_error("fclose $rrd_file failed");
129
				continue;
130
			}
131
		}
132
	}
133
}
134

    
135
function add_base_packages_menu_items() {
136
	global $g, $config;
137
	$base_packages = explode(",", $g['base_packages']);
138
	$modified_config = false;
139
	foreach ($base_packages as $bp) {
140
		$basepkg_path = "/usr/local/pkg/{$bp}";
141
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
142
		if ($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
143
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
144
			if ($pkg_config['menu'] != "") {
145
				if (is_array($pkg_config['menu'])) {
146
					foreach ($pkg_config['menu'] as $menu) {
147
						if (is_array($config['installedpackages']['menu'])) {
148
							foreach ($config['installedpackages']['menu'] as $amenu) {
149
								if ($amenu['name'] == $menu['name']) {
150
									continue;
151
								}
152
							}
153
						}
154
						$config['installedpackages']['menu'][] = $menu;
155
						$modified_config = true;
156
					}
157
				}
158
				$static_output .= "done.\n";
159
				update_output_window($static_output);
160
			}
161
		}
162
	}
163
	if ($modified_config) {
164
		write_config(gettext("Restored base_package menus after configuration restore."));
165
		$config = parse_config(true);
166
	}
167
}
168

    
169
function remove_bad_chars($string) {
170
	return preg_replace('/[^a-z_0-9]/i','',$string);
171
}
172

    
173
function check_and_returnif_section_exists($section) {
174
	global $config;
175
	if (is_array($config[$section])) {
176
		return true;
177
	}
178
	return false;
179
}
180

    
181
function spit_out_select_items($name, $showall) {
182
	global $config;
183

    
184
	$areas = array("aliases" => gettext("Aliases"),
185
		"captiveportal" => gettext("Captive Portal"),
186
		"voucher" => gettext("Captive Portal Vouchers"),
187
		"dnsmasq" => gettext("DNS Forwarder"),
188
		"unbound" => gettext("DNS Resolver"),
189
		"dhcpd" => gettext("DHCP Server"),
190
		"dhcpdv6" => gettext("DHCPv6 Server"),
191
		"filter" => gettext("Firewall Rules"),
192
		"interfaces" => gettext("Interfaces"),
193
		"ipsec" => gettext("IPSEC"),
194
		"nat" => gettext("NAT"),
195
		"openvpn" => gettext("OpenVPN"),
196
		"installedpackages" => gettext("Package Manager"),
197
		"pptpd" => gettext("PPTP Server"),
198
		"rrddata" => gettext("RRD Data"),
199
		"cron" => gettext("Scheduled Tasks"),
200
		"syslog" => gettext("Syslog"),
201
		"system" => gettext("System"),
202
		"staticroutes" => gettext("Static routes"),
203
		"sysctl" => gettext("System tunables"),
204
		"snmpd" => gettext("SNMP Server"),
205
		"shaper" => gettext("Traffic Shaper"),
206
		"vlans" => gettext("VLANS"),
207
		"wol" => gettext("Wake on LAN")
208
		);
209

    
210
	$select  = "<select name=\"{$name}\" id=\"{$name}\">";
211
	$select .= "<option value=\"\">" . gettext("ALL") . "</option>";
212

    
213
	if ($showall == true) {
214
		foreach ($areas as $area => $areaname) {
215
			$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
216
		}
217
	} else {
218
		foreach ($areas as $area => $areaname) {
219
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
220
				$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
221
			}
222
		}
223
	}
224

    
225
	$select .= "</select>\n";
226

    
227
	if ($name === "backuparea") {
228
		$select .= <<<END_SCRIPT_BLOCK
229
			<script type="text/javascript">
230
			//<![CDATA[
231
				jQuery(function (\$) {
232
					$("#{$name}").change(function () {
233
						backuparea_change(this);
234
					}).trigger("change");
235
				});
236
			//]]>
237
			</script>
238
END_SCRIPT_BLOCK;
239
	}
240

    
241
	echo $select;
242

    
243
}
244

    
245
if ($_POST['apply']) {
246
	ob_flush();
247
	flush();
248
	conf_mount_rw();
249
	clear_subsystem_dirty("restore");
250
	conf_mount_ro();
251
	exit;
252
}
253

    
254
if ($_POST) {
255
	unset($input_errors);
256
	if (stristr($_POST['Submit'], gettext("Restore configuration"))) {
257
		$mode = "restore";
258
	} else if (stristr($_POST['Submit'], gettext("Reinstall"))) {
259
		$mode = "reinstallpackages";
260
	} else if (stristr($_POST['Submit'], gettext("Clear Package Lock"))) {
261
		$mode = "clearpackagelock";
262
	} else if (stristr($_POST['Submit'], gettext("Download"))) {
263
		$mode = "download";
264
	} else if (stristr($_POST['Submit'], gettext("Restore version"))) {
265
		$mode = "restore_ver";
266
	}
267
	if ($_POST["nopackages"] <> "") {
268
		$options = "nopackages";
269
	}
270
	if ($_POST["ver"] <> "") {
271
		$ver2restore = $_POST["ver"];
272
	}
273
	if ($mode) {
274
		if ($mode == "download") {
275
			if ($_POST['encrypt']) {
276
				if (!$_POST['encrypt_password'] || !$_POST['encrypt_passconf']) {
277
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
278
				}
279
				if ($_POST['encrypt_password'] != $_POST['encrypt_passconf']) {
280
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
281
				}
282
			}
283

    
284
			if (!$input_errors) {
285

    
286
				//$lockbckp = lock('config');
287

    
288
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
289
				$name = "config-{$host}-".date("YmdHis").".xml";
290
				$data = "";
291

    
292
				if ($options == "nopackages") {
293
					if (!$_POST['backuparea']) {
294
						/* backup entire configuration */
295
						$data = file_get_contents("{$g['conf_path']}/config.xml");
296
					} else {
297
						/* backup specific area of configuration */
298
						$data = backup_config_section($_POST['backuparea']);
299
						$name = "{$_POST['backuparea']}-{$name}";
300
					}
301
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
302
					file_put_contents($sfn, $data);
303
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
304
					$data = file_get_contents($sfn . "-new");
305
				} else {
306
					if (!$_POST['backuparea']) {
307
						/* backup entire configuration */
308
						$data = file_get_contents("{$g['conf_path']}/config.xml");
309
					} else if ($_POST['backuparea'] === "rrddata") {
310
						$data = rrd_data_xml();
311
						$name = "{$_POST['backuparea']}-{$name}";
312
					} else {
313
						/* backup specific area of configuration */
314
						$data = backup_config_section($_POST['backuparea']);
315
						$name = "{$_POST['backuparea']}-{$name}";
316
					}
317
				}
318

    
319
				//unlock($lockbckp);
320

    
321
				/*
322
				 *  Backup RRD Data
323
				 */
324
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
325
					$rrd_data_xml = rrd_data_xml();
326
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
327
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
328
				}
329

    
330
				if ($_POST['encrypt']) {
331
					$data = encrypt_data($data, $_POST['encrypt_password']);
332
					tagfile_reformat($data, $data, "config.xml");
333
				}
334

    
335
				$size = strlen($data);
336
				header("Content-Type: application/octet-stream");
337
				header("Content-Disposition: attachment; filename={$name}");
338
				header("Content-Length: $size");
339
				if (isset($_SERVER['HTTPS'])) {
340
					header('Pragma: ');
341
					header('Cache-Control: ');
342
				} else {
343
					header("Pragma: private");
344
					header("Cache-Control: private, must-revalidate");
345
				}
346
				echo $data;
347

    
348
				exit;
349
			}
350
		}
351

    
352
		if ($mode == "restore") {
353
			if ($_POST['decrypt']) {
354
				if (!$_POST['decrypt_password'] || !$_POST['decrypt_passconf']) {
355
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
356
				}
357
				if ($_POST['decrypt_password'] != $_POST['decrypt_passconf']) {
358
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
359
				}
360
			}
361

    
362
			if (!$input_errors) {
363
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
364

    
365
					/* read the file contents */
366
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
367
					if (!$data) {
368
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
369
						return 1;
370
					}
371

    
372
					if ($_POST['decrypt']) {
373
						if (!tagfile_deformat($data, $data, "config.xml")) {
374
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
375
							return 1;
376
						}
377
						$data = decrypt_data($data, $_POST['decrypt_password']);
378
					}
379

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

    
579
		if ($mode == "reinstallpackages") {
580
			header("Location: pkg_mgr_install.php?mode=reinstallall");
581
			exit;
582
		} else if ($mode == "clearpackagelock") {
583
			clear_subsystem_dirty('packagelock');
584
			$savemsg = "Package Lock Cleared";
585
		} else if ($mode == "restore_ver") {
586
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
587
			if ($ver2restore <> "") {
588
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
589
				if (config_install($conf_file) == 0) {
590
					mark_subsystem_dirty("restore");
591
				} else {
592
					$input_errors[] = gettext("The configuration could not be restored.");
593
				}
594
			} else {
595
				$input_errors[] = gettext("No version selected.");
596
			}
597
		}
598
	}
599
}
600

    
601
$id = rand() . '.' . time();
602

    
603
$mth = ini_get('upload_progress_meter.store_method');
604
$dir = ini_get('upload_progress_meter.file.filename_template');
605

    
606
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
607
include("head.inc");
608

    
609
?>
610

    
611
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
612
<?php include("fbegin.inc"); ?>
613
<script type="text/javascript">
614
//<![CDATA[
615

    
616
function encrypt_change() {
617

    
618
	if (!document.iform.encrypt.checked) {
619
		document.getElementById("encrypt_opts").style.display="none";
620
	} else {
621
		document.getElementById("encrypt_opts").style.display="";
622
	}
623
}
624

    
625
function decrypt_change() {
626

    
627
	if (!document.iform.decrypt.checked) {
628
		document.getElementById("decrypt_opts").style.display="none";
629
	} else {
630
		document.getElementById("decrypt_opts").style.display="";
631
	}
632
}
633

    
634
function backuparea_change(obj) {
635
	if (obj.value == "rrddata") {
636
		document.getElementById("nopackages").disabled      = true;
637
		document.getElementById("dotnotbackuprrd").disabled = true;
638
	} else {
639
		document.getElementById("nopackages").disabled      = false;
640
		document.getElementById("dotnotbackuprrd").disabled = false;
641
	}
642
}
643
//]]>
644
</script>
645

    
646
<?php if ($input_errors) print_input_errors($input_errors); ?>
647
<?php if ($savemsg) print_info_box($savemsg); ?>
648
<?php if (is_subsystem_dirty('restore')): ?><br/>
649
<form action="reboot.php" method="post">
650
<input name="Submit" type="hidden" value="Yes" />
651
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting."));?><br />
652
</form>
653
<?php endif; ?>
654
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
655
<table width="100%" border="0" cellspacing="0" cellpadding="0" summary="diag backup">
656
	<tr>
657
		<td>
658
<?php
659
		$tab_array = array();
660
		$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
661
		$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
662
		display_top_tabs($tab_array);
663
?>
664
		</td>
665
	</tr>
666
	<tr>
667
		<td>
668
			<div id="mainarea">
669
			<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
670
				<tr>
671
					<td colspan="2" class="listtopic"><?=gettext("Backup configuration"); ?></td>
672
				</tr>
673
				<tr>
674
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
675
					<td width="78%" class="vtable">
676
						<p><?=gettext("Click this button to download the system configuration in XML format."); ?><br /><br /> <?=gettext("Backup area:"); ?> <?php spit_out_select_items("backuparea", false); ?></p>
677
						<table>
678
							<tr>
679
								<td>
680
									<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages" />
681
								</td>
682
								<td>
683
									<span class="vexpl"><?=gettext("Do not backup package information."); ?></span>
684
								</td>
685
							</tr>
686
						</table>
687
						<table>
688
							<tr>
689
								<td>
690
									<input name="encrypt" type="checkbox" class="formcheckbox" id="nopackages" onclick="encrypt_change()" />
691
								</td>
692
								<td>
693
									<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
694
								</td>
695
							</tr>
696
							<tr>
697
								<td>
698
									<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd" checked="checked" />
699
								</td>
700
								<td>
701
									<span class="vexpl"><?=gettext("Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)"); ?></span>
702
								</td>
703
							</tr>
704
						</table>
705
						<table id="encrypt_opts">
706
							<tr>
707
								<td>
708
									<span class="vexpl"><?=gettext("Password:"); ?> </span>
709
								</td>
710
								<td>
711
									<input name="encrypt_password" type="password" class="formfld pwd" size="20" value="" />
712
								</td>
713
							</tr>
714
							<tr>
715
								<td>
716
									<span class="vexpl"><?=gettext("confirm:"); ?> </span>
717
								</td>
718
								<td>
719
									<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
720
								</td>
721
							</tr>
722
						</table>
723
						<p><input name="Submit" type="submit" class="formbtn" id="download" value="<?=gettext("Download configuration"); ?>" /></p>
724
					</td>
725
				</tr>
726
				<tr>
727
					<td colspan="2" class="list" height="12">&nbsp;</td>
728
				</tr>
729
				<tr>
730
					<td colspan="2" class="listtopic"><?=gettext("Restore configuration"); ?></td>
731
				</tr>
732
				<tr>
733
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
734
					<td width="78%" class="vtable">
735
						<?=gettext("Open a"); ?> <?=$g['[product_name']?> <?=gettext("configuration XML file and click the button below to restore the configuration."); ?>
736
						<br /><br />
737
						<?=gettext("Restore area:"); ?> <?php spit_out_select_items("restorearea", true); ?>
738
						<p><input name="conffile" type="file" class="formbtn" id="conffile" size="40" /></p>
739
						<table>
740
							<tr>
741
								<td>
742
									<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onclick="decrypt_change()" />
743
								</td>
744
								<td>
745
									<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
746
								</td>
747
							</tr>
748
						</table>
749
						<table id="decrypt_opts">
750
							<tr>
751
								<td>
752
									<span class="vexpl"><?=gettext("Password :"); ?></span>
753
								</td>
754
								<td>
755
									<input name="decrypt_password" type="password" class="formfld pwd" size="20" value="" />
756
								</td>
757
							</tr>
758
							<tr>
759
								<td>
760
									<span class="vexpl"><?=gettext("confirm :"); ?></span>
761
								</td>
762
								<td>
763
									<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
764
								</td>
765
							</tr>
766
						</table>
767
						<p><input name="Submit" type="submit" class="formbtn" id="restore" value="<?=gettext("Restore configuration"); ?>" /></p>
768
						<p><strong><span class="red"><?=gettext("Note:"); ?></span></strong><br /><?=gettext("The firewall will reboot after restoring the configuration."); ?><br /></p>
769
					</td>
770
				</tr>
771
				<?php if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) { ?>
772
				<tr>
773
					<td colspan="2" class="list" height="12">&nbsp;</td>
774
				</tr>
775
				<tr>
776
					<td colspan="2" class="listtopic"><?=gettext("Package Functions"); ?></td>
777
				</tr>
778
				<tr>
779
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
780
					<td width="78%" class="vtable">
781
						<?php if ($config['installedpackages']['package'] != "") { ?>
782
							<p><?=gettext("Click this button to reinstall all system packages.  This may take a while."); ?> <br /><br />
783
							<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="<?=gettext("Reinstall packages"); ?>" />
784
							<br />
785
							<br />
786
						<?php } ?>
787
						<?php if (is_subsystem_dirty("packagelock")) { ?>
788
							<p><?=gettext("Click this button to clear the package lock if a package fails to reinstall properly after an upgrade."); ?> <br /><br />
789
							<input name="Submit" type="submit" class="formbtn" id="clearpackagelock" value="<?=gettext("Clear Package Lock"); ?>" />
790
						<?php } ?>
791
							</p>
792
					</td>
793
				</tr>
794
				<?php } ?>
795
			</table>
796
			</div>
797
		</td>
798
	</tr>
799
</table>
800
</form>
801

    
802
<script type="text/javascript">
803
//<![CDATA[
804
encrypt_change();
805
decrypt_change();
806
//]]>
807
</script>
808

    
809
<?php include("fend.inc"); ?>
810
</body>
811
</html>
812
<?php
813

    
814
if (is_subsystem_dirty('restore')) {
815
	system_reboot();
816
}
817

    
818
?>
(7-7/256)