1
|
#!/usr/local/bin/php
|
2
|
<?php
|
3
|
/*
|
4
|
diag_backup.php
|
5
|
part of m0n0wall (http://m0n0.ch/wall)
|
6
|
|
7
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
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
|
|
20
|
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
|
require("guiconfig.inc");
|
35
|
|
36
|
if ($_POST) {
|
37
|
unset($input_errors);
|
38
|
if (stristr($_POST['Submit'], "Restore"))
|
39
|
$mode = "restore";
|
40
|
else if (stristr($_POST['Submit'], "Reinstall"))
|
41
|
$mode = "reinstallpackages";
|
42
|
else if (stristr($_POST['Submit'], "Download"))
|
43
|
$mode = "download";
|
44
|
if ($_POST["nopackages"] <> "")
|
45
|
$options = "nopackages";
|
46
|
|
47
|
if ($mode) {
|
48
|
if ($mode == "download") {
|
49
|
config_lock();
|
50
|
$fn = "config-" . $config['system']['hostname'] . "." .
|
51
|
$config['system']['domain'] . "-" . date("YmdHis") . ".xml";
|
52
|
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
|
$fs = filesize($g['conf_path'] . "/config.xml");
|
61
|
header("Content-Type: application/octet-stream");
|
62
|
header("Content-Disposition: attachment; filename=$fn");
|
63
|
header("Content-Length: $fs");
|
64
|
readfile($g['conf_path'] . "/config.xml");
|
65
|
}
|
66
|
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
|
$command = "/sbin/sysctl -a | grep carp";
|
72
|
$fd = fopen($_FILES['conffile']['tmp_name'], "r");
|
73
|
if(!$fd) {
|
74
|
log_error("Warning, could not open " . $_FILES['conffile']['tmp_name']);
|
75
|
return 1;
|
76
|
}
|
77
|
while(!feof($fd)) {
|
78
|
$tmp .= fread($fd,49);
|
79
|
}
|
80
|
fclose($fd);
|
81
|
if(stristr($tmp, "m0n0wall" != FALSE)) {
|
82
|
log_error("Upgrading m0n0wall configuration to pfsense.");
|
83
|
/* m0n0wall was found in config. convert it. */
|
84
|
$upgradedconfig = str_replace("m0n0wall", "pfsense", $tmp);
|
85
|
fopen($_FILES['conffile']['tmp_name'], "w");
|
86
|
fwrite($fd, $upgradedconfig);
|
87
|
fclose($fd);
|
88
|
}
|
89
|
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
|
} else if ($mode == "reinstallpackages") {
|
98
|
header("Location: pkg_mgr_install.php?mode=reinstallall");
|
99
|
exit;
|
100
|
}
|
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
|
<table width="100%" border="0" cellspacing="0" cellpadding="6">
|
119
|
<tr>
|
120
|
<td colspan="2" class="listtopic">Backup configuration</td>
|
121
|
</tr>
|
122
|
<tr>
|
123
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
124
|
<td width="78%" class="vtable">
|
125
|
<p> Click this button to download the system configuration
|
126
|
in XML format.<br>
|
127
|
<br>
|
128
|
<input name="nopackages" type="checkbox" class="formcheckbox" id="nopackages">Do not backup package information.<br><br>
|
129
|
<input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration"></td>
|
130
|
</tr>
|
131
|
<tr>
|
132
|
<td colspan="2" class="list" height="12"></td>
|
133
|
</tr>
|
134
|
<tr>
|
135
|
<td colspan="2" class="listtopic">Restore configuration</td>
|
136
|
</tr>
|
137
|
<tr>
|
138
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
139
|
<td width="78%" class="vtable">
|
140
|
Open a pfSense configuration XML file and click the button
|
141
|
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
|
</td>
|
151
|
</tr>
|
152
|
<tr>
|
153
|
<td colspan="2"> </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"> </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
|
</table>
|
166
|
</form>
|
167
|
<?php include("fend.inc"); ?>
|
168
|
</body>
|
169
|
</html>
|