Project

General

Profile

Download (4.93 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 07bd3f83 Scott Ullrich
<?php 
3 5b237745 Scott Ullrich
/*
4
	diag_backup.php
5 07bd3f83 Scott Ullrich
	part of m0n0wall (http://m0n0.ch/wall)
6
	
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 07bd3f83 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 07bd3f83 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 07bd3f83 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 07bd3f83 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 07bd3f83 Scott Ullrich
require("guiconfig.inc"); 
35 5b237745 Scott Ullrich
36
if ($_POST) {
37
38
	unset($input_errors);
39 07bd3f83 Scott Ullrich
	
40 5b237745 Scott Ullrich
	if (stristr($_POST['Submit'], "Restore"))
41
		$mode = "restore";
42
	else if (stristr($_POST['Submit'], "Download"))
43
		$mode = "download";
44 07bd3f83 Scott Ullrich
		
45 5b237745 Scott Ullrich
	if ($mode) {
46
		if ($mode == "download") {
47
			config_lock();
48 07bd3f83 Scott Ullrich
			
49
			$fn = "config-" . $config['system']['hostname'] . "." . 
50 5b237745 Scott Ullrich
				$config['system']['domain'] . "-" . date("YmdHis") . ".xml";
51 07bd3f83 Scott Ullrich
			
52 5b237745 Scott Ullrich
			$fs = filesize($g['conf_path'] . "/config.xml");
53 07bd3f83 Scott Ullrich
			header("Content-Type: application/octet-stream"); 
54 5b237745 Scott Ullrich
			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 07bd3f83 Scott Ullrich
              <table width="100%" border="0" cellspacing="0" cellpadding="6">
89
                <tr> 
90 5b237745 Scott Ullrich
                  <td colspan="2" class="listtopic">Backup configuration</td>
91
                </tr>
92 07bd3f83 Scott Ullrich
                <tr> 
93
                  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
94
                  <td width="78%" class="vtable"> 
95
                    <p> Click this button to download the system configuration 
96 5b237745 Scott Ullrich
                      in XML format.<br>
97
                      <br>
98 07bd3f83 Scott Ullrich
                      <input name="Submit" type="submit" class="formbtn" id="download" value="Download configuration"></td>
99
                </tr>
100
                <tr> 
101
                  <td colspan="2" class="list" height="12"></td>
102 5b237745 Scott Ullrich
                </tr>
103 07bd3f83 Scott Ullrich
                <tr> 
104 5b237745 Scott Ullrich
                  <td colspan="2" class="listtopic">Restore configuration</td>
105
                </tr>
106 07bd3f83 Scott Ullrich
                <tr> 
107
                  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
108
                  <td width="78%" class="vtable"> 
109
                    Open a m0n0wall configuration XML file and click the button 
110 5b237745 Scott Ullrich
                      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 07bd3f83 Scott Ullrich
                  </td>
120 5b237745 Scott Ullrich
                </tr>
121
              </table>
122
            </form>
123
<?php include("fend.inc"); ?>
124
</body>
125
</html>