Project

General

Profile

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