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