Project

General

Profile

Download (27.8 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
		       "dhcpd" => gettext("DHCP Server"),
186
		       "dhcpdv6" => gettext("DHCPv6 Server"),
187
		       "filter" => gettext("Firewall Rules"),
188
		       "interfaces" => gettext("Interfaces"),
189
		       "ipsec" => gettext("IPSEC"),
190
		       "nat" => gettext("NAT"),
191
		       "openvpn" => gettext("OpenVPN"),
192
		       "installedpackages" => gettext("Package Manager"),
193
		       "pptpd" => gettext("PPTP Server"),
194
		       "rrddata" => gettext("RRD Data"),
195
		       "cron" => gettext("Scheduled Tasks"),
196
		       "syslog" => gettext("Syslog"),
197
		       "system" => gettext("System"),
198
		       "staticroutes" => gettext("Static routes"),
199
		       "sysctl" => gettext("System tunables"),
200
		       "snmpd" => gettext("SNMP Server"),
201
		       "shaper" => gettext("Traffic Shaper"),
202
		       "vlans" => gettext("VLANS"),
203
		       "wol" => gettext("Wake on LAN")
204
		);
205

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

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

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

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

    
233
	echo $select;
234

    
235
}
236

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

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

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

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

    
265
	if ($mode) {
266

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

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

    
276
			if (!$input_errors) {
277

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

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

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

    
311
				//unlock($lockbckp);
312

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

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

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

    
340
				exit;
341
			}
342
		}
343

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

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

    
353
			if (!$input_errors) {
354

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

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

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

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

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

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

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

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

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

    
596
?>
597

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

    
603
function encrypt_change() {
604

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

    
611
function decrypt_change() {
612

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

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

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

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

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

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

    
802
?>
(7-7/256)