Project

General

Profile

Download (8.47 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_firmware.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
$d_isfwfile = 1;
33
require_once("guiconfig.inc");
34
require_once("xmlrpc_client.inc");
35

    
36
/* if upgrade in progress, alert user */
37
if(file_exists($d_firmwarelock_path)) {
38
	$pgtitle = "System: Firmware: Manual Update";
39
	include("head.inc");
40
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
41
	include("fbegin.inc");
42
	echo "<p class=\"pgtitle\"><?=$pgtitle?></p>\n";
43
	echo "<div>\n";
44
	print_info_box("An upgrade is currently in progress.<p>The firewall will reboot when the operation is complete.<p><center><img src='/themes/{$g['theme']}/images/icons/icon_fw-update.gif'>");
45
	echo "</div>\n";
46
	include("fend.inc");
47
	echo "</body>";
48
	echo "</html>";
49
	exit;
50
}
51

    
52
/* Handle manual upgrade */
53
if ($_POST && !file_exists($d_firmwarelock_path)) {
54

    
55
	unset($input_errors);
56
	unset($sig_warning);
57

    
58
	if (stristr($_POST['Submit'], "Enable"))
59
		$mode = "enable";
60
	else if (stristr($_POST['Submit'], "Disable"))
61
		$mode = "disable";
62
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
63
		$mode = "upgrade";
64
	else if ($_POST['sig_no']) {
65
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
66
				unlink("{$g['tmp_path']}/firmware.tgz");
67
	}
68
	if ($mode) {
69
		if ($mode == "enable") {
70
			exec_rc_script("/etc/rc.firmware enable");
71
			touch($d_fwupenabled_path);
72
		} else if ($mode == "disable") {
73
			exec_rc_script("/etc/rc.firmware disable");
74
			if (file_exists($d_fwupenabled_path))
75
				unlink($d_fwupenabled_path);
76
		} else if ($mode == "upgrade") {
77
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
78
				/* verify firmware image(s) */
79
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
80
					$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
81
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
82
					/* probably out of memory for the MFS */
83
					$input_errors[] = "Image upload failed (out of memory?)";
84
					exec_rc_script("/etc/rc.firmware disable");
85
					if (file_exists($d_fwupenabled_path))
86
						unlink($d_fwupenabled_path);
87
				} else {
88
					/* move the image so PHP won't delete it */
89
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
90

    
91
					/* check digital signature */
92
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
93

    
94
					if ($sigchk == 1)
95
						$sig_warning = "The digital signature on this image is invalid.";
96
					else if ($sigchk == 2)
97
						$sig_warning = "This image is not digitally signed.";
98
					else if (($sigchk == 3) || ($sigchk == 4))
99
						$sig_warning = "There has been an error verifying the signature on this image.";
100

    
101
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
102
						$input_errors[] = "The image file is corrupt.";
103
						unlink("{$g['tmp_path']}/firmware.tgz");
104
					}
105
				}
106
			}
107

    
108
                        /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
109
                        if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
110
                                if (file_exists("{$g['tmp_path']}/firmware.tgz")) {
111
                                        /* fire up the update script in the background */
112
                                        touch($d_firmwarelock_path);
113
                                        $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
114
                                        mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
115
                                } else {
116
                                        $savemsg = "Firmware image missing or other error, please try again.";
117
                                }
118
                        }
119
		}
120
	}
121
}
122

    
123
$pgtitle = "System: Firmware: Manual Update";
124
include("head.inc");
125

    
126
?>
127
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
128
<?php include("fbegin.inc"); ?>
129
<p class="pgtitle"><?=$pgtitle?></p>
130
<?php if ($input_errors) print_input_errors($input_errors); ?>
131
<?php if ($savemsg) print_info_box($savemsg); ?>  	 
132
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
133
<?php if ($sig_warning && !$input_errors): ?>
134
<form action="system_firmware.php" method="post">
135
<?php
136
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
137
	"is not an official/supported image and may lead to unexpected behavior or security " .
138
	"compromises. Only install images that come from sources that you trust, and make sure ".
139
	"that the image has not been tampered with.<br><br>".
140
	"Do you want to install this image anyway (on your own risk)?";
141
print_info_box($sig_warning);
142
?>
143
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
144
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
145
</form>
146
<?php else: ?>
147
            <?php if (!file_exists($d_firmwarelock_path)): ?>
148
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
149
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
150
	<tr>
151
		<td>
152
<?php
153
	$tab_array = array();
154
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
155
	//$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
156
	//$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
157
	display_top_tabs($tab_array);
158
?>
159
		</td>
160
	</tr>
161
  <tr>
162
    <td>
163
	<div id="mainarea">
164
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
165
                <tr>
166
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
167
		</tr>
168
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
169
                  <td width="78%" class="vtable">
170
            <p>Click &quot;Enable firmware
171
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
172
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
173
              to start the upgrade process.</p>
174
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
175
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
176
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
177
				  <?php else: ?>
178
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
179
                    <br><br>
180
					<strong>Firmware image file: </strong>&nbsp;
181
					<input name="ulfile" type="file" class="formfld">
182
                    <br><br>
183
		    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
184
				  <?php endif; else: ?>
185
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
186
				  <?php endif; ?>
187
                  </td>
188
		</td>
189
                </tr>
190
                <tr>
191
                  <td width="22%" valign="top">&nbsp;</td>
192
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
193
                    </strong></span>DO NOT abort the firmware upgrade once it
194
                    has started. The firewall will reboot automatically after
195
                    storing the new firmware. The configuration will be maintained.</span></td>
196
              </table>
197
		</div>
198
		</tr>
199
		</td>
200
</table>
201

    
202
</form>
203
<?php endif; endif; ?>
204
<?php include("fend.inc"); ?>
205
</body>
206
</html>
(128-128/162)