Project

General

Profile

Download (27.3 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 8bdb6879 Darren Embry
$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 73ed069b Renato Botelho
65 8bdb6879 Darren Embry
	$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 754b75d0 Darren Embry
function restore_rrddata() {
86 7eead1fc Darren Embry
	global $config, $g, $rrdtool, $input_errors;
87 754b75d0 Darren Embry
	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 08877746 Darren Embry
			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 f757431d Darren Embry
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
100 08877746 Darren Embry
				continue;
101
			}
102 754b75d0 Darren Embry
			unlink($xml_file);
103
		}
104
		else if ($rrd['data']) {
105 7eead1fc Darren Embry
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
106
			$rrd_fd = fopen($rrd_file, "w");
107 08877746 Darren Embry
			if (!$rrd_fd) {
108
				log_error("Cannot write $rrd_file");
109
				continue;
110
			}
111 754b75d0 Darren Embry
			$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 08877746 Darren Embry
				if (fwrite($rrd_fd, $dcomp) === false) {
117
					log_error("fwrite $rrd_file failed");
118
					continue;
119
				}
120 754b75d0 Darren Embry
			} else {
121
				/* If the decompression failed, it wasn't compressed, so write raw data */
122 08877746 Darren Embry
				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 754b75d0 Darren Embry
			}
131
		}
132
	}
133
}
134
135 3420028c Scott Ullrich
function add_base_packages_menu_items() {
136
	global $g, $config;
137 cfbfd941 smos
	$base_packages = explode($g['base_packages'], ",");
138 3420028c Scott Ullrich
	$modified_config = false;
139
	foreach($base_packages as $bp) {
140 da17d77e Ermal Lu?i
		$basepkg_path = "/usr/local/pkg/{$bp}";
141 a250f179 Renato Botelho
		$tmpinfo = pathinfo($basepkg_path, PATHINFO_EXTENSION);
142 da17d77e Ermal Lu?i
		if($tmpinfo['extension'] == "xml" && file_exists($basepkg_path)) {
143
			$pkg_config = parse_xml_config_pkg($basepkg_path, "packagegui");
144 3420028c Scott Ullrich
			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 f3ceee6e Vinicius Coque
		write_config(gettext("Restored base_package menus after configuration restore."));
162 3420028c Scott Ullrich
		$config = parse_config(true);
163
	}
164
}
165
166 645ec835 Scott Ullrich
function remove_bad_chars($string) {
167 0e1619be Erik Fonnesbeck
	return preg_replace('/[^a-z_0-9]/i','',$string);
168 645ec835 Scott Ullrich
}
169
170 b3277798 Scott Ullrich
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 7eead1fc Darren Embry
function spit_out_select_items($name, $showall) {
178 b3277798 Scott Ullrich
	global $config;
179 73ed069b Renato Botelho
180 a250f179 Renato Botelho
	$areas = array("aliases" => gettext("Aliases"),
181 c9a19238 Darren Embry
		       "captiveportal" => gettext("Captive Portal"),
182
		       "voucher" => gettext("Captive Portal Vouchers"),
183
		       "dnsmasq" => gettext("DNS Forwarder"),
184
		       "dhcpd" => gettext("DHCP Server"),
185 63e9efc9 Renato Botelho
		       "dhcpdv6" => gettext("DHCPv6 Server"),
186 c9a19238 Darren Embry
		       "filter" => gettext("Firewall Rules"),
187
		       "interfaces" => gettext("Interfaces"),
188
		       "ipsec" => gettext("IPSEC"),
189
		       "nat" => gettext("NAT"),
190
		       "ovpn" => gettext("OpenVPN"),
191
		       "installedpackages" => gettext("Package Manager"),
192
		       "pptpd" => gettext("PPTP Server"),
193 7eead1fc Darren Embry
		       "rrddata" => gettext("RRD Data"),
194 c9a19238 Darren Embry
		       "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 7eead1fc Darren Embry
205
	$select  = "<select name=\"{$name}\" id=\"{$name}\">";
206 e085ff29 Carlos Eduardo Ramos
	$select .= "<option VALUE=\"\">" . gettext("ALL") . "</option>";
207 73ed069b Renato Botelho
208 a250f179 Renato Botelho
	if($showall == true)
209 eef938b5 Scott Ullrich
		foreach($areas as $area => $areaname)
210
			$select .= "<option value='{$area}'>{$areaname}</option>\n";
211 a250f179 Renato Botelho
	else
212 3244aa21 Scott Ullrich
		foreach($areas as $area => $areaname)
213 7eead1fc Darren Embry
			if($area === "rrddata" || check_and_returnif_section_exists($area) == true)
214 3244aa21 Scott Ullrich
				$select .= "<option value='{$area}'>{$areaname}</option>\n";
215 7eead1fc Darren Embry
216 b3277798 Scott Ullrich
	$select .= "</select>\n";
217 7eead1fc Darren Embry
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 73ed069b Renato Botelho
230 8e35abee Scott Ullrich
	echo $select;
231 73ed069b Renato Botelho
232 8e35abee Scott Ullrich
}
233
234 da17d77e Ermal Lu?i
if ($_POST['apply']) {
235 73ed069b Renato Botelho
	ob_flush();
236
	flush();
237 c9a19238 Darren Embry
	conf_mount_rw();
238
	clear_subsystem_dirty("restore");
239
	conf_mount_ro();
240 73ed069b Renato Botelho
	exit;
241 da17d77e Ermal Lu?i
}
242
243 5b237745 Scott Ullrich
if ($_POST) {
244
	unset($input_errors);
245 8246efa6 Renato Botelho
	if (stristr($_POST['Submit'], gettext("Restore configuration")))
246 5b237745 Scott Ullrich
		$mode = "restore";
247 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Reinstall")))
248 8ccc8f1a Scott Ullrich
		$mode = "reinstallpackages";
249 039cb920 jim-p
	else if (stristr($_POST['Submit'], gettext("Clear Package Lock")))
250
		$mode = "clearpackagelock";
251 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Download")))
252 5b237745 Scott Ullrich
		$mode = "download";
253 8246efa6 Renato Botelho
	else if (stristr($_POST['Submit'], gettext("Restore version")))
254 7cf03119 Bill Marquette
		$mode = "restore_ver";
255 73ed069b Renato Botelho
256 aab57926 Scott Ullrich
	if ($_POST["nopackages"] <> "")
257 528cad39 Colin Smith
		$options = "nopackages";
258 73ed069b Renato Botelho
259 7cf03119 Bill Marquette
	if ($_POST["ver"] <> "")
260
		$ver2restore = $_POST["ver"];
261 73ed069b Renato Botelho
262 5b237745 Scott Ullrich
	if ($mode) {
263 73ed069b Renato Botelho
264 5b237745 Scott Ullrich
		if ($mode == "download") {
265 73ed069b Renato Botelho
266 8ff5ffcc Matthew Grooms
			if ($_POST['encrypt']) {
267
				if(!$_POST['encrypt_password'] || !$_POST['encrypt_passconf'])
268 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for encryption.");
269 8ff5ffcc Matthew Grooms
				if($_POST['encrypt_password'] != $_POST['encrypt_passconf'])
270 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
271 528cad39 Colin Smith
			}
272 73ed069b Renato Botelho
273 8ff5ffcc Matthew Grooms
			if (!$input_errors) {
274 73ed069b Renato Botelho
275 07b1797b sullrich
				//$lockbckp = lock('config');
276 73ed069b Renato Botelho
277 8ff5ffcc Matthew Grooms
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
278
				$name = "config-{$host}-".date("YmdHis").".xml";
279
				$data = "";
280 73ed069b Renato Botelho
281 8ff5ffcc Matthew Grooms
				if($options == "nopackages") {
282 4195c967 sullrich
					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 da17d77e Ermal Lu?i
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
291 4195c967 sullrich
					file_put_contents($sfn, $data);
292
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
293 a250f179 Renato Botelho
					$data = file_get_contents($sfn . "-new");
294 8ff5ffcc Matthew Grooms
				} else {
295
					if(!$_POST['backuparea']) {
296
						/* backup entire configuration */
297
						$data = file_get_contents("{$g['conf_path']}/config.xml");
298 7eead1fc Darren Embry
					} else if ($_POST['backuparea'] === "rrddata") {
299
						$data = rrd_data_xml();
300
						$name = "{$_POST['backuparea']}-{$name}";
301 8ff5ffcc Matthew Grooms
					} else {
302
						/* backup specific area of configuration */
303
						$data = backup_config_section($_POST['backuparea']);
304
						$name = "{$_POST['backuparea']}-{$name}";
305
					}
306 181462b5 Scott Ullrich
				}
307 73ed069b Renato Botelho
308 07b1797b sullrich
				//unlock($lockbckp);
309 73ed069b Renato Botelho
310 a250f179 Renato Botelho
				/*
311 1390b049 Scott Ullrich
				 *  Backup RRD Data
312
				 */
313 7eead1fc Darren Embry
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
314 8bdb6879 Darren Embry
					$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 1390b049 Scott Ullrich
				}
318 73ed069b Renato Botelho
319 4cfd2390 Renato Botelho
				if ($_POST['encrypt']) {
320
					$data = encrypt_data($data, $_POST['encrypt_password']);
321
					tagfile_reformat($data, $data, "config.xml");
322
				}
323
324 8ff5ffcc Matthew Grooms
				$size = strlen($data);
325
				header("Content-Type: application/octet-stream");
326
				header("Content-Disposition: attachment; filename={$name}");
327 a8c35980 Scott Ullrich
				header("Content-Length: $size");
328 e77ea573 jim-p
				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 8ff5ffcc Matthew Grooms
				echo $data;
336 73ed069b Renato Botelho
337 8ff5ffcc Matthew Grooms
				exit;
338
			}
339
		}
340 73ed069b Renato Botelho
341 8ff5ffcc Matthew Grooms
		if ($mode == "restore") {
342 73ed069b Renato Botelho
343 8ff5ffcc Matthew Grooms
			if ($_POST['decrypt']) {
344
				if(!$_POST['decrypt_password'] || !$_POST['decrypt_passconf'])
345 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("You must supply and confirm the password for decryption.");
346 8ff5ffcc Matthew Grooms
				if($_POST['decrypt_password'] != $_POST['decrypt_passconf'])
347 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The supplied 'Password' and 'Confirm' field values must match.");
348 8ff5ffcc Matthew Grooms
			}
349 73ed069b Renato Botelho
350 8ff5ffcc Matthew Grooms
			if (!$input_errors) {
351 73ed069b Renato Botelho
352 8ff5ffcc Matthew Grooms
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
353 73ed069b Renato Botelho
354 8ff5ffcc Matthew Grooms
					/* read the file contents */
355
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
356
					if(!$data) {
357 dae4c487 Carlos Eduardo Ramos
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
358 8ff5ffcc Matthew Grooms
						return 1;
359 9fd18b1f Scott Ullrich
					}
360 73ed069b Renato Botelho
361 8ff5ffcc Matthew Grooms
					if ($_POST['decrypt']) {
362
						if (!tagfile_deformat($data, $data, "config.xml")) {
363 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
364 8ff5ffcc Matthew Grooms
							return 1;
365
						}
366
						$data = decrypt_data($data, $_POST['decrypt_password']);
367
					}
368 73ed069b Renato Botelho
369 1d683793 sullrich
					if(stristr($data, "<m0n0wall>")) {
370 205da5a0 Neriberto C.Prado
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
371 8ff5ffcc Matthew Grooms
						/* 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 8dcca9b5 Darren Embry
						if(!stristr($data, "<" . $_POST['restorearea'] . ">")) {
378 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("You have selected to restore an area but we could not locate the correct xml tag.");
379 8ff5ffcc Matthew Grooms
						} else {
380 8dcca9b5 Darren Embry
							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 7eead1fc Darren Embry
							}
395 8ff5ffcc Matthew Grooms
						}
396 181462b5 Scott Ullrich
					} else {
397 6819b7f6 Renato Botelho
						if(!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
398 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']);
399 8ff5ffcc Matthew Grooms
						} 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 da17d77e Ermal Lu?i
								mark_subsystem_dirty("restore");
406 09821234 Scott Ullrich
								touch("/conf/needs_package_sync");
407 8ff5ffcc Matthew Grooms
								/* remove cache, we will force a config reboot */
408 da17d77e Ermal Lu?i
								if(file_exists("{$g['tmp_path']}/config.cache"))
409
									unlink("{$g['tmp_path']}/config.cache");
410 8ff5ffcc Matthew Grooms
								$config = parse_config(true);
411 67bc955d Chris Buechler
								/* extract out rrd items, unset from $config when done */
412 1390b049 Scott Ullrich
								if($config['rrddata']) {
413 754b75d0 Darren Embry
									restore_rrddata();
414 a2b8f7b2 Scott Ullrich
									unset($config['rrddata']);
415 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
416 a2b8f7b2 Scott Ullrich
									write_config();
417 3420028c Scott Ullrich
									add_base_packages_menu_items();
418 d442e4e2 Scott Ullrich
									convert_config();
419 a2b8f7b2 Scott Ullrich
									conf_mount_ro();
420 1390b049 Scott Ullrich
								}
421 8ff5ffcc Matthew Grooms
								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 b6db8ea3 sullrich
									/* 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 f1ac1733 Erik Fonnesbeck
												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 b6db8ea3 sullrich
												// NAT Rules
441 f1ac1733 Erik Fonnesbeck
												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 b6db8ea3 sullrich
												// Alias in an alias
445 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
446 b6db8ea3 sullrich
											}
447
										}
448
									}
449 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
450 888e7a27 Scott Ullrich
									// Reset configuration version to something low
451 a250f179 Renato Botelho
									// in order to force the config upgrade code to
452 888e7a27 Scott Ullrich
									// run through with all steps that are required.
453
									$config['system']['version'] = "1.0";
454 798cb31a Scott Ullrich
									// 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 c9a19238 Darren Embry
											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 798cb31a Scott Ullrich
											}
509
										}
510 dec5cb85 Scott Ullrich
									}
511
									$config['diag']['ipv6nat'] = true;
512 8ff5ffcc Matthew Grooms
									write_config();
513 a250f179 Renato Botelho
									add_base_packages_menu_items();
514 d442e4e2 Scott Ullrich
									convert_config();
515 8ff5ffcc Matthew Grooms
									conf_mount_ro();
516 205da5a0 Neriberto C.Prado
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
517 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
518 8ff5ffcc Matthew Grooms
								}
519 2e19a683 Renato Botelho
								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 8ff5ffcc Matthew Grooms
								}
528
								setup_serial_port();
529
								if(is_interface_mismatch() == true) {
530
									touch("/var/run/interface_mismatch_reboot_needed");
531 da17d77e Ermal Lu?i
									clear_subsystem_dirty("restore");
532 f5a57bb0 Scott Ullrich
									convert_config();
533 8ff5ffcc Matthew Grooms
									header("Location: interfaces_assign.php");
534 bafaf123 Scott Ullrich
									exit;
535 8ff5ffcc Matthew Grooms
								}
536 66bcba1b Ermal
								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 8ff5ffcc Matthew Grooms
							} else {
544 205da5a0 Neriberto C.Prado
								$input_errors[] = gettext("The configuration could not be restored.");
545 db3996df Scott Ullrich
							}
546 9c72b993 Scott Ullrich
						}
547 181462b5 Scott Ullrich
					}
548 8ff5ffcc Matthew Grooms
				} else {
549 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
550 db3996df Scott Ullrich
				}
551 5b237745 Scott Ullrich
			}
552 8ff5ffcc Matthew Grooms
		}
553 73ed069b Renato Botelho
554 8ff5ffcc Matthew Grooms
		if ($mode == "reinstallpackages") {
555 73ed069b Renato Botelho
556 8ccc8f1a Scott Ullrich
			header("Location: pkg_mgr_install.php?mode=reinstallall");
557
			exit;
558 039cb920 jim-p
		} else if ($mode == "clearpackagelock") {
559
			clear_subsystem_dirty('packagelock');
560
			$savemsg = "Package Lock Cleared";
561 73ed069b Renato Botelho
		} else if ($mode == "restore_ver") {
562 205da5a0 Neriberto C.Prado
			$input_errors[] = gettext("XXX - this feature may hose your config (do NOT backrev configs!) - billm");
563 7cf03119 Bill Marquette
			if ($ver2restore <> "") {
564
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
565 343bb325 sullrich
				if (config_install($conf_file) == 0) {
566 c9a19238 Darren Embry
					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 5b237745 Scott Ullrich
		}
574
	}
575
}
576 6a1e6651 Bill Marquette
577 02e1170d Scott Ullrich
$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 205da5a0 Neriberto C.Prado
$pgtitle = array(gettext("Diagnostics"),gettext("Backup/restore"));
583 b63695db Scott Ullrich
include("head.inc");
584
585 5b237745 Scott Ullrich
?>
586
587
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
588
<?php include("fbegin.inc"); ?>
589 8ff5ffcc Matthew Grooms
<script language="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 a1003d57 Ermal Lu?i
function backuparea_change(obj) {
609 7eead1fc Darren Embry
	if (obj.value == "rrddata") {
610 73ed069b Renato Botelho
		document.getElementById("nopackages").disabled      = true;
611
		document.getElementById("dotnotbackuprrd").disabled = true;
612 7eead1fc Darren Embry
	} else {
613 73ed069b Renato Botelho
		document.getElementById("nopackages").disabled      = false;
614
		document.getElementById("dotnotbackuprrd").disabled = false;
615 7eead1fc Darren Embry
	}
616 a1003d57 Ermal Lu?i
}
617 8ff5ffcc Matthew Grooms
//-->
618
</script>
619 344c68b2 sullrich
620 9e2a4fce Erik Kristensen
<?php if ($input_errors) print_input_errors($input_errors); ?>
621
<?php if ($savemsg) print_info_box($savemsg); ?>
622 da17d77e Ermal Lu?i
<?php if (is_subsystem_dirty('restore')): ?><p>
623 344c68b2 sullrich
<form action="reboot.php" method="post">
624
<input name="Submit" type="hidden" value=" Yes ">
625 8246efa6 Renato Botelho
<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br/>" . gettext("The firewall is now rebooting."));?><br>
626 344c68b2 sullrich
</form>
627 da17d77e Ermal Lu?i
<?php endif; ?>
628 344c68b2 sullrich
<form action="diag_backup.php" method="post" name="iform" enctype="multipart/form-data">
629 9e2a4fce Erik Kristensen
<table width="100%" border="0" cellspacing="0" cellpadding="0">
630
	<tr>
631
		<td>
632 12af52d9 Scott Ullrich
<?php
633 9e2a4fce Erik Kristensen
		$tab_array = array();
634 205da5a0 Neriberto C.Prado
		$tab_array[0] = array(gettext("Config History"), false, "diag_confbak.php");
635
		$tab_array[1] = array(gettext("Backup/Restore"), true, "diag_backup.php");
636 9e2a4fce Erik Kristensen
		display_top_tabs($tab_array);
637 645ec835 Scott Ullrich
?>
638 9e2a4fce Erik Kristensen
		</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 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Backup configuration"); ?></td>
646 9e2a4fce Erik Kristensen
				</tr>
647
				<tr>
648
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
649
					<td width="78%" class="vtable">
650 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>
651 8ff5ffcc Matthew Grooms
						<table>
652
							<tr>
653
								<td>
654
									<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">
655
								</td>
656
								<td>
657 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Do not backup package information."); ?></span>
658 8ff5ffcc Matthew Grooms
								</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 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Encrypt this configuration file."); ?></span>
668 8ff5ffcc Matthew Grooms
								</td>
669
							</tr>
670 1390b049 Scott Ullrich
							<tr>
671
								<td>
672 a2fb9e48 jim-p
									<input name="donotbackuprrd" type="checkbox" class="formcheckbox" id="dotnotbackuprrd" checked>
673 1390b049 Scott Ullrich
								</td>
674
								<td>
675 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>
676 1390b049 Scott Ullrich
								</td>
677
							</tr>
678 8ff5ffcc Matthew Grooms
						</table>
679
						<table id="encrypt_opts">
680
							<tr>
681
								<td>
682 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("Password:"); ?> </span>
683 8ff5ffcc Matthew Grooms
								</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 dae4c487 Carlos Eduardo Ramos
									<span class="vexpl"><?=gettext("confirm:"); ?> </span>
691 8ff5ffcc Matthew Grooms
								</td>
692
								<td>
693
									<input name="encrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
694
								</td>
695
							</tr>
696
						</table>
697 42aa088e Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="download" value="<?=gettext("Download configuration"); ?>"></p>
698 9e2a4fce Erik Kristensen
					</td>
699
				</tr>
700
				<tr>
701
					<td colspan="2" class="list" height="12">&nbsp;</td>
702 73ed069b Renato Botelho
				</tr>
703
				<tr>
704 591586e3 Neriberto C.Prado
					<td colspan="2" class="listtopic"><?=gettext("Restore configuration"); ?></td>
705 9e2a4fce Erik Kristensen
				</tr>
706
				<tr>
707
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
708
					<td width="78%" class="vtable">
709 c9a19238 Darren Embry
						<?=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 bda40985 Charlie Marshall
						<p><input name="conffile" type="file" class="formbtn" id="conffile" size="40"></p>
713 8ff5ffcc Matthew Grooms
						<table>
714
							<tr>
715
								<td>
716
									<input name="decrypt" type="checkbox" class="formcheckbox" id="nopackages" onClick="decrypt_change()">
717
								</td>
718
								<td>
719 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Configuration file is encrypted."); ?></span>
720 8ff5ffcc Matthew Grooms
								</td>
721
							</tr>
722
						</table>
723
						<table id="decrypt_opts">
724
							<tr>
725
								<td>
726 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("Password :"); ?></span>
727 8ff5ffcc Matthew Grooms
								</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 591586e3 Neriberto C.Prado
									<span class="vexpl"><?=gettext("confirm :"); ?></span>
735 8ff5ffcc Matthew Grooms
								</td>
736
								<td>
737
									<input name="decrypt_passconf" type="password" class="formfld pwd" size="20" value="" />
738
								</td>
739
							</tr>
740
						</table>
741 b639d5cd Carlos Eduardo Ramos
						<p><input name="Submit" type="submit" class="formbtn" id="restore" value="<?=gettext("Restore configuration"); ?>"></p>
742 c0948c6c Renato Botelho
						<p><strong><span class="red"><?=gettext("Note:"); ?></span></strong><br /><?=gettext("The firewall will reboot after restoring the configuration."); ?><br /></p>
743 9e2a4fce Erik Kristensen
					</td>
744
				</tr>
745 b3282172 Phil Davis
				<?php if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) { ?>
746 9e2a4fce Erik Kristensen
				<tr>
747
					<td colspan="2" class="list" height="12">&nbsp;</td>
748
				</tr>
749
				<tr>
750 039cb920 jim-p
					<td colspan="2" class="listtopic"><?=gettext("Package Functions"); ?></td>
751 9e2a4fce Erik Kristensen
				</tr>
752
				<tr>
753
					<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
754
					<td width="78%" class="vtable">
755 b3282172 Phil Davis
						<?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 9e2a4fce Erik Kristensen
					</td>
766
				</tr>
767
				<?php } ?>
768
			</table>
769
			</div>
770 b24bf37b Colin Smith
		</td>
771 9e2a4fce Erik Kristensen
	</tr>
772
</table>
773
</form>
774
775 8ff5ffcc Matthew Grooms
<script language="JavaScript">
776
<!--
777
encrypt_change();
778
decrypt_change();
779
//-->
780
</script>
781
782 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
783
</body>
784 38d48421 Colin Smith
</html>
785 7a7f3af1 sullrich
<?php
786
787
if (is_subsystem_dirty('restore'))
788 cf9a4467 jim-p
	system_reboot();
789 7a7f3af1 sullrich
790 a1003d57 Ermal Lu?i
?>