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
|
|
38
|
unset($input_errors);
|
39
|
|
40
|
if (stristr($_POST['Submit'], "Restore"))
|
41
|
$mode = "restore";
|
42
|
else if (stristr($_POST['Submit'], "Download"))
|
43
|
$mode = "download";
|
44
|
|
45
|
if ($mode) {
|
46
|
if ($mode == "download") {
|
47
|
config_lock();
|
48
|
|
49
|
$fn = "config-" . $config['system']['hostname'] . "." .
|
50
|
$config['system']['domain'] . "-" . date("YmdHis") . ".xml";
|
51
|
|
52
|
$fs = filesize($g['conf_path'] . "/config.xml");
|
53
|
header("Content-Type: application/octet-stream");
|
54
|
header("Content-Disposition: attachment; filename=$fn");
|
55
|
header("Content-Length: $fs");
|
56
|
readfile($g['conf_path'] . "/config.xml");
|
57
|
config_unlock();
|
58
|
exit;
|
59
|
} else if ($mode == "restore") {
|
60
|
if (is_uploaded_file($_FILES['conffile']['tmp_name'])) {
|
61
|
if (config_install($_FILES['conffile']['tmp_name']) == 0) {
|
62
|
system_reboot();
|
63
|
$savemsg = "The configuration has been restored. The firewall is now rebooting.";
|
64
|
} else {
|
65
|
$input_errors[] = "The configuration could not be restored.";
|
66
|
}
|
67
|
} else {
|
68
|
$input_errors[] = "The configuration could not be restored (file upload error).";
|
69
|
}
|
70
|
}
|
71
|
}
|
72
|
}
|
73
|
?>
|
74
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
75
|
<html>
|
76
|
<head>
|
77
|
<title><?=gentitle("Diagnostics: Backup/restore");?></title>
|
78
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
79
|
<link href="gui.css" rel="stylesheet" type="text/css">
|
80
|
</head>
|
81
|
|
82
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
83
|
<?php include("fbegin.inc"); ?>
|
84
|
<p class="pgtitle">Diagnostics: Backup/restore</p>
|
85
|
<form action="diag_backup.php" method="post" enctype="multipart/form-data">
|
86
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
87
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
88
|
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
89
|
<tr>
|
90
|
<td colspan="2" class="listtopic">Backup configuration</td>
|
91
|
</tr>
|
92
|
<tr>
|
93
|
<td width="22%" valign="baseline"> </td>
|
94
|
<td width="78%" class="listn">
|
95
|
<p> Click this button to download the system configuration
|
96
|
in XML format.<br>
|
97
|
<br>
|
98
|
<input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration">
|
99
|
<br>
|
100
|
<br>
|
101
|
</p></td>
|
102
|
</tr>
|
103
|
<tr>
|
104
|
<td colspan="2" class="listtopic">Restore configuration</td>
|
105
|
</tr>
|
106
|
<tr>
|
107
|
<td width="22%" valign="baseline"> </td>
|
108
|
<td width="78%" class="listn">
|
109
|
<p> Open a m0n0wall configuration XML file and click the button
|
110
|
below to restore the configuration.<br>
|
111
|
<br>
|
112
|
<strong><span class="red">Note:</span></strong><br>
|
113
|
The firewall will reboot after restoring the configuration.<br>
|
114
|
<br>
|
115
|
<input name="conffile" type="file" class="formfld" id="conffile" size="40">
|
116
|
<br>
|
117
|
<br>
|
118
|
<input name="Submit" type="submit" class="formbtn" id="restore" value="Restore configuration">
|
119
|
</p>
|
120
|
</td>
|
121
|
</tr>
|
122
|
</table>
|
123
|
</form>
|
124
|
<?php include("fend.inc"); ?>
|
125
|
</body>
|
126
|
</html>
|