Project

General

Profile

Download (27.5 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-2014 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
								/* extract out rrd items, unset from $config when done */
415
								if($config['rrddata']) {
416
									restore_rrddata();
417
									unset($config['rrddata']);
418
									unlink_if_exists("{$g['tmp_path']}/config.cache");
419
									write_config();
420
									add_base_packages_menu_items();
421
									convert_config();
422
									conf_mount_ro();
423
								}
424
								if($m0n0wall_upgrade == true) {
425
									if($config['system']['gateway'] <> "")
426
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
427
									unset($config['shaper']);
428
									/* optional if list */
429
									$ifdescrs = get_configured_interface_list(true, true);
430
									/* remove special characters from interface descriptions */
431
									if(is_array($ifdescrs))
432
										foreach($ifdescrs as $iface)
433
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
434
									/* check for interface names with an alias */
435
									if(is_array($ifdescrs)) {
436
										foreach($ifdescrs as $iface) {
437
											if(is_alias($config['interfaces'][$iface]['descr'])) {
438
												// Firewall rules
439
												$origname = $config['interfaces'][$iface]['descr'];
440
												$newname  = $config['interfaces'][$iface]['descr'] . "Alias";
441
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
442
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
443
												// NAT Rules
444
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
445
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
446
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
447
												// Alias in an alias
448
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
449
											}
450
										}
451
									}
452
									unlink_if_exists("{$g['tmp_path']}/config.cache");
453
									// Reset configuration version to something low
454
									// in order to force the config upgrade code to
455
									// run through with all steps that are required.
456
									$config['system']['version'] = "1.0";
457
									// Deal with descriptions longer than 63 characters
458
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
459
										if(count($config['filter']['rule'][$i]['descr']) > 63)
460
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
461
									}
462
									// Move interface from ipsec to enc0
463
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
464
										if($config['filter']['rule'][$i]['interface'] == "ipsec")
465
											$config['filter']['rule'][$i]['interface'] = "enc0";
466
									}
467
									// Convert icmp types
468
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
469
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
470
										if($config["filter"]["rule"][$i]['icmptype']) {
471
											switch($config["filter"]["rule"][$i]['icmptype']) {
472
											case "echo":
473
												$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
474
												break;
475
											case "unreach":
476
												$config["filter"]["rule"][$i]['icmptype'] = "unreach";
477
												break;
478
											case "echorep":
479
												$config["filter"]["rule"][$i]['icmptype'] = "echorep";
480
												break;
481
											case "squench":
482
												$config["filter"]["rule"][$i]['icmptype'] = "squench";
483
												break;
484
											case "redir":
485
												$config["filter"]["rule"][$i]['icmptype'] = "redir";
486
												break;
487
											case "timex":
488
												$config["filter"]["rule"][$i]['icmptype'] = "timex";
489
												break;
490
											case "paramprob":
491
												$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
492
												break;
493
											case "timest":
494
												$config["filter"]["rule"][$i]['icmptype'] = "timereq";
495
												break;
496
											case "timestrep":
497
												$config["filter"]["rule"][$i]['icmptype'] = "timerep";
498
												break;
499
											case "inforeq":
500
												$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
501
												break;
502
											case "inforep":
503
												$config["filter"]["rule"][$i]['icmptype'] = "inforep";
504
												break;
505
											case "maskreq":
506
												$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
507
												break;
508
											case "maskrep":
509
												$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
510
												break;
511
											}
512
										}
513
									}
514
									$config['diag']['ipv6nat'] = true;
515
									write_config();
516
									add_base_packages_menu_items();
517
									convert_config();
518
									conf_mount_ro();
519
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
520
									mark_subsystem_dirty("restore");
521
								}
522
								if(is_array($config['captiveportal'])) {
523
									foreach($config['captiveportal'] as $cp) {
524
										if (isset($cp['enable'])) {
525
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
526
											mark_subsystem_dirty("restore");
527
											break;
528
										}
529
									}
530
								}
531
								setup_serial_port();
532
								if(is_interface_mismatch() == true) {
533
									touch("/var/run/interface_mismatch_reboot_needed");
534
									clear_subsystem_dirty("restore");
535
									convert_config();
536
									header("Location: interfaces_assign.php");
537
									exit;
538
								}
539
								if (is_interface_vlan_mismatch() == true) {
540
									touch("/var/run/interface_mismatch_reboot_needed");
541
									clear_subsystem_dirty("restore");
542
									convert_config();
543
									header("Location: interfaces_assign.php");
544
									exit;
545
								}
546
							} else {
547
								$input_errors[] = gettext("The configuration could not be restored.");
548
							}
549
						}
550
					}
551
				} else {
552
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
553
				}
554
			}
555
		}
556

    
557
		if ($mode == "reinstallpackages") {
558

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

    
580
$id = rand() . '.' . time();
581

    
582
$mth = ini_get('upload_progress_meter.store_method');
583
$dir = ini_get('upload_progress_meter.file.filename_template');
584

    
585
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
586
include("head.inc");
587

    
588
?>
589

    
590
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
591
<?php include("fbegin.inc"); ?>
592
<script type="text/javascript">
593
//<![CDATA[
594

    
595
function encrypt_change() {
596

    
597
	if (!document.iform.encrypt.checked)
598
		document.getElementById("encrypt_opts").style.display="none";
599
	else
600
		document.getElementById("encrypt_opts").style.display="";
601
}
602

    
603
function decrypt_change() {
604

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

    
611
function backuparea_change(obj) {
612
	if (obj.value == "rrddata") {
613
		document.getElementById("nopackages").disabled      = true;
614
		document.getElementById("dotnotbackuprrd").disabled = true;
615
	} else {
616
		document.getElementById("nopackages").disabled      = false;
617
		document.getElementById("dotnotbackuprrd").disabled = false;
618
	}
619
}
620
//]]>
621
</script>
622

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

    
779
<script type="text/javascript">
780
//<![CDATA[
781
encrypt_change();
782
decrypt_change();
783
//]]>
784
</script>
785

    
786
<?php include("fend.inc"); ?>
787
</body>
788
</html>
789
<?php
790

    
791
if (is_subsystem_dirty('restore'))
792
	system_reboot();
793

    
794
?>
(7-7/256)