Project

General

Profile

Download (25.1 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 cfbfd941 smos
	$base_packages = explode($g['base_packages'], ",");
61 3420028c Scott Ullrich
	$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 039cb920 jim-p
	else if (stristr($_POST['Submit'], gettext("Clear Package Lock")))
162
		$mode = "clearpackagelock";
163 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Download")))
164 5b237745 Scott Ullrich
		$mode = "download";
165 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Restore version")))
166 7cf03119 Bill Marquette
		$mode = "restore_ver";
167
168 aab57926 Scott Ullrich
	if ($_POST["nopackages"] <> "")
169 528cad39 Colin Smith
		$options = "nopackages";
170 8ccc8f1a Scott Ullrich
171 7cf03119 Bill Marquette
	if ($_POST["ver"] <> "")
172
		$ver2restore = $_POST["ver"];
173
174 5b237745 Scott Ullrich
	if ($mode) {
175 8ff5ffcc Matthew Grooms
176 5b237745 Scott Ullrich
		if ($mode == "download") {
177 8ff5ffcc Matthew Grooms
178
			if ($_POST['encrypt']) {
179
				if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
180 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
181 8ff5ffcc Matthew Grooms
				if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
182 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
183 528cad39 Colin Smith
			}
184 8ff5ffcc Matthew Grooms
185
			if (!$input_errors) {
186
187 07b1797b sullrich
				//$lockbckp = lock('config');
188 8ff5ffcc Matthew Grooms
189
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
190
				$name = "config-{$host}-".date("YmdHis").".xml";
191
				$data = "";
192
193
				if($options == "nopackages") {
194 4195c967 sullrich
					if(!$_POST['backuparea']) {
195
						/* backup entire configuration */
196
						$data = file_get_contents("{$g['conf_path']}/config.xml");
197
					} else {
198
						/* backup specific area of configuration */
199
						$data = backup_config_section($_POST['backuparea']);
200
						$name = "{$_POST['backuparea']}-{$name}";
201
					}
202 da17d77e Ermal Lu?i
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
203 4195c967 sullrich
					file_put_contents($sfn, $data);
204
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
205 a250f179 Renato Botelho
					$data = file_get_contents($sfn . "-new");
206 8ff5ffcc Matthew Grooms
				} else {
207
					if(!$_POST['backuparea']) {
208
						/* backup entire configuration */
209
						$data = file_get_contents("{$g['conf_path']}/config.xml");
210
					} else {
211
						/* backup specific area of configuration */
212
						$data = backup_config_section($_POST['backuparea']);
213
						$name = "{$_POST['backuparea']}-{$name}";
214
					}
215 181462b5 Scott Ullrich
				}
216 8ff5ffcc Matthew Grooms
217 07b1797b sullrich
				//unlock($lockbckp);
218 da17d77e Ermal Lu?i
219 8ff5ffcc Matthew Grooms
				if ($_POST['encrypt']) {
220
					$data = encrypt_data($data, $_POST['encrypt_password']);
221
					tagfile_reformat($data, $data, "config.xml");
222 181462b5 Scott Ullrich
				}
223 8ff5ffcc Matthew Grooms
224 a250f179 Renato Botelho
				/*
225 1390b049 Scott Ullrich
				 *  Backup RRD Data
226
				 */
227
				if(!$_POST['donotbackuprrd']) {
228 67bc955d Chris Buechler
					$data = str_replace("</" . $g['xml_rootobj'] . ">", "\t<rrddata>", $data);
229 cfbfd941 smos
					$rrd_files_var_db_rrd = explode("\n",`cd /var/db/rrd && ls *.rrd`);
230 1390b049 Scott Ullrich
					foreach($rrd_files_var_db_rrd as $rrd) {
231
						if($rrd) {
232
							$rrd_data = file_get_contents("{$g['vardb_path']}/rrd/{$rrd}");
233
							if($rrd_data) {
234
								$data .= "\t\t<rrddatafile>\n";
235
								$data .= "\t\t\t<filename>{$rrd}</filename>\n";
236 2c9a4ed1 jim-p
								$data .= "\t\t\t<data>" . base64_encode(gzdeflate($rrd_data)) . "</data>\n";
237 1390b049 Scott Ullrich
								$data .= "\t\t</rrddatafile>\n";
238
							}
239
						}
240
					}
241
					$data .= "\t</rrddata>\n";
242 67bc955d Chris Buechler
					$data .= "</" . $g['xml_rootobj'] . ">\n";
243 1390b049 Scott Ullrich
				}
244 a250f179 Renato Botelho
245 8ff5ffcc Matthew Grooms
				$size = strlen($data);
246
				header("Content-Type: application/octet-stream");
247
				header("Content-Disposition: attachment; filename={$name}");
248 a8c35980 Scott Ullrich
				header("Content-Length: $size");
249 e77ea573 jim-p
				if (isset($_SERVER['HTTPS'])) {
250
					header('Pragma: ');
251
					header('Cache-Control: ');
252
				} else {
253
					header("Pragma: private");
254
					header("Cache-Control: private, must-revalidate");
255
				}
256 8ff5ffcc Matthew Grooms
				echo $data;
257
258
				exit;
259
			}
260
		}
261
262
		if ($mode == "restore") {
263
264
			if ($_POST['decrypt']) {
265
				if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
266 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
267 8ff5ffcc Matthew Grooms
				if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
268 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
269 8ff5ffcc Matthew Grooms
			}
270
271
			if (!$input_errors) {
272
273
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
274
275
					/* read the file contents */
276
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
277
					if(!$data) {
278 dae4c487 Carlos Eduardo Ramos
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
279 8ff5ffcc Matthew Grooms
						return 1;
280 9fd18b1f Scott Ullrich
					}
281 8ff5ffcc Matthew Grooms
282
					if ($_POST['decrypt']) {
283
						if (!tagfile_deformat($data, $data, "config.xml")) {
284 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
285 8ff5ffcc Matthew Grooms
							return 1;
286
						}
287
						$data = decrypt_data($data, $_POST['decrypt_password']);
288
					}
289
290 1d683793 sullrich
					if(stristr($data, "<m0n0wall>")) {
291 205da5a0 Neriberto C.Prado
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
292 8ff5ffcc Matthew Grooms
						/* m0n0wall was found in config.  convert it. */
293
						$data = str_replace("m0n0wall", "pfsense", $data);
294
						$m0n0wall_upgrade = true;
295
					}
296
					if($_POST['restorearea']) {
297
						/* restore a specific area of the configuration */
298
						if(!stristr($data, $_POST['restorearea'])) {
299 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
300 8ff5ffcc Matthew Grooms
						} else {
301
							restore_config_section($_POST['restorearea'], $data);
302
							filter_configure();
303 205da5a0 Neriberto C.Prado
							$savemsg = gettext("The configuration area has been restored.  You may need to reboot the firewall.");
304 8ff5ffcc Matthew Grooms
						}
305 181462b5 Scott Ullrich
					} else {
306 6819b7f6 Renato Botelho
						if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
307 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']);
308 8ff5ffcc Matthew Grooms
						} else {
309
							/* restore the entire configuration */
310
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
311
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
312
								/* this will be picked up by /index.php */
313
								conf_mount_rw();
314 da17d77e Ermal Lu?i
								mark_subsystem_dirty("restore");
315 09821234 Scott Ullrich
								touch("/conf/needs_package_sync");
316 8ff5ffcc Matthew Grooms
								/* remove cache, we will force a config reboot */
317 da17d77e Ermal Lu?i
								if(file_exists("{$g['tmp_path']}/config.cache"))
318
									unlink("{$g['tmp_path']}/config.cache");
319 8ff5ffcc Matthew Grooms
								$config = parse_config(true);
320 67bc955d Chris Buechler
								/* extract out rrd items, unset from $config when done */
321 1390b049 Scott Ullrich
								if($config['rrddata']) {
322
									foreach($config['rrddata']['rrddatafile'] as $rrd) {
323
										$rrd_fd = fopen("{$g['vardb_path']}/rrd/{$rrd['filename']}", "w");
324 2c9a4ed1 jim-p
										$data = base64_decode($rrd['data']);
325
										/* Try to decompress the data. */
326
										$dcomp = @gzinflate($data);
327
										if ($dcomp) {
328
											/* If the decompression worked, write the decompressed data */
329
											fwrite($rrd_fd, $dcomp);
330
										} else {
331
											/* If the decompression failed, it wasn't compressed, so write raw data */
332
											fwrite($rrd_fd, $data);
333
										}
334 1390b049 Scott Ullrich
										fclose($rrd_fd);
335
									}
336 a2b8f7b2 Scott Ullrich
									unset($config['rrddata']);
337 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
338 a2b8f7b2 Scott Ullrich
									write_config();
339 3420028c Scott Ullrich
									add_base_packages_menu_items();
340 d442e4e2 Scott Ullrich
									convert_config();
341 a2b8f7b2 Scott Ullrich
									conf_mount_ro();
342 1390b049 Scott Ullrich
								}
343 8ff5ffcc Matthew Grooms
								if($m0n0wall_upgrade == true) {
344
									if($config['system']['gateway'] <> "")
345
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
346
									unset($config['shaper']);
347
									/* optional if list */
348
									$ifdescrs = get_configured_interface_list(true, true);
349
									/* remove special characters from interface descriptions */
350
									if(is_array($ifdescrs))
351
										foreach($ifdescrs as $iface)
352
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
353 b6db8ea3 sullrich
									/* check for interface names with an alias */
354
									if(is_array($ifdescrs)) {
355
										foreach($ifdescrs as $iface) {
356
											if(is_alias($config['interfaces'][$iface]['descr'])) {
357
												// Firewall rules
358
												$origname = $config['interfaces'][$iface]['descr'];
359
												$newname  = $config['interfaces'][$iface]['descr'] . "Alias";
360 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
361
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
362 b6db8ea3 sullrich
												// NAT Rules
363 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
364
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
365
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
366 b6db8ea3 sullrich
												// Alias in an alias
367 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
368 b6db8ea3 sullrich
											}
369
										}
370
									}
371 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
372 888e7a27 Scott Ullrich
									// Reset configuration version to something low
373 a250f179 Renato Botelho
									// in order to force the config upgrade code to
374 888e7a27 Scott Ullrich
									// run through with all steps that are required.
375
									$config['system']['version'] = "1.0";
376 798cb31a Scott Ullrich
									// Deal with descriptions longer than 63 characters
377
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
378
										if(count($config['filter']['rule'][$i]['descr']) > 63)
379
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
380
									}
381
									// Move interface from ipsec to enc0
382
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
383
										if($config['filter']['rule'][$i]['interface'] == "ipsec")
384
											$config['filter']['rule'][$i]['interface'] = "enc0";
385
									}
386
									// Convert icmp types
387
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
388
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
389
										if($config["filter"]["rule"][$i]['icmptype']) {
390
											switch($config["filter"]["rule"][$i]['icmptype']) {
391
												case "echo":
392
													$config["filter"]["rule"][$i]['icmptype'] = "echoreq";
393
													break;
394
					                            case "unreach":
395
													$config["filter"]["rule"][$i]['icmptype'] = "unreach";
396
													break;
397
					                            case "echorep":
398
													$config["filter"]["rule"][$i]['icmptype'] = "echorep";
399
													break;
400
					                            case "squench":
401
													$config["filter"]["rule"][$i]['icmptype'] = "squench";
402
													break;
403
					                            case "redir":
404
													$config["filter"]["rule"][$i]['icmptype'] = "redir";
405
													break;
406
					                            case "timex":
407
													$config["filter"]["rule"][$i]['icmptype'] = "timex";
408
													break;
409
					                            case "paramprob":
410
													$config["filter"]["rule"][$i]['icmptype'] = "paramprob";
411
													break;
412
					                            case "timest":
413
													$config["filter"]["rule"][$i]['icmptype'] = "timereq";
414
													break;
415
					                            case "timestrep":
416
													$config["filter"]["rule"][$i]['icmptype'] = "timerep";
417
													break;
418
					                            case "inforeq":
419
													$config["filter"]["rule"][$i]['icmptype'] = "inforeq";
420
													break;
421
					                            case "inforep":
422
													$config["filter"]["rule"][$i]['icmptype'] = "inforep";
423
													break;
424
					                            case "maskreq":
425
													$config["filter"]["rule"][$i]['icmptype'] = "maskreq";
426
													break;
427
					                            case "maskrep":
428
													$config["filter"]["rule"][$i]['icmptype'] = "maskrep";
429
													break;
430
											}
431
										}
432 dec5cb85 Scott Ullrich
									}
433
									$config['diag']['ipv6nat'] = true;
434 8ff5ffcc Matthew Grooms
									write_config();
435 a250f179 Renato Botelho
									add_base_packages_menu_items();
436 d442e4e2 Scott Ullrich
									convert_config();
437 8ff5ffcc Matthew Grooms
									conf_mount_ro();
438 205da5a0 Neriberto C.Prado
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
439 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
440 8ff5ffcc Matthew Grooms
								}
441
								if(isset($config['captiveportal']['enable'])) {
442
									/* for some reason ipfw doesn't init correctly except on bootup sequence */
443 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
444 8ff5ffcc Matthew Grooms
								}
445
								setup_serial_port();
446
								if(is_interface_mismatch() == true) {
447
									touch("/var/run/interface_mismatch_reboot_needed");
448 da17d77e Ermal Lu?i
									clear_subsystem_dirty("restore");
449 f5a57bb0 Scott Ullrich
									convert_config();
450 8ff5ffcc Matthew Grooms
									header("Location: interfaces_assign.php");
451 bafaf123 Scott Ullrich
									exit;
452 8ff5ffcc Matthew Grooms
								}
453 66bcba1b Ermal
								if (is_interface_vlan_mismatch() == true) {
454
									touch("/var/run/interface_mismatch_reboot_needed");
455
									clear_subsystem_dirty("restore");
456
									convert_config();
457
									header("Location: interfaces_assign.php");
458
									exit;
459
								}
460 8ff5ffcc Matthew Grooms
							} else {
461 205da5a0 Neriberto C.Prado
								$input_errors[] = gettext("The configuration could not be restored.");
462 db3996df Scott Ullrich
							}
463 9c72b993 Scott Ullrich
						}
464 181462b5 Scott Ullrich
					}
465 8ff5ffcc Matthew Grooms
				} else {
466 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
467 db3996df Scott Ullrich
				}
468 5b237745 Scott Ullrich
			}
469 8ff5ffcc Matthew Grooms
		}
470
471
		if ($mode == "reinstallpackages") {
472
473 8ccc8f1a Scott Ullrich
			header("Location: pkg_mgr_install.php?mode=reinstallall");
474
			exit;
475 039cb920 jim-p
		} else if ($mode == "clearpackagelock") {
476
			clear_subsystem_dirty('packagelock');
477
			$savemsg = "Package Lock Cleared";
478 7cf03119 Bill Marquette
                } else if ($mode == "restore_ver") {
479 205da5a0 Neriberto C.Prado
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
480 7cf03119 Bill Marquette
			if ($ver2restore <> "") {
481
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
482 343bb325 sullrich
				if (config_install($conf_file) == 0) {
483
						mark_subsystem_dirty("restore");
484 7cf03119 Bill Marquette
                        } else {
485 205da5a0 Neriberto C.Prado
                        	$input_errors[] = gettext("The configuration could not be restored.");
486 7cf03119 Bill Marquette
                        }
487 343bb325 sullrich
                } else {
488 205da5a0 Neriberto C.Prado
                        $input_errors[] = gettext("No version selected.");
489 343bb325 sullrich
                }
490 5b237745 Scott Ullrich
		}
491
	}
492
}
493 6a1e6651 Bill Marquette
494 02e1170d Scott Ullrich
$id = rand() . '.' . time();
495
496
$mth = ini_get('upload_progress_meter.store_method');
497
$dir = ini_get('upload_progress_meter.file.filename_template');
498
499 205da5a0 Neriberto C.Prado
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
500 b63695db Scott Ullrich
include("head.inc");
501
502 5b237745 Scott Ullrich
?>
503
504
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
505
<?php include("fbegin.inc"); ?>
506 8ff5ffcc Matthew Grooms
<script language="JavaScript">
507
<!--
508
509
function encrypt_change() {
510
511
	if (!document.iform.encrypt.checked)
512
		document.getElementById("encrypt_opts").style.display="none";
513
	else
514
		document.getElementById("encrypt_opts").style.display="";
515
}
516
517
function decrypt_change() {
518
519
	if (!document.iform.decrypt.checked)
520
		document.getElementById("decrypt_opts").style.display="none";
521
	else
522
		document.getElementById("decrypt_opts").style.display="";
523
}
524
525 a1003d57 Ermal Lu?i
function backuparea_change(obj) {
526
527
        if (obj.value == "")
528
                document.getElementById("dotnotbackuprrd").checked = false;
529
        else
530
                document.getElementById("dotnotbackuprrd").checked = true;
531
}
532 8ff5ffcc Matthew Grooms
//-->
533
</script>
534 344c68b2 sullrich
535 9e2a4fce Erik Kristensen
<?php if ($input_errors) print_input_errors($input_errors); ?>
536
<?php if ($savemsg) print_info_box($savemsg); ?>
537 da17d77e Ermal Lu?i
<?php if (is_subsystem_dirty('restore')): ?><p>
538 344c68b2 sullrich
<form action="reboot.php" method="post">
539
<input name="Submit" type="hidden" value=" Yes ">
540 8246efa6 Renato Botelho
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br/>" . gettext("The firewall is now rebooting."));?><br>
541 344c68b2 sullrich
</form>
542 da17d77e Ermal Lu?i
<?php endif; ?>
543 344c68b2 sullrich
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
544 9e2a4fce Erik Kristensen
<table width="100%" border="0" cellspacing="0" cellpadding="0">
545
	<tr>
546
		<td>
547 12af52d9 Scott Ullrich
<?php
548 9e2a4fce Erik Kristensen
		$tab_array = array();
549 205da5a0 Neriberto C.Prado
		$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
550
		$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
551 9e2a4fce Erik Kristensen
		display_top_tabs($tab_array);
552 645ec835 Scott Ullrich
?>
553 9e2a4fce Erik Kristensen
		</td>
554
	</tr>
555
	<tr>
556
		<td>
557
			<div id="mainarea">
558
			<table class="tabcont" align="center" width="100%" border="0" cellpadding="6" cellspacing="0">
559
				<tr>
560 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Backup configuration"); ?></td>
561 9e2a4fce Erik Kristensen
				</tr>
562
				<tr>
563
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
564
					<td width="78%" class="vtable">
565 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>
566 8ff5ffcc Matthew Grooms
						<table>
567
							<tr>
568
								<td>
569
									<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">
570
								</td>
571
								<td>
572 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Do not backup package information."); ?></span>
573 8ff5ffcc Matthew Grooms
								</td>
574
							</tr>
575
						</table>
576
						<table>
577
							<tr>
578
								<td>
579
									<input name="encrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="encrypt_change()">
580
								</td>
581
								<td>
582 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
583 8ff5ffcc Matthew Grooms
								</td>
584
							</tr>
585 1390b049 Scott Ullrich
							<tr>
586
								<td>
587 a2fb9e48 jim-p
									<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd" checked>
588 1390b049 Scott Ullrich
								</td>
589
								<td>
590 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>
591 1390b049 Scott Ullrich
								</td>
592
							</tr>
593 8ff5ffcc Matthew Grooms
						</table>
594
						<table id="encrypt_opts">
595
							<tr>
596
								<td>
597 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("Password:"); ?> </span>
598 8ff5ffcc Matthew Grooms
								</td>
599
								<td>
600
									<input name="encrypt_password" type="password" class="formfld pwd" size="20" value="" />
601
								</td>
602
							</tr>
603
							<tr>
604
								<td>
605 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("confirm:"); ?> </span>
606 8ff5ffcc Matthew Grooms
								</td>
607
								<td>
608
									<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
609
								</td>
610
							</tr>
611
						</table>
612 42aa088e Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="download" value="<?=gettext("Download configuration"); ?>"></p>
613 9e2a4fce Erik Kristensen
					</td>
614
				</tr>
615
				<tr>
616
					<td colspan="2" class="list" height="12">&nbsp;</td>
617 5b237745 Scott Ullrich
                </tr>
618 8ccc8f1a Scott Ullrich
                <tr>
619 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Restore configuration"); ?></td>
620 9e2a4fce Erik Kristensen
				</tr>
621
				<tr>
622
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
623
					<td width="78%" class="vtable">
624 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); ?>
625 b5c78501 Seth Mos
						<p><input name="conffile" type="file" class="formfld unknown" id="conffile" size="40"></p>
626 8ff5ffcc Matthew Grooms
						<table>
627
							<tr>
628
								<td>
629
									<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="decrypt_change()">
630
								</td>
631
								<td>
632 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
633 8ff5ffcc Matthew Grooms
								</td>
634
							</tr>
635
						</table>
636
						<table id="decrypt_opts">
637
							<tr>
638
								<td>
639 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Password :"); ?></span>
640 8ff5ffcc Matthew Grooms
								</td>
641
								<td>
642
									<input name="decrypt_password" type="password" class="formfld pwd" size="20" value="" />
643
								</td>
644
							</tr>
645
							<tr>
646
								<td>
647 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("confirm :"); ?></span>
648 8ff5ffcc Matthew Grooms
								</td>
649
								<td>
650
									<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
651
								</td>
652
							</tr>
653
						</table>
654 b639d5cd Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="restore" value="<?=gettext("Restore configuration"); ?>"></p>
655 c0948c6c Renato Botelho
						<p><strong><span class="red"><?=gettext("Note:"); ?></span></strong><br /><?=gettext("The firewall will reboot after restoring the configuration."); ?><br /></p>
656 9e2a4fce Erik Kristensen
					</td>
657
				</tr>
658
				<?php if($config['installedpackages']['package'] != "") { ?>
659
				<tr>
660
					<td colspan="2" class="list" height="12">&nbsp;</td>
661
				</tr>
662
				<tr>
663 039cb920 jim-p
					<td colspan="2" class="listtopic"><?=gettext("Package Functions"); ?></td>
664 9e2a4fce Erik Kristensen
				</tr>
665
				<tr>
666
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
667
					<td width="78%" class="vtable">
668 591586e3 Neriberto C.Prado
						<p><?=gettext("Click this button to reinstall all system packages.  This may take a while."); ?> <br /><br />
669 e085ff29 Carlos Eduardo Ramos
		  				<input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="<?=gettext("Reinstall packages"); ?>">
670 039cb920 jim-p
						<br/>
671
						<br/>
672
						<p><?=gettext("Click this button to clear the package lock if a package fails to reinstall properly after an upgrade."); ?> <br /><br />
673
						<input name="Submit" type="submit" class="formbtn" id="clearpackagelock" value="<?=gettext("Clear Package Lock"); ?>">
674 9e2a4fce Erik Kristensen
					</td>
675
				</tr>
676
				<?php } ?>
677
			</table>
678
			</div>
679 b24bf37b Colin Smith
		</td>
680 9e2a4fce Erik Kristensen
	</tr>
681
</table>
682
</form>
683
684 8ff5ffcc Matthew Grooms
<script language="JavaScript">
685
<!--
686
encrypt_change();
687
decrypt_change();
688
//-->
689
</script>
690
691 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
692
</body>
693 38d48421 Colin Smith
</html>
694 7a7f3af1 sullrich
<?php
695
696
if (is_subsystem_dirty('restore'))
697 cf9a4467 jim-p
	system_reboot();
698 7a7f3af1 sullrich
699 a1003d57 Ermal Lu?i
?>