Project

General

Profile

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