Project

General

Profile

Download (23.9 KB) Statistics
| Branch: | Tag: | Revision:
1 8ccc8f1a Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 aaec5634 Renato Botelho
 * diag_backup.php
4 9da2cf1c Stephen Beaver
 *
5 aaec5634 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * All rights reserved.
8 fd9ebcd5 Stephen Beaver
 *
9 aaec5634 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
10
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
11
 * All rights reserved.
12 fd9ebcd5 Stephen Beaver
 *
13 aaec5634 Renato Botelho
 * Redistribution and use in source and binary forms, with or without
14
 * modification, are permitted provided that the following conditions are met:
15 fd9ebcd5 Stephen Beaver
 *
16 aaec5634 Renato Botelho
 * 1. Redistributions of source code must retain the above copyright notice,
17
 *    this list of conditions and the following disclaimer.
18 fd9ebcd5 Stephen Beaver
 *
19 aaec5634 Renato Botelho
 * 2. Redistributions in binary form must reproduce the above copyright
20
 *    notice, this list of conditions and the following disclaimer in
21
 *    the documentation and/or other materials provided with the
22
 *    distribution.
23 fd9ebcd5 Stephen Beaver
 *
24 aaec5634 Renato Botelho
 * 3. All advertising materials mentioning features or use of this software
25
 *    must display the following acknowledgment:
26
 *    "This product includes software developed by the pfSense Project
27
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
28 fd9ebcd5 Stephen Beaver
 *
29 aaec5634 Renato Botelho
 * 4. The names "pfSense" and "pfSense Project" must not be used to
30
 *    endorse or promote products derived from this software without
31
 *    prior written permission. For written permission, please contact
32
 *    coreteam@pfsense.org.
33 fd9ebcd5 Stephen Beaver
 *
34 aaec5634 Renato Botelho
 * 5. Products derived from this software may not be called "pfSense"
35
 *    nor may "pfSense" appear in their names without prior written
36
 *    permission of the Electric Sheep Fencing, LLC.
37 fd9ebcd5 Stephen Beaver
 *
38 aaec5634 Renato Botelho
 * 6. Redistributions of any form whatsoever must retain the following
39
 *    acknowledgment:
40 0da0d43e Phil Davis
 *
41 aaec5634 Renato Botelho
 * "This product includes software developed by the pfSense Project
42
 * for use in the pfSense software distribution (http://www.pfsense.org/).
43 fd9ebcd5 Stephen Beaver
 *
44 aaec5634 Renato Botelho
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
45
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
47
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
48
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
49
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
51
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55
 * OF THE POSSIBILITY OF SUCH DAMAGE.
56 fd9ebcd5 Stephen Beaver
 */
57 5b237745 Scott Ullrich
58 6b07c15a Matthew Grooms
##|+PRIV
59 5d916fc7 Stephen Beaver
##|*IDENT=page-diagnostics-backup-restore
60 0f298138 k-paulius
##|*NAME=Diagnostics: Backup & Restore
61
##|*DESCR=Allow access to the 'Diagnostics: Backup & Restore' page.
62 6b07c15a Matthew Grooms
##|*MATCH=diag_backup.php*
63
##|-PRIV
64
65 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
66 3420028c Scott Ullrich
ini_set('max_execution_time', '0');
67
ini_set('max_input_time', '0');
68 47d11b79 Mark Crane
69 5b237745 Scott Ullrich
/* omit no-cache headers because it confuses IE with file downloads */
70
$omit_nocacheheaders = true;
71 aceaf18c Phil Davis
require_once("guiconfig.inc");
72 7a927e67 Scott Ullrich
require_once("functions.inc");
73
require_once("filter.inc");
74
require_once("shaper.inc");
75 5b237745 Scott Ullrich
76 8bdb6879 Darren Embry
$rrddbpath = "/var/db/rrd";
77
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
78
79
function rrd_data_xml() {
80
	global $rrddbpath;
81
	global $rrdtool;
82 73ed069b Renato Botelho
83 8bdb6879 Darren Embry
	$result = "\t<rrddata>\n";
84
	$rrd_files = glob("{$rrddbpath}/*.rrd");
85
	$xml_files = array();
86
	foreach ($rrd_files as $rrd_file) {
87
		$basename = basename($rrd_file);
88
		$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
89
		exec("$rrdtool dump '{$rrd_file}' '{$xml_file}'");
90
		$xml_data = file_get_contents($xml_file);
91
		unlink($xml_file);
92
		if ($xml_data !== false) {
93
			$result .= "\t\t<rrddatafile>\n";
94
			$result .= "\t\t\t<filename>{$basename}</filename>\n";
95
			$result .= "\t\t\t<xmldata>" . base64_encode(gzdeflate($xml_data)) . "</xmldata>\n";
96
			$result .= "\t\t</rrddatafile>\n";
97
		}
98
	}
99
	$result .= "\t</rrddata>\n";
100
	return $result;
101
}
102
103 754b75d0 Darren Embry
function restore_rrddata() {
104 7eead1fc Darren Embry
	global $config, $g, $rrdtool, $input_errors;
105 5f601060 Phil Davis
	foreach ($config['rrddata']['rrddatafile'] as $rrd) {
106 754b75d0 Darren Embry
		if ($rrd['xmldata']) {
107
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
108
			$xml_file = preg_replace('/\.rrd$/', ".xml", $rrd_file);
109 08877746 Darren Embry
			if (file_put_contents($xml_file, gzinflate(base64_decode($rrd['xmldata']))) === false) {
110 ff30e319 bruno
				log_error(sprintf(gettext("Cannot write %s"), $xml_file));
111 08877746 Darren Embry
				continue;
112
			}
113
			$output = array();
114
			$status = null;
115
			exec("$rrdtool restore -f '{$xml_file}' '{$rrd_file}'", $output, $status);
116
			if ($status) {
117 f757431d Darren Embry
				log_error("rrdtool restore -f '{$xml_file}' '{$rrd_file}' failed returning {$status}.");
118 08877746 Darren Embry
				continue;
119
			}
120 754b75d0 Darren Embry
			unlink($xml_file);
121 5f601060 Phil Davis
		} else if ($rrd['data']) {
122 7eead1fc Darren Embry
			$rrd_file = "{$g['vardb_path']}/rrd/{$rrd['filename']}";
123
			$rrd_fd = fopen($rrd_file, "w");
124 08877746 Darren Embry
			if (!$rrd_fd) {
125 ff30e319 bruno
				log_error(sprintf(gettext("Cannot write %s"), $rrd_file));
126 08877746 Darren Embry
				continue;
127
			}
128 754b75d0 Darren Embry
			$data = base64_decode($rrd['data']);
129
			/* Try to decompress the data. */
130
			$dcomp = @gzinflate($data);
131
			if ($dcomp) {
132
				/* If the decompression worked, write the decompressed data */
133 08877746 Darren Embry
				if (fwrite($rrd_fd, $dcomp) === false) {
134 ff30e319 bruno
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
135 08877746 Darren Embry
					continue;
136
				}
137 754b75d0 Darren Embry
			} else {
138
				/* If the decompression failed, it wasn't compressed, so write raw data */
139 08877746 Darren Embry
				if (fwrite($rrd_fd, $data) === false) {
140 ff30e319 bruno
					log_error(sprintf(gettext("fwrite %s failed"), $rrd_file));
141 08877746 Darren Embry
					continue;
142
				}
143
			}
144
			if (fclose($rrd_fd) === false) {
145 ff30e319 bruno
				log_error(sprintf(gettext("fclose %s failed"), $rrd_file));
146 08877746 Darren Embry
				continue;
147 754b75d0 Darren Embry
			}
148
		}
149
	}
150
}
151
152 645ec835 Scott Ullrich
function remove_bad_chars($string) {
153 699737d9 Phil Davis
	return preg_replace('/[^a-z_0-9]/i', '', $string);
154 645ec835 Scott Ullrich
}
155
156 b3277798 Scott Ullrich
function check_and_returnif_section_exists($section) {
157
	global $config;
158 5f601060 Phil Davis
	if (is_array($config[$section])) {
159 b3277798 Scott Ullrich
		return true;
160 5f601060 Phil Davis
	}
161 b3277798 Scott Ullrich
	return false;
162
}
163
164 da17d77e Ermal Lu?i
if ($_POST['apply']) {
165 73ed069b Renato Botelho
	ob_flush();
166
	flush();
167 c9a19238 Darren Embry
	conf_mount_rw();
168
	clear_subsystem_dirty("restore");
169
	conf_mount_ro();
170 73ed069b Renato Botelho
	exit;
171 da17d77e Ermal Lu?i
}
172
173 5b237745 Scott Ullrich
if ($_POST) {
174
	unset($input_errors);
175 0f742e51 Phil Davis
	if ($_POST['restore']) {
176 5b237745 Scott Ullrich
		$mode = "restore";
177 0f742e51 Phil Davis
	} else if ($_POST['reinstallpackages']) {
178 8ccc8f1a Scott Ullrich
		$mode = "reinstallpackages";
179 0f742e51 Phil Davis
	} else if ($_POST['clearpackagelock']) {
180 039cb920 jim-p
		$mode = "clearpackagelock";
181 0f742e51 Phil Davis
	} else if ($_POST['download']) {
182 5b237745 Scott Ullrich
		$mode = "download";
183 5f601060 Phil Davis
	} else if (stristr($_POST['Submit'], gettext("Restore version"))) {
184 7cf03119 Bill Marquette
		$mode = "restore_ver";
185 5f601060 Phil Davis
	}
186
	if ($_POST["nopackages"] <> "") {
187 528cad39 Colin Smith
		$options = "nopackages";
188 5f601060 Phil Davis
	}
189
	if ($_POST["ver"] <> "") {
190 7cf03119 Bill Marquette
		$ver2restore = $_POST["ver"];
191 5f601060 Phil Davis
	}
192 5b237745 Scott Ullrich
	if ($mode) {
193
		if ($mode == "download") {
194 8ff5ffcc Matthew Grooms
			if ($_POST['encrypt']) {
195 76d6d925 Stephen Beaver
				if (!$_POST['encrypt_password']) {
196 9b6ea44e Stephen Beaver
					$input_errors[] = gettext("A password for encryption must be supplied and confirmed.");
197 5f601060 Phil Davis
				}
198 528cad39 Colin Smith
			}
199 73ed069b Renato Botelho
200 8ff5ffcc Matthew Grooms
			if (!$input_errors) {
201 73ed069b Renato Botelho
202 07b1797b sullrich
				//$lockbckp = lock('config');
203 73ed069b Renato Botelho
204 8ff5ffcc Matthew Grooms
				$host = "{$config['system']['hostname']}.{$config['system']['domain']}";
205
				$name = "config-{$host}-".date("YmdHis").".xml";
206
				$data = "";
207 73ed069b Renato Botelho
208 5f601060 Phil Davis
				if ($options == "nopackages") {
209
					if (!$_POST['backuparea']) {
210 4195c967 sullrich
						/* backup entire configuration */
211
						$data = file_get_contents("{$g['conf_path']}/config.xml");
212
					} else {
213
						/* backup specific area of configuration */
214
						$data = backup_config_section($_POST['backuparea']);
215
						$name = "{$_POST['backuparea']}-{$name}";
216
					}
217 da17d77e Ermal Lu?i
					$sfn = "{$g['tmp_path']}/config.xml.nopkg";
218 4195c967 sullrich
					file_put_contents($sfn, $data);
219
					exec("sed '/<installedpackages>/,/<\/installedpackages>/d' {$sfn} > {$sfn}-new");
220 a250f179 Renato Botelho
					$data = file_get_contents($sfn . "-new");
221 8ff5ffcc Matthew Grooms
				} else {
222 5f601060 Phil Davis
					if (!$_POST['backuparea']) {
223 8ff5ffcc Matthew Grooms
						/* backup entire configuration */
224
						$data = file_get_contents("{$g['conf_path']}/config.xml");
225 7eead1fc Darren Embry
					} else if ($_POST['backuparea'] === "rrddata") {
226
						$data = rrd_data_xml();
227
						$name = "{$_POST['backuparea']}-{$name}";
228 8ff5ffcc Matthew Grooms
					} else {
229
						/* backup specific area of configuration */
230
						$data = backup_config_section($_POST['backuparea']);
231
						$name = "{$_POST['backuparea']}-{$name}";
232
					}
233 181462b5 Scott Ullrich
				}
234 73ed069b Renato Botelho
235 07b1797b sullrich
				//unlock($lockbckp);
236 73ed069b Renato Botelho
237 a250f179 Renato Botelho
				/*
238 0e834fc5 Stephen Beaver
				 *	Backup RRD Data
239 1390b049 Scott Ullrich
				 */
240 7eead1fc Darren Embry
				if ($_POST['backuparea'] !== "rrddata" && !$_POST['donotbackuprrd']) {
241 8bdb6879 Darren Embry
					$rrd_data_xml = rrd_data_xml();
242
					$closing_tag = "</" . $g['xml_rootobj'] . ">";
243
					$data = str_replace($closing_tag, $rrd_data_xml . $closing_tag, $data);
244 1390b049 Scott Ullrich
				}
245 73ed069b Renato Botelho
246 4cfd2390 Renato Botelho
				if ($_POST['encrypt']) {
247
					$data = encrypt_data($data, $_POST['encrypt_password']);
248
					tagfile_reformat($data, $data, "config.xml");
249
				}
250
251 8ff5ffcc Matthew Grooms
				$size = strlen($data);
252
				header("Content-Type: application/octet-stream");
253
				header("Content-Disposition: attachment; filename={$name}");
254 a8c35980 Scott Ullrich
				header("Content-Length: $size");
255 e77ea573 jim-p
				if (isset($_SERVER['HTTPS'])) {
256
					header('Pragma: ');
257
					header('Cache-Control: ');
258
				} else {
259
					header("Pragma: private");
260
					header("Cache-Control: private, must-revalidate");
261
				}
262 8ff5ffcc Matthew Grooms
				echo $data;
263 73ed069b Renato Botelho
264 8ff5ffcc Matthew Grooms
				exit;
265
			}
266
		}
267 73ed069b Renato Botelho
268 8ff5ffcc Matthew Grooms
		if ($mode == "restore") {
269
			if ($_POST['decrypt']) {
270 76d6d925 Stephen Beaver
				if (!$_POST['decrypt_password']) {
271 9b6ea44e Stephen Beaver
					$input_errors[] = gettext("A password for decryption must be supplied and confirmed.");
272 5f601060 Phil Davis
				}
273 8ff5ffcc Matthew Grooms
			}
274 73ed069b Renato Botelho
275 8ff5ffcc Matthew Grooms
			if (!$input_errors) {
276
				if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
277 73ed069b Renato Botelho
278 8ff5ffcc Matthew Grooms
					/* read the file contents */
279
					$data = file_get_contents($_FILES['conffile']['tmp_name']);
280 5f601060 Phil Davis
					if (!$data) {
281 dae4c487 Carlos Eduardo Ramos
						log_error(sprintf(gettext("Warning, could not read file %s"), $_FILES['conffile']['tmp_name']));
282 8ff5ffcc Matthew Grooms
						return 1;
283 9fd18b1f Scott Ullrich
					}
284 73ed069b Renato Botelho
285 8ff5ffcc Matthew Grooms
					if ($_POST['decrypt']) {
286
						if (!tagfile_deformat($data, $data, "config.xml")) {
287 205da5a0 Neriberto C.Prado
							$input_errors[] = gettext("The uploaded file does not appear to contain an encrypted pfsense configuration.");
288 8ff5ffcc Matthew Grooms
							return 1;
289
						}
290
						$data = decrypt_data($data, $_POST['decrypt_password']);
291
					}
292 73ed069b Renato Botelho
293 5f601060 Phil Davis
					if (stristr($data, "<m0n0wall>")) {
294 205da5a0 Neriberto C.Prado
						log_error(gettext("Upgrading m0n0wall configuration to pfsense."));
295 8ff5ffcc Matthew Grooms
						/* m0n0wall was found in config.  convert it. */
296
						$data = str_replace("m0n0wall", "pfsense", $data);
297
						$m0n0wall_upgrade = true;
298
					}
299 5f601060 Phil Davis
					if ($_POST['restorearea']) {
300 8ff5ffcc Matthew Grooms
						/* restore a specific area of the configuration */
301 5f601060 Phil Davis
						if (!stristr($data, "<" . $_POST['restorearea'] . ">")) {
302 ce871619 Stephen Beaver
							$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
303 8ff5ffcc Matthew Grooms
						} else {
304 8dcca9b5 Darren Embry
							if (!restore_config_section($_POST['restorearea'], $data)) {
305 ce871619 Stephen Beaver
								$input_errors[] = gettext("An area to restore was selected but the correct xml tag could not be located.");
306 8dcca9b5 Darren Embry
							} else {
307
								if ($config['rrddata']) {
308
									restore_rrddata();
309
									unset($config['rrddata']);
310
									unlink_if_exists("{$g['tmp_path']}/config.cache");
311 2ff475b7 doktornotor
									write_config(sprintf(gettext("Unset RRD data from configuration after restoring %s configuration area"), $_POST['restorearea']));
312 8dcca9b5 Darren Embry
									convert_config();
313
									conf_mount_ro();
314
								}
315
								filter_configure();
316 ce871619 Stephen Beaver
								$savemsg = gettext("The configuration area has been restored. The firewall may need to be rebooted.");
317 7eead1fc Darren Embry
							}
318 8ff5ffcc Matthew Grooms
						}
319 181462b5 Scott Ullrich
					} else {
320 5f601060 Phil Davis
						if (!stristr($data, "<" . $g['xml_rootobj'] . ">")) {
321 ce871619 Stephen Beaver
							$input_errors[] = sprintf(gettext("A full configuration restore was selected but a %s tag could not be located."), $g['xml_rootobj']);
322 8ff5ffcc Matthew Grooms
						} else {
323
							/* restore the entire configuration */
324
							file_put_contents($_FILES['conffile']['tmp_name'], $data);
325
							if (config_install($_FILES['conffile']['tmp_name']) == 0) {
326
								/* this will be picked up by /index.php */
327
								conf_mount_rw();
328 da17d77e Ermal Lu?i
								mark_subsystem_dirty("restore");
329 e6068346 Phil Davis
								touch("/conf/needs_package_sync_after_reboot");
330 8ff5ffcc Matthew Grooms
								/* remove cache, we will force a config reboot */
331 5f601060 Phil Davis
								if (file_exists("{$g['tmp_path']}/config.cache")) {
332 da17d77e Ermal Lu?i
									unlink("{$g['tmp_path']}/config.cache");
333 5f601060 Phil Davis
								}
334 8ff5ffcc Matthew Grooms
								$config = parse_config(true);
335 0174c480 Ermal LUÇI
								if (file_exists("/boot/loader.conf")) {
336
									$loaderconf = file_get_contents("/boot/loader.conf");
337 08af94cb Chris Buechler
									if (strpos($loaderconf, "console=\"comconsole")) {
338 0174c480 Ermal LUÇI
										$config['system']['enableserial'] = true;
339 ff30e319 bruno
										write_config(gettext("Restore serial console enabling in configuration."));
340 0174c480 Ermal LUÇI
									}
341 5d4b8830 Ermal LUÇI
									unset($loaderconf);
342 0174c480 Ermal LUÇI
								}
343 67bc955d Chris Buechler
								/* extract out rrd items, unset from $config when done */
344 5f601060 Phil Davis
								if ($config['rrddata']) {
345 754b75d0 Darren Embry
									restore_rrddata();
346 a2b8f7b2 Scott Ullrich
									unset($config['rrddata']);
347 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
348 2ff475b7 doktornotor
									write_config(gettext("Unset RRD data from configuration after restoring full configuration"));
349 d442e4e2 Scott Ullrich
									convert_config();
350 a2b8f7b2 Scott Ullrich
									conf_mount_ro();
351 1390b049 Scott Ullrich
								}
352 5f601060 Phil Davis
								if ($m0n0wall_upgrade == true) {
353
									if ($config['system']['gateway'] <> "") {
354 8ff5ffcc Matthew Grooms
										$config['interfaces']['wan']['gateway'] = $config['system']['gateway'];
355 5f601060 Phil Davis
									}
356 8ff5ffcc Matthew Grooms
									unset($config['shaper']);
357
									/* optional if list */
358
									$ifdescrs = get_configured_interface_list(true, true);
359
									/* remove special characters from interface descriptions */
360 5f601060 Phil Davis
									if (is_array($ifdescrs)) {
361
										foreach ($ifdescrs as $iface) {
362 8ff5ffcc Matthew Grooms
											$config['interfaces'][$iface]['descr'] = remove_bad_chars($config['interfaces'][$iface]['descr']);
363 5f601060 Phil Davis
										}
364
									}
365 b6db8ea3 sullrich
									/* check for interface names with an alias */
366 5f601060 Phil Davis
									if (is_array($ifdescrs)) {
367
										foreach ($ifdescrs as $iface) {
368
											if (is_alias($config['interfaces'][$iface]['descr'])) {
369 b6db8ea3 sullrich
												// Firewall rules
370
												$origname = $config['interfaces'][$iface]['descr'];
371 6c07db48 Phil Davis
												$newname = $config['interfaces'][$iface]['descr'] . "Alias";
372 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('filter', 'rule'), array('source', 'address'), $newname, $origname);
373
												update_alias_names_upon_change(array('filter', 'rule'), array('destination', 'address'), $newname, $origname);
374 b6db8ea3 sullrich
												// NAT Rules
375 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('nat', 'rule'), array('source', 'address'), $newname, $origname);
376
												update_alias_names_upon_change(array('nat', 'rule'), array('destination', 'address'), $newname, $origname);
377
												update_alias_names_upon_change(array('nat', 'rule'), array('target'), $newname, $origname);
378 b6db8ea3 sullrich
												// Alias in an alias
379 f1ac1733 Erik Fonnesbeck
												update_alias_names_upon_change(array('aliases', 'alias'), array('address'), $newname, $origname);
380 b6db8ea3 sullrich
											}
381
										}
382
									}
383 da17d77e Ermal Lu?i
									unlink_if_exists("{$g['tmp_path']}/config.cache");
384 888e7a27 Scott Ullrich
									// Reset configuration version to something low
385 a250f179 Renato Botelho
									// in order to force the config upgrade code to
386 888e7a27 Scott Ullrich
									// run through with all steps that are required.
387
									$config['system']['version'] = "1.0";
388 798cb31a Scott Ullrich
									// Deal with descriptions longer than 63 characters
389
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
390 5f601060 Phil Davis
										if (count($config['filter']['rule'][$i]['descr']) > 63) {
391 798cb31a Scott Ullrich
											$config['filter']['rule'][$i]['descr'] = substr($config['filter']['rule'][$i]['descr'], 0, 63);
392 5f601060 Phil Davis
										}
393 798cb31a Scott Ullrich
									}
394
									// Move interface from ipsec to enc0
395
									for ($i = 0; isset($config["filter"]["rule"][$i]); $i++) {
396 5f601060 Phil Davis
										if ($config['filter']['rule'][$i]['interface'] == "ipsec") {
397 798cb31a Scott Ullrich
											$config['filter']['rule'][$i]['interface'] = "enc0";
398 5f601060 Phil Davis
										}
399 798cb31a Scott Ullrich
									}
400
									// Convert icmp types
401
									// http://www.openbsd.org/cgi-bin/man.cgi?query=icmp&sektion=4&arch=i386&apropos=0&manpath=OpenBSD+Current
402 6779b24d stilez
									$convert = array('echo' => 'echoreq', 'timest' => 'timereq', 'timestrep' => 'timerep');
403
									foreach ($config["filter"]["rule"] as $ruleid => &$ruledata) {
404
										if ($convert[$ruledata['icmptype']]) {
405
											$ruledata['icmptype'] = $convert[$ruledata['icmptype']];
406 798cb31a Scott Ullrich
										}
407 dec5cb85 Scott Ullrich
									}
408
									$config['diag']['ipv6nat'] = true;
409 2ff475b7 doktornotor
									write_config(gettext("Imported m0n0wall configuration"));
410 d442e4e2 Scott Ullrich
									convert_config();
411 8ff5ffcc Matthew Grooms
									conf_mount_ro();
412 205da5a0 Neriberto C.Prado
									$savemsg = gettext("The m0n0wall configuration has been restored and upgraded to pfSense.");
413 da17d77e Ermal Lu?i
									mark_subsystem_dirty("restore");
414 8ff5ffcc Matthew Grooms
								}
415 5f601060 Phil Davis
								if (is_array($config['captiveportal'])) {
416
									foreach ($config['captiveportal'] as $cp) {
417 2e19a683 Renato Botelho
										if (isset($cp['enable'])) {
418
											/* for some reason ipfw doesn't init correctly except on bootup sequence */
419
											mark_subsystem_dirty("restore");
420
											break;
421
										}
422
									}
423 8ff5ffcc Matthew Grooms
								}
424
								setup_serial_port();
425 5f601060 Phil Davis
								if (is_interface_mismatch() == true) {
426 8ff5ffcc Matthew Grooms
									touch("/var/run/interface_mismatch_reboot_needed");
427 da17d77e Ermal Lu?i
									clear_subsystem_dirty("restore");
428 f5a57bb0 Scott Ullrich
									convert_config();
429 8ff5ffcc Matthew Grooms
									header("Location: interfaces_assign.php");
430 bafaf123 Scott Ullrich
									exit;
431 8ff5ffcc Matthew Grooms
								}
432 66bcba1b Ermal
								if (is_interface_vlan_mismatch() == true) {
433
									touch("/var/run/interface_mismatch_reboot_needed");
434
									clear_subsystem_dirty("restore");
435
									convert_config();
436
									header("Location: interfaces_assign.php");
437
									exit;
438
								}
439 8ff5ffcc Matthew Grooms
							} else {
440 205da5a0 Neriberto C.Prado
								$input_errors[] = gettext("The configuration could not be restored.");
441 db3996df Scott Ullrich
							}
442 9c72b993 Scott Ullrich
						}
443 181462b5 Scott Ullrich
					}
444 8ff5ffcc Matthew Grooms
				} else {
445 205da5a0 Neriberto C.Prado
					$input_errors[] = gettext("The configuration could not be restored (file upload error).");
446 db3996df Scott Ullrich
				}
447 5b237745 Scott Ullrich
			}
448 8ff5ffcc Matthew Grooms
		}
449 73ed069b Renato Botelho
450 8ff5ffcc Matthew Grooms
		if ($mode == "reinstallpackages") {
451 8ccc8f1a Scott Ullrich
			header("Location: pkg_mgr_install.php?mode=reinstallall");
452
			exit;
453 039cb920 jim-p
		} else if ($mode == "clearpackagelock") {
454
			clear_subsystem_dirty('packagelock');
455 8545adde k-paulius
			$savemsg = "Package lock cleared.";
456 73ed069b Renato Botelho
		} else if ($mode == "restore_ver") {
457 ce871619 Stephen Beaver
			$input_errors[] = gettext("XXX - this feature may hose the config (do NOT backrev configs!) - billm");
458 7cf03119 Bill Marquette
			if ($ver2restore <> "") {
459
				$conf_file = "{$g['cf_conf_path']}/bak/config-" . strtotime($ver2restore) . ".xml";
460 343bb325 sullrich
				if (config_install($conf_file) == 0) {
461 c9a19238 Darren Embry
					mark_subsystem_dirty("restore");
462
				} else {
463
					$input_errors[] = gettext("The configuration could not be restored.");
464
				}
465
			} else {
466
				$input_errors[] = gettext("No version selected.");
467
			}
468 5b237745 Scott Ullrich
		}
469
	}
470
}
471 6a1e6651 Bill Marquette
472 02e1170d Scott Ullrich
$id = rand() . '.' . time();
473
474
$mth = ini_get('upload_progress_meter.store_method');
475
$dir = ini_get('upload_progress_meter.file.filename_template');
476
477 a4af095c Renato Botelho
function build_area_list($showall) {
478
	global $config;
479 b63695db Scott Ullrich
480 0e834fc5 Stephen Beaver
	$areas = array(
481
		"aliases" => gettext("Aliases"),
482 a4af095c Renato Botelho
		"captiveportal" => gettext("Captive Portal"),
483
		"voucher" => gettext("Captive Portal Vouchers"),
484
		"dnsmasq" => gettext("DNS Forwarder"),
485
		"unbound" => gettext("DNS Resolver"),
486
		"dhcpd" => gettext("DHCP Server"),
487
		"dhcpdv6" => gettext("DHCPv6 Server"),
488
		"filter" => gettext("Firewall Rules"),
489
		"interfaces" => gettext("Interfaces"),
490
		"ipsec" => gettext("IPSEC"),
491
		"nat" => gettext("NAT"),
492
		"openvpn" => gettext("OpenVPN"),
493
		"installedpackages" => gettext("Package Manager"),
494
		"rrddata" => gettext("RRD Data"),
495
		"cron" => gettext("Scheduled Tasks"),
496
		"syslog" => gettext("Syslog"),
497
		"system" => gettext("System"),
498
		"staticroutes" => gettext("Static routes"),
499
		"sysctl" => gettext("System tunables"),
500
		"snmpd" => gettext("SNMP Server"),
501
		"shaper" => gettext("Traffic Shaper"),
502
		"vlans" => gettext("VLANS"),
503 7ca42d47 k-paulius
		"wol" => gettext("Wake-on-LAN")
504 a4af095c Renato Botelho
		);
505 0e834fc5 Stephen Beaver
506
	$list = array("" => gettext("All"));
507
508 288a2a0f Phil Davis
	if ($showall) {
509 0e834fc5 Stephen Beaver
		return($list + $areas);
510 288a2a0f Phil Davis
	} else {
511 a4af095c Renato Botelho
		foreach ($areas as $area => $areaname) {
512
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
513
				$list[$area] = $areaname;
514
			}
515
		}
516 8ff5ffcc Matthew Grooms
517 0e834fc5 Stephen Beaver
		return($list);
518 5f601060 Phil Davis
	}
519 8ff5ffcc Matthew Grooms
}
520
521 0f298138 k-paulius
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
522 de02dc29 Phil Davis
$pglinks = array("", "@self", "@self");
523 b63695db Scott Ullrich
include("head.inc");
524
525 947141fd Phil Davis
if ($input_errors) {
526 a4af095c Renato Botelho
	print_input_errors($input_errors);
527 947141fd Phil Davis
}
528 0e834fc5 Stephen Beaver
529 947141fd Phil Davis
if ($savemsg) {
530 a4af095c Renato Botelho
	print_info_box($savemsg, 'success');
531 947141fd Phil Davis
}
532 0e834fc5 Stephen Beaver
533 a4af095c Renato Botelho
if (is_subsystem_dirty('restore')):
534 5b237745 Scott Ullrich
?>
535 a4af095c Renato Botelho
	<br/>
536 1af5edbf Stephen Beaver
	<form action="diag_reboot.php" method="post">
537 7d5b007c Sjon Hortensius
		<input name="Submit" type="hidden" value="Yes" />
538 f6aebbcc NewEraCracker
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
539 a4af095c Renato Botelho
		<br />
540 7d5b007c Sjon Hortensius
	</form>
541 0e834fc5 Stephen Beaver
<?php
542 a4af095c Renato Botelho
endif;
543
544
$tab_array = array();
545 0f298138 k-paulius
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
546 a4af095c Renato Botelho
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
547
display_top_tabs($tab_array);
548
549
$form = new Form(false);
550 3beeb66a Stephen Beaver
$form->setMultipartEncoding();	// Allow file uploads
551 a4af095c Renato Botelho
552 5f88f964 k-paulius
$section = new Form_Section('Backup Configuration');
553 a4af095c Renato Botelho
554
$section->addInput(new Form_Select(
555
	'backuparea',
556
	'Backup area',
557
	'',
558
	build_area_list(false)
559
));
560
561
$section->addInput(new Form_Checkbox(
562
	'nopackages',
563
	'Skip packages',
564
	'Do not backup package information.',
565
	false
566
));
567
568
$section->addInput(new Form_Checkbox(
569
	'donotbackuprrd',
570
	'Skip RRD data',
571
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
572
	true
573
));
574
575
$section->addInput(new Form_Checkbox(
576
	'encrypt',
577
	'Encryption',
578
	'Encrypt this configuration file.',
579
	false
580 7c0f116b Jared Dillard
));
581 a4af095c Renato Botelho
582 76d6d925 Stephen Beaver
$section->addInput(new Form_Input(
583 a4af095c Renato Botelho
	'encrypt_password',
584 c8b10b4c Stephen Beaver
	'Password',
585 a4af095c Renato Botelho
	'password',
586 c8b10b4c Stephen Beaver
	null
587 7c0f116b Jared Dillard
));
588 a4af095c Renato Botelho
589
$group = new Form_Group('');
590 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
591 a4af095c Renato Botelho
$group->add(new Form_Button(
592 0f742e51 Phil Davis
	'download',
593 faab522f Renato Botelho
	'Download configuration as XML',
594 37676f4e jim-p
	null,
595
	'fa-download'
596
))->setAttribute('id')->addClass('btn-primary');
597 a4af095c Renato Botelho
598
$section->add($group);
599
$form->add($section);
600
601 5f88f964 k-paulius
$section = new Form_Section('Restore Backup');
602 a4af095c Renato Botelho
603
$section->addInput(new Form_StaticText(
604
	null,
605 52e416cc Phil Davis
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_name'])
606 a4af095c Renato Botelho
));
607
608
$section->addInput(new Form_Select(
609
	'restorearea',
610
	'Restore area',
611
	'',
612 de407762 Phil Davis
	build_area_list(true)
613 a4af095c Renato Botelho
));
614
615
$section->addInput(new Form_Input(
616
	'conffile',
617
	'Configuration file',
618
	'file',
619
	null
620
));
621
622
$section->addInput(new Form_Checkbox(
623 7c0f116b Jared Dillard
	'decrypt',
624 a4af095c Renato Botelho
	'Encryption',
625 7c0f116b Jared Dillard
	'Configuration file is encrypted.',
626 a4af095c Renato Botelho
	false
627 7c0f116b Jared Dillard
));
628 a4af095c Renato Botelho
629 76d6d925 Stephen Beaver
$section->addInput(new Form_Input(
630 a4af095c Renato Botelho
	'decrypt_password',
631 c8b10b4c Stephen Beaver
	'Password',
632 a4af095c Renato Botelho
	'password',
633
	null,
634
	['placeholder' => 'Password']
635 7c0f116b Jared Dillard
));
636 a4af095c Renato Botelho
637
$group = new Form_Group('');
638 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
639 a4af095c Renato Botelho
$group->add(new Form_Button(
640 0f742e51 Phil Davis
	'restore',
641 faab522f Renato Botelho
	'Restore Configuration',
642 37676f4e jim-p
	null,
643
	'fa-undo'
644
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
645 a4af095c Renato Botelho
646
$section->add($group);
647
648
$form->add($section);
649
650
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
651 5f88f964 k-paulius
	$section = new Form_Section('Package Functions');
652 0e834fc5 Stephen Beaver
653 a4af095c Renato Botelho
	if ($config['installedpackages']['package'] != "") {
654
		$group = new Form_Group('');
655 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
656 a4af095c Renato Botelho
		$group->add(new Form_Button(
657 0f742e51 Phil Davis
			'reinstallpackages',
658 faab522f Renato Botelho
			'Reinstall Packages',
659 37676f4e jim-p
			null,
660
			'fa-retweet'
661
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
662 0e834fc5 Stephen Beaver
663 a4af095c Renato Botelho
		$section->add($group);
664 7eead1fc Darren Embry
	}
665 0e834fc5 Stephen Beaver
666 a4af095c Renato Botelho
	if (is_subsystem_dirty("packagelock")) {
667
		$group = new Form_Group('');
668 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
669 a4af095c Renato Botelho
		$group->add(new Form_Button(
670 0f742e51 Phil Davis
			'clearpackagelock',
671 faab522f Renato Botelho
			'Clear Package Lock',
672 37676f4e jim-p
			null,
673
			'fa-wrench'
674
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
675 0e834fc5 Stephen Beaver
676 a4af095c Renato Botelho
		$section->add($group);
677
	}
678 0e834fc5 Stephen Beaver
679 a4af095c Renato Botelho
	$form->add($section);
680 a1003d57 Ermal Lu?i
}
681 a4af095c Renato Botelho
682
print($form);
683 7c0f116b Jared Dillard
?>
684
<script type="text/javascript">
685
//<![CDATA[
686 947141fd Phil Davis
events.push(function() {
687 7c0f116b Jared Dillard
688
	// ------- Show/hide sections based on checkbox settings --------------------------------------
689 0da0d43e Phil Davis
690 7c0f116b Jared Dillard
	function hideSections(hide) {
691
		hidePasswords();
692
	}
693
694
	function hidePasswords() {
695 3beeb66a Stephen Beaver
696 7c0f116b Jared Dillard
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
697
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
698
699
		hideInput('encrypt_password', encryptHide);
700 c8b10b4c Stephen Beaver
		hideInput('encrypt_password_confirm', encryptHide);
701 7c0f116b Jared Dillard
		hideInput('decrypt_password', decryptHide);
702 c8b10b4c Stephen Beaver
		hideInput('decrypt_password_confirm', decryptHide);
703 7c0f116b Jared Dillard
	}
704
705 ff59b884 Stephen Beaver
	// ---------- Click handlers ------------------------------------------------------------------
706 7c0f116b Jared Dillard
707
	$('input[name="encrypt"]').on('change', function() {
708
		hidePasswords();
709
	});
710
711
	$('input[name="decrypt"]').on('change', function() {
712
		hidePasswords();
713 3beeb66a Stephen Beaver
	});
714 7c0f116b Jared Dillard
715 947141fd Phil Davis
	$('#conffile').change(function () {
716 40f146c5 Phil Davis
		if (document.getElementById("conffile").value) {
717
			$('.restore').prop('disabled', false);
718
		} else {
719
			$('.restore').prop('disabled', true);
720
		}
721 ff59b884 Stephen Beaver
    });
722 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
723
724 7c0f116b Jared Dillard
	hideSections();
725 ff59b884 Stephen Beaver
	$('.restore').prop('disabled', true);
726 7c0f116b Jared Dillard
});
727
//]]>
728
</script>
729
730
<?php
731 a4af095c Renato Botelho
include("foot.inc");
732 7a7f3af1 sullrich
733 5f601060 Phil Davis
if (is_subsystem_dirty('restore')) {
734 cf9a4467 jim-p
	system_reboot();
735 c9d46a8e Renato Botelho
}