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