Project

General

Profile

Download (27.9 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
		}
105
		else if ($rrd['data']) {
106
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
107
			$rrd_fd = fopen($rrd_file, "w");
108
			if (!$rrd_fd) {
109
				log_error("Cannot write $rrd_file");
110
				continue;
111
			}
112
			$data = base64_decode($rrd['data']);
113
			/* Try to decompress the data. */
114
			$dcomp = @gzinflate($data);
115
			if ($dcomp) {
116
				/* If the decompression worked, write the decompressed data */
117
				if (fwrite($rrd_fd, $dcomp) === false) {
118
					log_error("fwrite $rrd_file failed");
119
					continue;
120
				}
121
			} else {
122
				/* If the decompression failed, it wasn't compressed, so write raw data */
123
				if (fwrite($rrd_fd, $data) === false) {
124
					log_error("fwrite $rrd_file failed");
125
					continue;
126
				}
127
			}
128
			if (fclose($rrd_fd) === false) {
129
				log_error("fclose $rrd_file failed");
130
				continue;
131
			}
132
		}
133
	}
134
}
135

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

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

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

    
178
function spit_out_select_items($name, $showall) {
179
	global $config;
180

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

    
207
	$select  = "<select name=\"{$name}\" id=\"{$name}\">";
208
	$select .= "<option value=\"\">" . gettext("ALL") . "</option>";
209

    
210
	if($showall == true)
211
		foreach($areas as $area => $areaname)
212
			$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
213
	else
214
		foreach($areas as $area => $areaname)
215
			if($area === "rrddata" || check_and_returnif_section_exists($area) == true)
216
				$select .= "<option value=\"{$area}\">{$areaname}</option>\n";
217

    
218
	$select .= "</select>\n";
219

    
220
	if ($name === "backuparea") {
221
		$select .= <<<END_SCRIPT_BLOCK
222
			<script type="text/javascript">
223
			//<![CDATA[
224
				jQuery(function (\$) {
225
					$("#{$name}").change(function () {
226
						backuparea_change(this);
227
					}).trigger("change");
228
				});
229
			//]]>
230
			</script>
231
END_SCRIPT_BLOCK;
232
	}
233

    
234
	echo $select;
235

    
236
}
237

    
238
if ($_POST['apply']) {
239
	ob_flush();
240
	flush();
241
	conf_mount_rw();
242
	clear_subsystem_dirty("restore");
243
	conf_mount_ro();
244
	exit;
245
}
246

    
247
if ($_POST) {
248
	unset($input_errors);
249
	if (stristr($_POST['Submit'], gettext("Restore configuration")))
250
		$mode = "restore";
251
	else if (stristr($_POST['Submit'], gettext("Reinstall")))
252
		$mode = "reinstallpackages";
253
	else if (stristr($_POST['Submit'], gettext("Clear Package Lock")))
254
		$mode = "clearpackagelock";
255
	else if (stristr($_POST['Submit'], gettext("Download")))
256
		$mode = "download";
257
	else if (stristr($_POST['Submit'], gettext("Restore version")))
258
		$mode = "restore_ver";
259

    
260
	if ($_POST["nopackages"] <> "")
261
		$options = "nopackages";
262

    
263
	if ($_POST["ver"] <> "")
264
		$ver2restore = $_POST["ver"];
265

    
266
	if ($mode) {
267

    
268
		if ($mode == "download") {
269

    
270
			if ($_POST['encrypt']) {
271
				if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
272
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
273
				if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
274
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
275
			}
276

    
277
			if (!$input_errors) {
278

    
279
				//$lockbckp = lock('config');
280

    
281
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
282
				$name = "config-{$host}-".date("YmdHis").".xml";
283
				$data = "";
284

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

    
312
				//unlock($lockbckp);
313

    
314
				/*
315
				 *  Backup RRD Data
316
				 */
317
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
318
					$rrd_data_xml = rrd_data_xml();
319
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
320
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
321
				}
322

    
323
				if ($_POST['encrypt']) {
324
					$data = encrypt_data($data, $_POST['encrypt_password']);
325
					tagfile_reformat($data, $data, "config.xml");
326
				}
327

    
328
				$size = strlen($data);
329
				header("Content-Type: application/octet-stream");
330
				header("Content-Disposition: attachment; filename={$name}");
331
				header("Content-Length: $size");
332
				if (isset($_SERVER['HTTPS'])) {
333
					header('Pragma: ');
334
					header('Cache-Control: ');
335
				} else {
336
					header("Pragma: private");
337
					header("Cache-Control: private, must-revalidate");
338
				}
339
				echo $data;
340

    
341
				exit;
342
			}
343
		}
344

    
345
		if ($mode == "restore") {
346

    
347
			if ($_POST['decrypt']) {
348
				if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
349
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
350
				if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
351
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
352
			}
353

    
354
			if (!$input_errors) {
355

    
356
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
357

    
358
					/* read the file contents */
359
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
360
					if(!$data) {
361
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
362
						return 1;
363
					}
364

    
365
					if ($_POST['decrypt']) {
366
						if (!tagfile_deformat($data, $data, "config.xml")) {
367
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
368
							return 1;
369
						}
370
						$data = decrypt_data($data, $_POST['decrypt_password']);
371
					}
372

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

    
566
		if ($mode == "reinstallpackages") {
567

    
568
			header("Location: pkg_mgr_install.php?mode=reinstallall");
569
			exit;
570
		} else if ($mode == "clearpackagelock") {
571
			clear_subsystem_dirty('packagelock');
572
			$savemsg = "Package Lock Cleared";
573
		} else if ($mode == "restore_ver") {
574
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
575
			if ($ver2restore <> "") {
576
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
577
				if (config_install($conf_file) == 0) {
578
					mark_subsystem_dirty("restore");
579
				} else {
580
					$input_errors[] = gettext("The configuration could not be restored.");
581
				}
582
			} else {
583
				$input_errors[] = gettext("No version selected.");
584
			}
585
		}
586
	}
587
}
588

    
589
$id = rand() . '.' . time();
590

    
591
$mth = ini_get('upload_progress_meter.store_method');
592
$dir = ini_get('upload_progress_meter.file.filename_template');
593

    
594
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
595
include("head.inc");
596

    
597
?>
598

    
599
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
600
<?php include("fbegin.inc"); ?>
601
<script type="text/javascript">
602
//<![CDATA[
603

    
604
function encrypt_change() {
605

    
606
	if (!document.iform.encrypt.checked)
607
		document.getElementById("encrypt_opts").style.display="none";
608
	else
609
		document.getElementById("encrypt_opts").style.display="";
610
}
611

    
612
function decrypt_change() {
613

    
614
	if (!document.iform.decrypt.checked)
615
		document.getElementById("decrypt_opts").style.display="none";
616
	else
617
		document.getElementById("decrypt_opts").style.display="";
618
}
619

    
620
function backuparea_change(obj) {
621
	if (obj.value == "rrddata") {
622
		document.getElementById("nopackages").disabled      = true;
623
		document.getElementById("dotnotbackuprrd").disabled = true;
624
	} else {
625
		document.getElementById("nopackages").disabled      = false;
626
		document.getElementById("dotnotbackuprrd").disabled = false;
627
	}
628
}
629
//]]>
630
</script>
631

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

    
788
<script type="text/javascript">
789
//<![CDATA[
790
encrypt_change();
791
decrypt_change();
792
//]]>
793
</script>
794

    
795
<?php include("fend.inc"); ?>
796
</body>
797
</html>
798
<?php
799

    
800
if (is_subsystem_dirty('restore'))
801
	system_reboot();
802

    
803
?>
(7-7/256)