Projet

Général

Profil

Télécharger (27,3 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / usr / local / www / diag_backup.php @ 0fab7eb1

1
<?php
2
/* $Id$ */
3
/*
4
	diag_backup.php
5
	Copyright (C) 2004-2009 Scott Ullrich
6
	All rights reserved.
7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
230
	echo $select;
231

    
232
}
233

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

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

    
256
	if ($_POST["nopackages"] <> "")
257
		$options = "nopackages";
258

    
259
	if ($_POST["ver"] <> "")
260
		$ver2restore = $_POST["ver"];
261

    
262
	if ($mode) {
263

    
264
		if ($mode == "download") {
265

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

    
273
			if (!$input_errors) {
274

    
275
				//$lockbckp = lock('config');
276

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

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

    
308
				//unlock($lockbckp);
309

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

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

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

    
337
				exit;
338
			}
339
		}
340

    
341
		if ($mode == "restore") {
342

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

    
350
			if (!$input_errors) {
351

    
352
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
353

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

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

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

    
554
		if ($mode == "reinstallpackages") {
555

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

    
577
$id = rand() . '.' . time();
578

    
579
$mth = ini_get('upload_progress_meter.store_method');
580
$dir = ini_get('upload_progress_meter.file.filename_template');
581

    
582
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
583
include("head.inc");
584

    
585
?>
586

    
587
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
588
<?php include("fbegin.inc"); ?>
589
<script type="text/javascript">
590
<!--
591

    
592
function encrypt_change() {
593

    
594
	if (!document.iform.encrypt.checked)
595
		document.getElementById("encrypt_opts").style.display="none";
596
	else
597
		document.getElementById("encrypt_opts").style.display="";
598
}
599

    
600
function decrypt_change() {
601

    
602
	if (!document.iform.decrypt.checked)
603
		document.getElementById("decrypt_opts").style.display="none";
604
	else
605
		document.getElementById("decrypt_opts").style.display="";
606
}
607

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

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

    
775
<script type="text/javascript">
776
<!--
777
encrypt_change();
778
decrypt_change();
779
//-->
780
</script>
781

    
782
<?php include("fend.inc"); ?>
783
</body>
784
</html>
785
<?php
786

    
787
if (is_subsystem_dirty('restore'))
788
	system_reboot();
789

    
790
?>
(7-7/254)