Project

General

Profile

Download (24.6 KB) Statistics
| Branch: | Tag: | Revision:
1 8ccc8f1a Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4
	diag_backup.php
5 13d193c2 Scott Ullrich
	Copyright (C) 2004-2009 Scott Ullrich
6 929db667 Scott Ullrich
	All rights reserved.
7 8ccc8f1a Scott Ullrich
8 929db667 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
9 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11 8ccc8f1a Scott Ullrich
12 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14 8ccc8f1a Scott Ullrich
15 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17 8ccc8f1a Scott Ullrich
18 5b237745 Scott Ullrich
	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 8ccc8f1a Scott Ullrich
22 5b237745 Scott Ullrich
	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 13d193c2 Scott Ullrich
/*
35
	pfSense_BUILDER_BINARIES:	/sbin/shutdown
36
	pfSense_MODULE:	backup
37
*/
38
39 6b07c15a Matthew Grooms
##|+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 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
47 3420028c Scott Ullrich
ini_set('max_execution_time', '0');
48
ini_set('max_input_time', '0');
49 47d11b79 Mark Crane
50 5b237745 Scott Ullrich
/* omit no-cache headers because it confuses IE with file downloads */
51
$omit_nocacheheaders = true;
52 99b1cc43 Scott Ullrich
$nocsrf = true;
53 8ccc8f1a Scott Ullrich
require("guiconfig.inc");
54 7a927e67 Scott Ullrich
require_once("functions.inc");
55
require_once("filter.inc");
56
require_once("shaper.inc");
57 5b237745 Scott Ullrich
58 3420028c Scott Ullrich
function add_base_packages_menu_items() {
59
	global $g, $config;
60
	$base_packages = split($g['base_packages'], ",");
61
	$modified_config = false;
62
	foreach($base_packages as $bp) {
63 da17d77e Ermal Lu?i
		$basepkg_path = "/usr/local/pkg/{$bp}";
64 a250f179 Renato Botelho
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
65 da17d77e Ermal Lu?i
		if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
66
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
67 3420028c Scott Ullrich
			if($pkg_config['menu'] != "") {
68
				if(is_array($pkg_config['menu'])) {
69
					foreach($pkg_config['menu'] as $menu) {
70
						if(is_array($config['installedpackages']['menu']))
71
							foreach($config['installedpackages']['menu'] as $amenu)
72
								if($amenu['name'] == $menu['name'])
73
									continue;
74
						$config['installedpackages']['menu'][] = $menu;
75
						$modified_config = true;
76
					}
77
				}
78
				$static_output .= "done.\n";
79
				update_output_window($static_output);
80
			}
81
		}
82
	}
83
	if($modified_config) {
84 f3ceee6e Vinicius Coque
		write_config(gettext("Restored base_package menus after configuration restore."));
85 3420028c Scott Ullrich
		$config = parse_config(true);
86
	}
87
}
88
89 645ec835 Scott Ullrich
function remove_bad_chars($string) {
90 0e1619be Erik Fonnesbeck
	return preg_replace('/[^a-z_0-9]/i','',$string);
91 645ec835 Scott Ullrich
}
92
93 b3277798 Scott Ullrich
function check_and_returnif_section_exists($section) {
94
	global $config;
95
	if(is_array($config[$section]))
96
		return true;
97
	return false;
98
}
99
100 3244aa21 Scott Ullrich
function spit_out_select_items($area, $showall) {
101 b3277798 Scott Ullrich
	global $config;
102 a250f179 Renato Botelho
103
	$areas = array("aliases" => gettext("Aliases"),
104 205da5a0 Neriberto C.Prado
				   "captiveportal" => gettext("Captive Portal"),
105
				   "voucher" => gettext("Captive Portal Vouchers"),
106 a250f179 Renato Botelho
				   "dnsmasq" => gettext("DNS Forwarder"),
107 205da5a0 Neriberto C.Prado
				   "dhcpd" => gettext("DHCP Server"),
108
				   "filter" => gettext("Firewall Rules"),
109
				   "interfaces" => gettext("Interfaces"),
110
				   "ipsec" => gettext("IPSEC"),
111
				   "nat" => gettext("NAT"),
112
				   "ovpn" => gettext("OpenVPN"),
113
				   "installedpackages" => gettext("Package Manager"),
114
				   "pptpd" => gettext("PPTP Server"),
115 a250f179 Renato Botelho
				   "cron" => gettext("Scheduled Tasks"),
116 205da5a0 Neriberto C.Prado
				   "syslog" => gettext("Syslog"),
117
				   "system" => gettext("System"),
118
				   "staticroutes" => gettext("Static routes"),
119
				   "sysctl" => gettext("System tunables"),
120
				   "snmpd" => gettext("SNMP Server"),
121
				   "shaper" => gettext("Traffic Shaper"),
122
				   "vlans" => gettext("VLANS"),
123
				   "wol" => gettext("Wake on LAN")
124 b3277798 Scott Ullrich
	);
125
126 a1003d57 Ermal Lu?i
	$select  = "<select name=\"{$area}\" id=\"{$aread}\" ";
127
	if ($area == "backuparea")
128
		$select .= " onChange=backuparea_change(this)";
129
	$select .= " >\n";
130 e085ff29 Carlos Eduardo Ramos
	$select .= "<option VALUE=\"\">" . gettext("ALL") . "</option>";
131 b3277798 Scott Ullrich
132 a250f179 Renato Botelho
	if($showall == true)
133 eef938b5 Scott Ullrich
		foreach($areas as $area => $areaname)
134
			$select .= "<option value='{$area}'>{$areaname}</option>\n";
135 a250f179 Renato Botelho
	else
136 3244aa21 Scott Ullrich
		foreach($areas as $area => $areaname)
137
			if(check_and_returnif_section_exists($area) == true)
138
				$select .= "<option value='{$area}'>{$areaname}</option>\n";
139 b3277798 Scott Ullrich
140
	$select .= "</select>\n";
141 a250f179 Renato Botelho
142 8e35abee Scott Ullrich
	echo $select;
143
144
}
145
146 da17d77e Ermal Lu?i
if ($_POST['apply']) {
147
        ob_flush();
148
        flush();
149 344c68b2 sullrich
		conf_mount_rw();
150
		clear_subsystem_dirty("restore");
151
		conf_mount_ro();
152 da17d77e Ermal Lu?i
        exit;
153
}
154
155 5b237745 Scott Ullrich
if ($_POST) {
156
	unset($input_errors);
157 8246efa6 Renato Botelho
	if (stristr($_POST['Submit'], gettext("Restore configuration")))
158 5b237745 Scott Ullrich
		$mode = "restore";
159 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Reinstall")))
160 8ccc8f1a Scott Ullrich
		$mode = "reinstallpackages";
161 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Download")))
162 5b237745 Scott Ullrich
		$mode = "download";
163 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Restore version")))
164 7cf03119 Bill Marquette
		$mode = "restore_ver";
165
166 aab57926 Scott Ullrich
	if ($_POST["nopackages"] <> "")
167 528cad39 Colin Smith
		$options = "nopackages";
168 8ccc8f1a Scott Ullrich
169 7cf03119 Bill Marquette
	if ($_POST["ver"] <> "")
170
		$ver2restore = $_POST["ver"];
171
172 5b237745 Scott Ullrich
	if ($mode) {
173 8ff5ffcc Matthew Grooms
174 5b237745 Scott Ullrich
		if ($mode == "download") {
175 8ff5ffcc Matthew Grooms
176
			if ($_POST['encrypt']) {
177
				if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
178 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
179 8ff5ffcc Matthew Grooms
				if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
180 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
181 528cad39 Colin Smith
			}
182 8ff5ffcc Matthew Grooms
183
			if (!$input_errors) {
184
185 07b1797b sullrich
				//$lockbckp = lock('config');
186 8ff5ffcc Matthew Grooms
187
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
188
				$name = "config-{$host}-".date("YmdHis").".xml";
189
				$data = "";
190
191
				if($options == "nopackages") {
192 4195c967 sullrich
					if(!$_POST['backuparea']) {
193
						/* backup entire configuration */
194
						$data = file_get_contents("{$g['conf_path']}/config.xml");
195
					} else {
196
						/* backup specific area of configuration */
197
						$data = backup_config_section($_POST['backuparea']);
198
						$name = "{$_POST['backuparea']}-{$name}";
199
					}
200 da17d77e Ermal Lu?i
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
201 4195c967 sullrich
					file_put_contents($sfn, $data);
202
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
203 a250f179 Renato Botelho
					$data = file_get_contents($sfn . "-new");
204 8ff5ffcc Matthew Grooms
				} else {
205
					if(!$_POST['backuparea']) {
206
						/* backup entire configuration */
207
						$data = file_get_contents("{$g['conf_path']}/config.xml");
208
					} else {
209
						/* backup specific area of configuration */
210
						$data = backup_config_section($_POST['backuparea']);
211
						$name = "{$_POST['backuparea']}-{$name}";
212
					}
213 181462b5 Scott Ullrich
				}
214 8ff5ffcc Matthew Grooms
215 07b1797b sullrich
				//unlock($lockbckp);
216 da17d77e Ermal Lu?i
217 8ff5ffcc Matthew Grooms
				if ($_POST['encrypt']) {
218
					$data = encrypt_data($data, $_POST['encrypt_password']);
219
					tagfile_reformat($data, $data, "config.xml");
220 181462b5 Scott Ullrich
				}
221 8ff5ffcc Matthew Grooms
222 a250f179 Renato Botelho
				/*
223 1390b049 Scott Ullrich
				 *  Backup RRD Data
224
				 */
225
				if(!$_POST['donotbackuprrd']) {
226 67bc955d Chris Buechler
					$data = str_replace("</" . $g['xml_rootobj'] . ">", "\t<rrddata>", $data);
227 1390b049 Scott Ullrich
					$rrd_files_var_db_rrd = split("\n",`cd /var/db/rrd && ls *.rrd`);
228
					foreach($rrd_files_var_db_rrd as $rrd) {
229
						if($rrd) {
230
							$rrd_data = file_get_contents("{$g['vardb_path']}/rrd/{$rrd}");
231
							if($rrd_data) {
232
								$data .= "\t\t<rrddatafile>\n";
233
								$data .= "\t\t\t<filename>{$rrd}</filename>\n";
234 2c9a4ed1 jim-p
								$data .= "\t\t\t<data>" . base64_encode(gzdeflate($rrd_data)) . "</data>\n";
235 1390b049 Scott Ullrich
								$data .= "\t\t</rrddatafile>\n";
236
							}
237
						}
238
					}
239
					$data .= "\t</rrddata>\n";
240 67bc955d Chris Buechler
					$data .= "</" . $g['xml_rootobj'] . ">\n";
241 1390b049 Scott Ullrich
				}
242 a250f179 Renato Botelho
243 8ff5ffcc Matthew Grooms
				$size = strlen($data);
244
				header("Content-Type: application/octet-stream");
245
				header("Content-Disposition: attachment; filename={$name}");
246 a8c35980 Scott Ullrich
				header("Content-Length: $size");
247 e77ea573 jim-p
				if (isset($_SERVER['HTTPS'])) {
248
					header('Pragma: ');
249
					header('Cache-Control: ');
250
				} else {
251
					header("Pragma: private");
252
					header("Cache-Control: private, must-revalidate");
253
				}
254 8ff5ffcc Matthew Grooms
				echo $data;
255
256
				exit;
257
			}
258
		}
259
260
		if ($mode == "restore") {
261
262
			if ($_POST['decrypt']) {
263
				if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
264 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
265 8ff5ffcc Matthew Grooms
				if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
266 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
267 8ff5ffcc Matthew Grooms
			}
268
269
			if (!$input_errors) {
270
271
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
272
273
					/* read the file contents */
274
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
275
					if(!$data) {
276 dae4c487 Carlos Eduardo Ramos
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
277 8ff5ffcc Matthew Grooms
						return 1;
278 9fd18b1f Scott Ullrich
					}
279 8ff5ffcc Matthew Grooms
280
					if ($_POST['decrypt']) {
281
						if (!tagfile_deformat($data, $data, "config.xml")) {
282 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
283 8ff5ffcc Matthew Grooms
							return 1;
284
						}
285
						$data = decrypt_data($data, $_POST['decrypt_password']);
286
					}
287
288 1d683793 sullrich
					if(stristr($data, "<m0n0wall>")) {
289 205da5a0 Neriberto C.Prado
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
290 8ff5ffcc Matthew Grooms
						/* m0n0wall was found in config.  convert it. */
291
						$data = str_replace("m0n0wall", "pfsense", $data);
292
						$m0n0wall_upgrade = true;
293
					}
294
					if($_POST['restorearea']) {
295
						/* restore a specific area of the configuration */
296
						if(!stristr($data, $_POST['restorearea'])) {
297 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
298 8ff5ffcc Matthew Grooms
						} else {
299
							restore_config_section($_POST['restorearea'], $data);
300
							filter_configure();
301 205da5a0 Neriberto C.Prado
							$savemsg = gettext("The configuration area has been restored.  You may need to reboot the firewall.");
302 8ff5ffcc Matthew Grooms
						}
303 181462b5 Scott Ullrich
					} else {
304 6819b7f6 Renato Botelho
						if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
305 dae4c487 Carlos Eduardo Ramos
							$input_errors[] = sprintf(gettext("You have selected to restore the full configuration but we could not locate a %s tag."), $g['xml_rootobj']);
306 8ff5ffcc Matthew Grooms
						} else {
307
							/* restore the entire configuration */
308
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
309
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
310
								/* this will be picked up by /index.php */
311
								conf_mount_rw();
312 da17d77e Ermal Lu?i
								mark_subsystem_dirty("restore");
313 09821234 Scott Ullrich
								touch("/conf/needs_package_sync");
314 8ff5ffcc Matthew Grooms
								/* remove cache, we will force a config reboot */
315 da17d77e Ermal Lu?i
								if(file_exists("{$g['tmp_path']}/config.cache"))
316
									unlink("{$g['tmp_path']}/config.cache");
317 8ff5ffcc Matthew Grooms
								$config = parse_config(true);
318 67bc955d Chris Buechler
								/* extract out rrd items, unset from $config when done */
319 1390b049 Scott Ullrich
								if($config['rrddata']) {
320
									foreach($config['rrddata']['rrddatafile'] as $rrd) {
321
										$rrd_fd = fopen("{$g['vardb_path']}/rrd/{$rrd['filename']}", "w");
322 2c9a4ed1 jim-p
										$data = base64_decode($rrd['data']);
323
										/* Try to decompress the data. */
324
										$dcomp = @gzinflate($data);
325
										if ($dcomp) {
326
											/* If the decompression worked, write the decompressed data */
327
											fwrite($rrd_fd, $dcomp);
328
										} else {
329
											/* If the decompression failed, it wasn't compressed, so write raw data */
330
											fwrite($rrd_fd, $data);
331
										}
332 1390b049 Scott Ullrich
										fclose($rrd_fd);
333
									}
334 a2b8f7b2 Scott Ullrich
									unset($config['rrddata']);
335 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
336 a2b8f7b2 Scott Ullrich
									write_config();
337 3420028c Scott Ullrich
									add_base_packages_menu_items();
338 d442e4e2 Scott Ullrich
									convert_config();
339 a2b8f7b2 Scott Ullrich
									conf_mount_ro();
340 1390b049 Scott Ullrich
								}
341 8ff5ffcc Matthew Grooms
								if($m0n0wall_upgrade == true) {
342
									if($config['system']['gateway'] <> "")
343
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
344
									unset($config['shaper']);
345
									/* optional if list */
346
									$ifdescrs = get_configured_interface_list(true, true);
347
									/* remove special characters from interface descriptions */
348
									if(is_array($ifdescrs))
349
										foreach($ifdescrs as $iface)
350
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
351 b6db8ea3 sullrich
									/* check for interface names with an alias */
352
									if(is_array($ifdescrs)) {
353
										foreach($ifdescrs as $iface) {
354
											if(is_alias($config['interfaces'][$iface]['descr'])) {
355
												// Firewall rules
356
												$origname = $config['interfaces'][$iface]['descr'];
357
												$newname  = $config['interfaces'][$iface]['descr'] . "Alias";
358 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
359
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
360 b6db8ea3 sullrich
												// NAT Rules
361 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
362
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
363
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
364 b6db8ea3 sullrich
												// Alias in an alias
365 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
366 b6db8ea3 sullrich
											}
367
										}
368
									}
369 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
370 888e7a27 Scott Ullrich
									// Reset configuration version to something low
371 a250f179 Renato Botelho
									// in order to force the config upgrade code to
372 888e7a27 Scott Ullrich
									// run through with all steps that are required.
373
									$config['system']['version'] = "1.0";
374 798cb31a Scott Ullrich
									// Deal with descriptions longer than 63 characters
375
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
376
										if(count($config['filter']['rule'][$i]['descr']) > 63)
377
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
378
									}
379
									// Move interface from ipsec to enc0
380
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
381
										if($config['filter']['rule'][$i]['interface'] == "ipsec")
382
											$config['filter']['rule'][$i]['interface'] = "enc0";
383
									}
384
									// Convert icmp types
385
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
386
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
387
										if($config["filter"]["rule"][$i]['icmptype']) {
388
											switch($config["filter"]["rule"][$i]['icmptype']) {
389
												case "echo":
390
													$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
391
													break;
392
					                            case "unreach":
393
													$config["filter"]["rule"][$i]['icmptype'] = "unreach";
394
													break;
395
					                            case "echorep":
396
													$config["filter"]["rule"][$i]['icmptype'] = "echorep";
397
													break;
398
					                            case "squench":
399
													$config["filter"]["rule"][$i]['icmptype'] = "squench";
400
													break;
401
					                            case "redir":
402
													$config["filter"]["rule"][$i]['icmptype'] = "redir";
403
													break;
404
					                            case "timex":
405
													$config["filter"]["rule"][$i]['icmptype'] = "timex";
406
													break;
407
					                            case "paramprob":
408
													$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
409
													break;
410
					                            case "timest":
411
													$config["filter"]["rule"][$i]['icmptype'] = "timereq";
412
													break;
413
					                            case "timestrep":
414
													$config["filter"]["rule"][$i]['icmptype'] = "timerep";
415
													break;
416
					                            case "inforeq":
417
													$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
418
													break;
419
					                            case "inforep":
420
													$config["filter"]["rule"][$i]['icmptype'] = "inforep";
421
													break;
422
					                            case "maskreq":
423
													$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
424
													break;
425
					                            case "maskrep":
426
													$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
427
													break;
428
											}
429
										}
430 dec5cb85 Scott Ullrich
									}
431
									$config['diag']['ipv6nat'] = true;
432 8ff5ffcc Matthew Grooms
									write_config();
433 a250f179 Renato Botelho
									add_base_packages_menu_items();
434 d442e4e2 Scott Ullrich
									convert_config();
435 8ff5ffcc Matthew Grooms
									conf_mount_ro();
436 205da5a0 Neriberto C.Prado
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
437 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
438 8ff5ffcc Matthew Grooms
								}
439
								if(isset($config['captiveportal']['enable'])) {
440
									/* for some reason ipfw doesn't init correctly except on bootup sequence */
441 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
442 8ff5ffcc Matthew Grooms
								}
443
								setup_serial_port();
444
								if(is_interface_mismatch() == true) {
445
									touch("/var/run/interface_mismatch_reboot_needed");
446 da17d77e Ermal Lu?i
									clear_subsystem_dirty("restore");
447 f5a57bb0 Scott Ullrich
									convert_config();
448 8ff5ffcc Matthew Grooms
									header("Location: interfaces_assign.php");
449 bafaf123 Scott Ullrich
									exit;
450 8ff5ffcc Matthew Grooms
								}
451 66bcba1b Ermal
								if (is_interface_vlan_mismatch() == true) {
452
									touch("/var/run/interface_mismatch_reboot_needed");
453
									clear_subsystem_dirty("restore");
454
									convert_config();
455
									header("Location: interfaces_assign.php");
456
									exit;
457
								}
458 8ff5ffcc Matthew Grooms
							} else {
459 205da5a0 Neriberto C.Prado
								$input_errors[] = gettext("The configuration could not be restored.");
460 db3996df Scott Ullrich
							}
461 9c72b993 Scott Ullrich
						}
462 181462b5 Scott Ullrich
					}
463 8ff5ffcc Matthew Grooms
				} else {
464 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
465 db3996df Scott Ullrich
				}
466 5b237745 Scott Ullrich
			}
467 8ff5ffcc Matthew Grooms
		}
468
469
		if ($mode == "reinstallpackages") {
470
471 8ccc8f1a Scott Ullrich
			header("Location: pkg_mgr_install.php?mode=reinstallall");
472
			exit;
473 7cf03119 Bill Marquette
                } else if ($mode == "restore_ver") {
474 205da5a0 Neriberto C.Prado
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
475 7cf03119 Bill Marquette
			if ($ver2restore <> "") {
476
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
477 343bb325 sullrich
				if (config_install($conf_file) == 0) {
478
						mark_subsystem_dirty("restore");
479 7cf03119 Bill Marquette
                        } else {
480 205da5a0 Neriberto C.Prado
                        	$input_errors[] = gettext("The configuration could not be restored.");
481 7cf03119 Bill Marquette
                        }
482 343bb325 sullrich
                } else {
483 205da5a0 Neriberto C.Prado
                        $input_errors[] = gettext("No version selected.");
484 343bb325 sullrich
                }
485 5b237745 Scott Ullrich
		}
486
	}
487
}
488 6a1e6651 Bill Marquette
489 02e1170d Scott Ullrich
$id = rand() . '.' . time();
490
491
$mth = ini_get('upload_progress_meter.store_method');
492
$dir = ini_get('upload_progress_meter.file.filename_template');
493
494 205da5a0 Neriberto C.Prado
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
495 b63695db Scott Ullrich
include("head.inc");
496
497 5b237745 Scott Ullrich
?>
498
499
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
500
<?php include("fbegin.inc"); ?>
501 8ff5ffcc Matthew Grooms
<script language="JavaScript">
502
<!--
503
504
function encrypt_change() {
505
506
	if (!document.iform.encrypt.checked)
507
		document.getElementById("encrypt_opts").style.display="none";
508
	else
509
		document.getElementById("encrypt_opts").style.display="";
510
}
511
512
function decrypt_change() {
513
514
	if (!document.iform.decrypt.checked)
515
		document.getElementById("decrypt_opts").style.display="none";
516
	else
517
		document.getElementById("decrypt_opts").style.display="";
518
}
519
520 a1003d57 Ermal Lu?i
function backuparea_change(obj) {
521
522
        if (obj.value == "")
523
                document.getElementById("dotnotbackuprrd").checked = false;
524
        else
525
                document.getElementById("dotnotbackuprrd").checked = true;
526
}
527 8ff5ffcc Matthew Grooms
//-->
528
</script>
529 344c68b2 sullrich
530 9e2a4fce Erik Kristensen
<?php if ($input_errors) print_input_errors($input_errors); ?>
531
<?php if ($savemsg) print_info_box($savemsg); ?>
532 da17d77e Ermal Lu?i
<?php if (is_subsystem_dirty('restore')): ?><p>
533 344c68b2 sullrich
<form action="reboot.php" method="post">
534
<input name="Submit" type="hidden" value=" Yes ">
535 8246efa6 Renato Botelho
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br/>" . gettext("The firewall is now rebooting."));?><br>
536 344c68b2 sullrich
</form>
537 da17d77e Ermal Lu?i
<?php endif; ?>
538 344c68b2 sullrich
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
539 9e2a4fce Erik Kristensen
<table width="100%" border="0" cellspacing="0" cellpadding="0">
540
	<tr>
541
		<td>
542 12af52d9 Scott Ullrich
<?php
543 9e2a4fce Erik Kristensen
		$tab_array = array();
544 205da5a0 Neriberto C.Prado
		$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
545
		$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
546 9e2a4fce Erik Kristensen
		display_top_tabs($tab_array);
547 645ec835 Scott Ullrich
?>
548 9e2a4fce Erik Kristensen
		</td>
549
	</tr>
550
	<tr>
551
		<td>
552
			<div id="mainarea">
553
			<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
554
				<tr>
555 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Backup configuration"); ?></td>
556 9e2a4fce Erik Kristensen
				</tr>
557
				<tr>
558
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
559
					<td width="78%" class="vtable">
560 591586e3 Neriberto C.Prado
						<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>
561 8ff5ffcc Matthew Grooms
						<table>
562
							<tr>
563
								<td>
564
									<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">
565
								</td>
566
								<td>
567 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Do not backup package information."); ?></span>
568 8ff5ffcc Matthew Grooms
								</td>
569
							</tr>
570
						</table>
571
						<table>
572
							<tr>
573
								<td>
574
									<input name="encrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="encrypt_change()">
575
								</td>
576
								<td>
577 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
578 8ff5ffcc Matthew Grooms
								</td>
579
							</tr>
580 1390b049 Scott Ullrich
							<tr>
581
								<td>
582 a2fb9e48 jim-p
									<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd" checked>
583 1390b049 Scott Ullrich
								</td>
584
								<td>
585 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)"); ?></span>
586 1390b049 Scott Ullrich
								</td>
587
							</tr>
588 8ff5ffcc Matthew Grooms
						</table>
589
						<table id="encrypt_opts">
590
							<tr>
591
								<td>
592 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("Password:"); ?> </span>
593 8ff5ffcc Matthew Grooms
								</td>
594
								<td>
595
									<input name="encrypt_password" type="password" class="formfld pwd" size="20" value="" />
596
								</td>
597
							</tr>
598
							<tr>
599
								<td>
600 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("confirm:"); ?> </span>
601 8ff5ffcc Matthew Grooms
								</td>
602
								<td>
603
									<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
604
								</td>
605
							</tr>
606
						</table>
607 42aa088e Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="download" value="<?=gettext("Download configuration"); ?>"></p>
608 9e2a4fce Erik Kristensen
					</td>
609
				</tr>
610
				<tr>
611
					<td colspan="2" class="list" height="12">&nbsp;</td>
612 5b237745 Scott Ullrich
                </tr>
613 8ccc8f1a Scott Ullrich
                <tr>
614 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Restore configuration"); ?></td>
615 9e2a4fce Erik Kristensen
				</tr>
616
				<tr>
617
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
618
					<td width="78%" class="vtable">
619 591586e3 Neriberto C.Prado
						<?=gettext("Open a"); ?> <?=$g['[product_name']?> <?=gettext("configuration XML file and click the button below to restore the configuration."); ?> <br /><br /> <?=gettext("Restore area:"); ?> <?php spit_out_select_items("restorearea", true); ?>
620 b5c78501 Seth Mos
						<p><input name="conffile" type="file" class="formfld unknown" id="conffile" size="40"></p>
621 8ff5ffcc Matthew Grooms
						<table>
622
							<tr>
623
								<td>
624
									<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="decrypt_change()">
625
								</td>
626
								<td>
627 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
628 8ff5ffcc Matthew Grooms
								</td>
629
							</tr>
630
						</table>
631
						<table id="decrypt_opts">
632
							<tr>
633
								<td>
634 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Password :"); ?></span>
635 8ff5ffcc Matthew Grooms
								</td>
636
								<td>
637
									<input name="decrypt_password" type="password" class="formfld pwd" size="20" value="" />
638
								</td>
639
							</tr>
640
							<tr>
641
								<td>
642 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("confirm :"); ?></span>
643 8ff5ffcc Matthew Grooms
								</td>
644
								<td>
645
									<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
646
								</td>
647
							</tr>
648
						</table>
649 b639d5cd Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="restore" value="<?=gettext("Restore configuration"); ?>"></p>
650 c0948c6c Renato Botelho
						<p><strong><span class="red"><?=gettext("Note:"); ?></span></strong><br /><?=gettext("The firewall will reboot after restoring the configuration."); ?><br /></p>
651 9e2a4fce Erik Kristensen
					</td>
652
				</tr>
653
				<?php if($config['installedpackages']['package'] != "") { ?>
654
				<tr>
655
					<td colspan="2" class="list" height="12">&nbsp;</td>
656
				</tr>
657
				<tr>
658 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Reinstall packages"); ?></td>
659 9e2a4fce Erik Kristensen
				</tr>
660
				<tr>
661
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
662
					<td width="78%" class="vtable">
663 591586e3 Neriberto C.Prado
						<p><?=gettext("Click this button to reinstall all system packages.  This may take a while."); ?> <br /><br />
664 e085ff29 Carlos Eduardo Ramos
		  				<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="<?=gettext("Reinstall packages"); ?>">
665 9e2a4fce Erik Kristensen
					</td>
666
				</tr>
667
				<?php } ?>
668
			</table>
669
			</div>
670 b24bf37b Colin Smith
		</td>
671 9e2a4fce Erik Kristensen
	</tr>
672
</table>
673
</form>
674
675 8ff5ffcc Matthew Grooms
<script language="JavaScript">
676
<!--
677
encrypt_change();
678
decrypt_change();
679
//-->
680
</script>
681
682 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
683
</body>
684 38d48421 Colin Smith
</html>
685 7a7f3af1 sullrich
<?php
686
687
if (is_subsystem_dirty('restore'))
688 cf9a4467 jim-p
	system_reboot();
689 7a7f3af1 sullrich
690 a1003d57 Ermal Lu?i
?>