Project

General

Profile

Download (9.12 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 4668f9f7 Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4
	system_firmware.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 4668f9f7 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 4668f9f7 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 4668f9f7 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 4668f9f7 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 4668f9f7 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 4668f9f7 Scott Ullrich
$d_isfwfile = 1; require("guiconfig.inc");
33 5b237745 Scott Ullrich
34 18ff56f2 Scott Ullrich
if($_GET['autoupgrade'] <> "") {
35 99970541 Scott Ullrich
    $http_auth_username = "";
36
    $http_auth_password = "";
37
    if($config['system']['proxy_auth_username'])
38
	$http_auth_username = $config['system']['proxy_auth_username'];
39
    if($config['system']['proxy_auth_password'])
40
	$http_auth_password = $config['system']['proxy_auth_password'];
41
    exec_rc_script_async("/etc/rc.firmware_auto {$http_auth_username} {$http_auth_password}");
42 18ff56f2 Scott Ullrich
    $savemsg = "pfSense is now auto upgrading.  The firewall will automatically reboot if it succeeds.";
43
}
44
45 3c041ee4 Scott Ullrich
/* checks with pfSense to see if a newer firmware version is available;
46 5b237745 Scott Ullrich
   returns any HTML message it gets from the server */
47
function check_firmware_version() {
48
	global $g;
49 4668f9f7 Scott Ullrich
	$post = "platform=" . rawurlencode($g['platform']) .
50 5b237745 Scott Ullrich
		"&version=" . rawurlencode(trim(file_get_contents("/etc/version")));
51 4668f9f7 Scott Ullrich
52 3c041ee4 Scott Ullrich
	$rfd = @fsockopen("www.pfSense.com", 80, $errno, $errstr, 3);
53 5b237745 Scott Ullrich
	if ($rfd) {
54 643a50c3 Scott Ullrich
		$hdr = "POST /pfSense/checkversion.php HTTP/1.0\r\n";
55 5b237745 Scott Ullrich
		$hdr .= "Content-Type: application/x-www-form-urlencoded\r\n";
56 6ab78253 Scott Ullrich
		$hdr .= "User-Agent: pfSense-webConfigurator/1.0\r\n";
57 3c041ee4 Scott Ullrich
		$hdr .= "Host: www.pfSense.com\r\n";
58 5b237745 Scott Ullrich
		$hdr .= "Content-Length: " . strlen($post) . "\r\n\r\n";
59 4668f9f7 Scott Ullrich
60 5b237745 Scott Ullrich
		fwrite($rfd, $hdr);
61
		fwrite($rfd, $post);
62 4668f9f7 Scott Ullrich
63 5b237745 Scott Ullrich
		$inhdr = true;
64
		$resp = "";
65
		while (!feof($rfd)) {
66
			$line = fgets($rfd);
67
			if ($inhdr) {
68
				if (trim($line) == "")
69
					$inhdr = false;
70
			} else {
71
				$resp .= $line;
72
			}
73
		}
74 4668f9f7 Scott Ullrich
75 5b237745 Scott Ullrich
		fclose($rfd);
76 4668f9f7 Scott Ullrich
77 ac869cd9 Scott Ullrich
		if($_GET['autoupgrade'] <> "")
78
		    return;
79
80 5b237745 Scott Ullrich
		return $resp;
81
	}
82 4668f9f7 Scott Ullrich
83 5b237745 Scott Ullrich
	return null;
84
}
85
86
if ($_POST && !file_exists($d_firmwarelock_path)) {
87
88
	unset($input_errors);
89
	unset($sig_warning);
90 4668f9f7 Scott Ullrich
91 5b237745 Scott Ullrich
	if (stristr($_POST['Submit'], "Enable"))
92
		$mode = "enable";
93
	else if (stristr($_POST['Submit'], "Disable"))
94
		$mode = "disable";
95
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
96
		$mode = "upgrade";
97 67965af4 Scott Ullrich
	else if ($_POST['sig_no']) {
98 5424dedc Scott Ullrich
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
99
				unlink("{$g['tmp_path']}/firmware.tgz");
100 67965af4 Scott Ullrich
    }
101 4668f9f7 Scott Ullrich
102 5b237745 Scott Ullrich
	if ($mode) {
103
		if ($mode == "enable") {
104
			exec_rc_script("/etc/rc.firmware enable");
105
			touch($d_fwupenabled_path);
106
		} else if ($mode == "disable") {
107
			exec_rc_script("/etc/rc.firmware disable");
108
			if (file_exists($d_fwupenabled_path))
109
				unlink($d_fwupenabled_path);
110
		} else if ($mode == "upgrade") {
111
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
112
				/* verify firmware image(s) */
113
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
114
					$input_errors[] = "The uploaded image file is not for this platfom ({$g['platform']}).";
115
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
116
					/* probably out of memory for the MFS */
117
					$input_errors[] = "Image upload failed (out of memory?)";
118
					exec_rc_script("/etc/rc.firmware disable");
119
					if (file_exists($d_fwupenabled_path))
120
						unlink($d_fwupenabled_path);
121
				} else {
122
					/* move the image so PHP won't delete it */
123 5424dedc Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
124 4668f9f7 Scott Ullrich
125 5b237745 Scott Ullrich
					/* check digital signature */
126 5424dedc Scott Ullrich
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
127 4668f9f7 Scott Ullrich
128 5b237745 Scott Ullrich
					if ($sigchk == 1)
129
						$sig_warning = "The digital signature on this image is invalid.";
130
					else if ($sigchk == 2)
131
						$sig_warning = "This image is not digitally signed.";
132
					else if (($sigchk == 3) || ($sigchk == 4))
133
						$sig_warning = "There has been an error verifying the signature on this image.";
134 4668f9f7 Scott Ullrich
135 5424dedc Scott Ullrich
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
136 5b237745 Scott Ullrich
						$input_errors[] = "The image file is corrupt.";
137 5424dedc Scott Ullrich
						unlink("{$g['tmp_path']}/firmware.tgz");
138 5b237745 Scott Ullrich
					}
139
				}
140
			}
141
142 4668f9f7 Scott Ullrich
			if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
143 5b237745 Scott Ullrich
				/* fire up the update script in the background */
144
				touch($d_firmwarelock_path);
145 5424dedc Scott Ullrich
				exec_rc_script_async("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
146 4668f9f7 Scott Ullrich
147 5b237745 Scott Ullrich
				$savemsg = "The firmware is now being installed. The firewall will reboot automatically.";
148
			}
149
		}
150
	}
151
} else {
152
	if (!isset($config['system']['disablefirmwarecheck']))
153
		$fwinfo = check_firmware_version();
154
}
155
?>
156
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
157
<html>
158
<head>
159
<title><?=gentitle("System: Firmware");?></title>
160
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
161
<link href="gui.css" rel="stylesheet" type="text/css">
162
</head>
163
164
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
165
<?php include("fbegin.inc"); ?>
166
<p class="pgtitle">System: Firmware</p>
167
<?php if ($input_errors) print_input_errors($input_errors); ?>
168
<?php if ($savemsg) print_info_box($savemsg); ?>
169 3c041ee4 Scott Ullrich
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
170 5b237745 Scott Ullrich
<?php if (!in_array($g['platform'], $fwupplatforms)): ?>
171
<p><strong>Firmware uploading is not supported on this platform.</strong></p>
172
<?php elseif ($sig_warning && !$input_errors): ?>
173
<form action="system_firmware.php" method="post">
174 4668f9f7 Scott Ullrich
<?php
175 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
176
	"is not an official/supported image and may lead to unexpected behavior or security " .
177
	"compromises. Only install images that come from sources that you trust, and make sure ".
178
	"that the image has not been tampered with.<br><br>".
179
	"Do you want to install this image anyway (on your own risk)?";
180
print_info_box($sig_warning);
181
?>
182
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
183
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
184
</form>
185
<?php else: ?>
186
            <?php if (!file_exists($d_firmwarelock_path)): ?>
187 0013ccf1 Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
188
<?php if($savemsg == ""): ?>
189 4668f9f7 Scott Ullrich
            <p>Click &quot;Enable firmware
190 5b237745 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.img)
191 4668f9f7 Scott Ullrich
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
192 5b237745 Scott Ullrich
              to start the upgrade process.</p>
193 0013ccf1 Scott Ullrich
194 5b237745 Scott Ullrich
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
195 4668f9f7 Scott Ullrich
                <tr>
196 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
197 4668f9f7 Scott Ullrich
                  <td width="78%">
198 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
199
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
200
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
201
				  <?php else: ?>
202
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
203
                    <br><br>
204
					<strong>Firmware image file: </strong>&nbsp;<input name="ulfile" type="file" class="formfld">
205
                    <br><br>
206
                    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
207
				  <?php endif; else: ?>
208
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
209
				  <?php endif; ?>
210
                  </td>
211
                </tr>
212 4668f9f7 Scott Ullrich
                <tr>
213 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
214
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
215 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
216
                    has started. The firewall will reboot automatically after
217 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
218
                </tr>
219 18ff56f2 Scott Ullrich
220
		<tr>
221
		 <td colspan="2">&nbsp;</td>
222
		</tr>
223
		<tr>
224
		 <td colspan="2" class="listtopic">Invoke pfSense Auto Upgrade</td>
225
		</tr>
226
		<tr>
227
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
228
		  <td width="78%" class="vtable">
229 81b8cb2e Scott Ullrich
		  <p> Click this button to automatically upgrade pfSense in the background.  This may take a while.<br>
230 18ff56f2 Scott Ullrich
		  <br>
231
		  <a href="system_firmware.php?autoupgrade=true">Invoke Auto Upgrade</a>
232
		</tr>
233 5b237745 Scott Ullrich
              </table>
234 0013ccf1 Scott Ullrich
<?php endif ?>
235
236 5b237745 Scott Ullrich
</form>
237
<?php endif; endif; ?>
238
<?php include("fend.inc"); ?>
239
</body>
240
</html>