Project

General

Profile

Download (6.77 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 8ccc8f1a Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4
	diag_backup.php
5 07bd3f83 Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
6 8ccc8f1a Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 8ccc8f1a Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 8ccc8f1a Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 8ccc8f1a Scott Ullrich
16 5b237745 Scott Ullrich
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 8ccc8f1a Scott Ullrich
20 5b237745 Scott Ullrich
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30
*/
31
32
/* omit no-cache headers because it confuses IE with file downloads */
33
$omit_nocacheheaders = true;
34 8ccc8f1a Scott Ullrich
require("guiconfig.inc");
35 5b237745 Scott Ullrich
36
if ($_POST) {
37
	unset($input_errors);
38
	if (stristr($_POST['Submit'], "Restore"))
39
		$mode = "restore";
40 8ccc8f1a Scott Ullrich
	else if (stristr($_POST['Submit'], "Reinstall"))
41
		$mode = "reinstallpackages";
42 5b237745 Scott Ullrich
	else if (stristr($_POST['Submit'], "Download"))
43
		$mode = "download";
44 aab57926 Scott Ullrich
	if ($_POST["nopackages"] <> "")
45 528cad39 Colin Smith
		$options = "nopackages";
46 8ccc8f1a Scott Ullrich
47 5b237745 Scott Ullrich
	if ($mode) {
48
		if ($mode == "download") {
49
			config_lock();
50 8ccc8f1a Scott Ullrich
			$fn = "config-" . $config['system']['hostname'] . "." .
51 5b237745 Scott Ullrich
				$config['system']['domain'] . "-" . date("YmdHis") . ".xml";
52 528cad39 Colin Smith
			if($options == "nopackages") {
53
				exec("sed '/<installedpackages>/,/<\/installedpackages>/d' /conf/config.xml > /tmp/config.xml.nopkg");
54
				$fs = filesize("/tmp/config.xml.nopkg");
55
				header("Content-Type: application/octet-stream");
56
                        	header("Content-Disposition: attachment; filename=$fn");
57
                        	header("Content-Length: $fs");
58
				readfile("/tmp/config.xml.nopkg");
59
			} else {
60 5b237745 Scott Ullrich
			$fs = filesize($g['conf_path'] . "/config.xml");
61 8ccc8f1a Scott Ullrich
			header("Content-Type: application/octet-stream");
62 5b237745 Scott Ullrich
			header("Content-Disposition: attachment; filename=$fn");
63
			header("Content-Length: $fs");
64
			readfile($g['conf_path'] . "/config.xml");
65 528cad39 Colin Smith
			}
66 5b237745 Scott Ullrich
			config_unlock();
67
			exit;
68
		} else if ($mode == "restore") {
69
			if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
70
				if (config_install($_FILES['conffile']['tmp_name']) == 0) {
71 bfd3e487 Scott Ullrich
					$command = "/sbin/sysctl -a | grep carp";
72 3af86226 Scott Ullrich
					$fd = fopen($_FILES['conffile']['tmp_name'], "r");
73 bfd3e487 Scott Ullrich
					if(!$fd) {
74 7b2274cb Scott Ullrich
						log_error("Warning, could not open " . $_FILES['conffile']['tmp_name']);
75 bfd3e487 Scott Ullrich
						return 1;
76
					}
77
					while(!feof($fd)) {
78
						    $tmp .= fread($fd,49);
79
					}
80
					fclose($fd);
81
					if(stristr($tmp, "m0n0wall" != FALSE)) {
82 7b2274cb Scott Ullrich
						log_error("Upgrading m0n0wall configuration to pfsense.");
83 bfd3e487 Scott Ullrich
						/* m0n0wall was found in config.  convert it. */
84 63562b76 Scott Ullrich
						$upgradedconfig = str_replace("m0n0wall", "pfsense", $tmp);
85 bfd3e487 Scott Ullrich
						fopen($_FILES['conffile']['tmp_name'], "w");
86 63562b76 Scott Ullrich
						fwrite($fd, $upgradedconfig);
87 bfd3e487 Scott Ullrich
						fclose($fd);
88
					}
89 5b237745 Scott Ullrich
					system_reboot();
90
					$savemsg = "The configuration has been restored. The firewall is now rebooting.";
91
				} else {
92
					$input_errors[] = "The configuration could not be restored.";
93
				}
94
			} else {
95
				$input_errors[] = "The configuration could not be restored (file upload error).";
96
			}
97 8ccc8f1a Scott Ullrich
		} else if ($mode == "reinstallpackages") {
98
			header("Location: pkg_mgr_install.php?mode=reinstallall");
99
			exit;
100 5b237745 Scott Ullrich
		}
101
	}
102
}
103
?>
104
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
105
<html>
106
<head>
107
<title><?=gentitle("Diagnostics: Backup/restore");?></title>
108
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
109
<link href="gui.css" rel="stylesheet" type="text/css">
110
</head>
111
112
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
113
<?php include("fbegin.inc"); ?>
114
      <p class="pgtitle">Diagnostics: Backup/restore</p>
115
            <form action="diag_backup.php" method="post" enctype="multipart/form-data">
116
            <?php if ($input_errors) print_input_errors($input_errors); ?>
117
            <?php if ($savemsg) print_info_box($savemsg); ?>
118 07bd3f83 Scott Ullrich
              <table width="100%" border="0" cellspacing="0" cellpadding="6">
119 8ccc8f1a Scott Ullrich
                <tr>
120 5b237745 Scott Ullrich
                  <td colspan="2" class="listtopic">Backup configuration</td>
121
                </tr>
122 8ccc8f1a Scott Ullrich
                <tr>
123 07bd3f83 Scott Ullrich
                  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
124 8ccc8f1a Scott Ullrich
                  <td width="78%" class="vtable">
125
                    <p> Click this button to download the system configuration
126 5b237745 Scott Ullrich
                      in XML format.<br>
127
                      <br>
128 63562b76 Scott Ullrich
		      <input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">Do not backup package information.<br><br>
129 07bd3f83 Scott Ullrich
                      <input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration"></td>
130
                </tr>
131 8ccc8f1a Scott Ullrich
                <tr>
132 07bd3f83 Scott Ullrich
                  <td colspan="2" class="list" height="12"></td>
133 5b237745 Scott Ullrich
                </tr>
134 8ccc8f1a Scott Ullrich
                <tr>
135 5b237745 Scott Ullrich
                  <td colspan="2" class="listtopic">Restore configuration</td>
136
                </tr>
137 8ccc8f1a Scott Ullrich
                <tr>
138 07bd3f83 Scott Ullrich
                  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
139 8ccc8f1a Scott Ullrich
                  <td width="78%" class="vtable">
140
                    Open a pfSense configuration XML file and click the button
141 5b237745 Scott Ullrich
                      below to restore the configuration.<br>
142
                      <br>
143
                      <strong><span class="red">Note:</span></strong><br>
144
                      The firewall will reboot after restoring the configuration.<br>
145
                      <br>
146
                      <input name="conffile" type="file" class="formfld" id="conffile" size="40">
147
                      <br>
148
                      <br>
149
                      <input name="Submit" type="submit" class="formbtn" id="restore" value="Restore configuration">
150 07bd3f83 Scott Ullrich
                  </td>
151 5b237745 Scott Ullrich
                </tr>
152 8ccc8f1a Scott Ullrich
		<tr>
153
		 <td colspan="2">&nbsp;</td>
154
		</tr>
155
		<tr>
156
		 <td colspan="2" class="listtopic">Reinstall packages</td>
157
		</tr>
158
		<tr>
159
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
160
		  <td width="78%" class="vtable">
161
		  <p> Click this button to reinstall all system packages.  This may wake a while.<br>
162
		  <br>
163
		  <input name="Submit" type="submit" class="formbtn" id="reinstallpackages" value="Reinstall packages"></td>
164
		</tr>
165 5b237745 Scott Ullrich
              </table>
166
            </form>
167
<?php include("fend.inc"); ?>
168
</body>
169
</html>