1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
system_firmware.php
|
5
|
Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
|
6
|
All rights reserved.
|
7
|
|
8
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
9
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
10
|
All rights reserved.
|
11
|
|
12
|
|
13
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
14
|
|
15
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
16
|
All rights reserved.
|
17
|
|
18
|
Redistribution and use in source and binary forms, with or without
|
19
|
modification, are permitted provided that the following conditions are met:
|
20
|
|
21
|
1. Redistributions of source code must retain the above copyright notice,
|
22
|
this list of conditions and the following disclaimer.
|
23
|
|
24
|
2. Redistributions in binary form must reproduce the above copyright
|
25
|
notice, this list of conditions and the following disclaimer in the
|
26
|
documentation and/or other materials provided with the distribution.
|
27
|
|
28
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
29
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
30
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
31
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
32
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
33
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
34
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
35
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
36
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
37
|
POSSIBILITY OF SUCH DAMAGE.
|
38
|
*/
|
39
|
|
40
|
$d_isfwfile = 1;
|
41
|
require_once("guiconfig.inc");
|
42
|
|
43
|
$curcfg = $config['system']['firmware'];
|
44
|
|
45
|
|
46
|
require_once("xmlrpc_client.inc");
|
47
|
|
48
|
/* Allow additional execution time 0 = no limit. */
|
49
|
ini_set('max_execution_time', '3600');
|
50
|
ini_set('max_input_time', '3600');
|
51
|
|
52
|
function file_is_for_platform($filename) {
|
53
|
global $g;
|
54
|
if($g['platform'] == "nanobsd") {
|
55
|
if(strstr($filename, "nanobsd"))
|
56
|
return true;
|
57
|
else
|
58
|
return false;
|
59
|
}
|
60
|
exec("tar xzf $filename -C /tmp/ etc/platform");
|
61
|
if(!file_exists("/tmp/etc/platform"))
|
62
|
return false;
|
63
|
$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform"));
|
64
|
if($g['platform'] == $upgrade_is_for_platform) {
|
65
|
unlink("/tmp/etc/platform");
|
66
|
return true;
|
67
|
}
|
68
|
return false;
|
69
|
}
|
70
|
|
71
|
/* if upgrade in progress, alert user */
|
72
|
if(file_exists($d_firmwarelock_path)) {
|
73
|
$pgtitle = "System: Firmware: Manual Update";
|
74
|
include("head.inc");
|
75
|
echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
|
76
|
include("fbegin.inc");
|
77
|
echo "<div>\n";
|
78
|
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'>");
|
79
|
echo "</div>\n";
|
80
|
include("fend.inc");
|
81
|
echo "</body>";
|
82
|
echo "</html>";
|
83
|
exit;
|
84
|
}
|
85
|
|
86
|
if($_POST['kerneltype']) {
|
87
|
system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
|
88
|
}
|
89
|
|
90
|
/* Handle manual upgrade */
|
91
|
if ($_POST && !file_exists($d_firmwarelock_path)) {
|
92
|
|
93
|
unset($input_errors);
|
94
|
unset($sig_warning);
|
95
|
|
96
|
if (stristr($_POST['Submit'], "Enable"))
|
97
|
$mode = "enable";
|
98
|
else if (stristr($_POST['Submit'], "Disable"))
|
99
|
$mode = "disable";
|
100
|
else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
|
101
|
$mode = "upgrade";
|
102
|
else if ($_POST['sig_no']) {
|
103
|
if(file_exists("{$g['upload_path']}/firmware.tgz"))
|
104
|
unlink("{$g['upload_path']}/firmware.tgz");
|
105
|
}
|
106
|
if ($mode) {
|
107
|
if ($mode == "enable") {
|
108
|
conf_mount_rw();
|
109
|
touch($d_fwupenabled_path);
|
110
|
} else if ($mode == "disable") {
|
111
|
conf_mount_ro();
|
112
|
if (file_exists($d_fwupenabled_path))
|
113
|
unlink($d_fwupenabled_path);
|
114
|
} else if ($mode == "upgrade") {
|
115
|
if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
|
116
|
/* verify firmware image(s) */
|
117
|
if (file_is_for_platform($_FILES['ulfile']['tmp_name']) == false && !$_POST['sig_override'])
|
118
|
$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
|
119
|
else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
|
120
|
/* probably out of memory for the MFS */
|
121
|
$input_errors[] = "Image upload failed (out of memory?)";
|
122
|
exec_rc_script("/etc/rc.firmware disable");
|
123
|
if (file_exists($d_fwupenabled_path))
|
124
|
unlink($d_fwupenabled_path);
|
125
|
} else {
|
126
|
/* move the image so PHP won't delete it */
|
127
|
rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
|
128
|
|
129
|
/* check digital signature */
|
130
|
$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
|
131
|
|
132
|
if ($sigchk == 1)
|
133
|
$sig_warning = "The digital signature on this image is invalid.";
|
134
|
else if ($sigchk == 2)
|
135
|
$sig_warning = "This image is not digitally signed.";
|
136
|
else if (($sigchk == 3) || ($sigchk == 4))
|
137
|
$sig_warning = "There has been an error verifying the signature on this image.";
|
138
|
|
139
|
if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
|
140
|
$input_errors[] = "The image file is corrupt.";
|
141
|
unlink("{$g['upload_path']}/firmware.tgz");
|
142
|
}
|
143
|
}
|
144
|
}
|
145
|
|
146
|
run_plugins("/usr/local/pkg/firmware_upgrade");
|
147
|
|
148
|
/* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
|
149
|
if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
|
150
|
if (file_exists("{$g['upload_path']}/firmware.tgz")) {
|
151
|
/* fire up the update script in the background */
|
152
|
touch($d_firmwarelock_path);
|
153
|
$savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
|
154
|
if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
|
155
|
mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
|
156
|
else if(stristr($_FILES['ulfile']['name'],"bdiff"))
|
157
|
mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
|
158
|
else
|
159
|
mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
|
160
|
} else {
|
161
|
$savemsg = "Firmware image missing or other error, please try again.";
|
162
|
}
|
163
|
}
|
164
|
}
|
165
|
}
|
166
|
}
|
167
|
|
168
|
$pgtitle = "System: Firmware: Manual Update";
|
169
|
include("head.inc");
|
170
|
|
171
|
?>
|
172
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
173
|
<?php include("fbegin.inc"); ?>
|
174
|
<p class="pgtitle"><?=$pgtitle?></p>
|
175
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
176
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
177
|
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
|
178
|
<?php if ($sig_warning && !$input_errors): ?>
|
179
|
<form action="system_firmware.php" method="post">
|
180
|
<?php
|
181
|
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
|
182
|
"is not an official/supported image and may lead to unexpected behavior or security " .
|
183
|
"compromises. Only install images that come from sources that you trust, and make sure ".
|
184
|
"that the image has not been tampered with.<br><br>".
|
185
|
"Do you want to install this image anyway (on your own risk)?";
|
186
|
print_info_box($sig_warning);
|
187
|
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
|
188
|
echo "<input type='hidden' name='isnano' id='isnano' value='yes'>\n";
|
189
|
?>
|
190
|
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
|
191
|
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
|
192
|
</form>
|
193
|
<?php else: ?>
|
194
|
<?php if (!file_exists($d_firmwarelock_path)): ?>
|
195
|
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
|
196
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
197
|
<tr>
|
198
|
<td>
|
199
|
<?php
|
200
|
$tab_array = array();
|
201
|
$tab_array[0] = array("Manual Update", true, "system_firmware.php");
|
202
|
$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
|
203
|
$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
|
204
|
display_top_tabs($tab_array);
|
205
|
?>
|
206
|
</td>
|
207
|
</tr>
|
208
|
<tr>
|
209
|
<td>
|
210
|
<div id="mainarea">
|
211
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
|
212
|
<tr>
|
213
|
<td colspan="2" class="listtopic">Invoke <?=$g['product_name']?> Manual Upgrade</td>
|
214
|
</tr>
|
215
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
216
|
<td width="78%" class="vtable">
|
217
|
<p>Click "Enable firmware
|
218
|
upload" below, then choose the image file (<?=$g['firmware_update_text'];?>)
|
219
|
to be uploaded.<br>Click "Upgrade firmware"
|
220
|
to start the upgrade process.</p>
|
221
|
<?php if (!file_exists($d_sysrebootreqd_path)): ?>
|
222
|
<?php if (!file_exists($d_fwupenabled_path)): ?>
|
223
|
<input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
|
224
|
<?php else: ?>
|
225
|
<input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
|
226
|
<br><br>
|
227
|
<strong>Firmware image file: </strong>
|
228
|
<input name="ulfile" type="file" class="formfld">
|
229
|
<br><br>
|
230
|
<?php
|
231
|
if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
|
232
|
if($g['platform'] == "pfSense") {
|
233
|
echo "Please select kernel type: ";
|
234
|
echo "<select name='kerneltype'>";
|
235
|
echo "<option value='SMP'>Multiprocessor kernel</option>";
|
236
|
echo "<option value='UP'>Uniprocessor kernel</option>";
|
237
|
echo "<option value='wrap'>Embedded kernel</option>";
|
238
|
echo "<option value='Developers'>Developers kernel</option>";
|
239
|
echo "</select>";
|
240
|
echo "<br><br>";
|
241
|
}
|
242
|
}
|
243
|
?>
|
244
|
<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
|
245
|
<?php endif; else: ?>
|
246
|
<strong>You must reboot the system before you can upgrade the firmware.</strong>
|
247
|
<?php endif; ?>
|
248
|
</td>
|
249
|
</td>
|
250
|
</tr>
|
251
|
<tr>
|
252
|
<td width="22%" valign="top"> </td>
|
253
|
<td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
|
254
|
</strong></span>DO NOT abort the firmware upgrade once it
|
255
|
has started. The firewall will reboot automatically after
|
256
|
storing the new firmware. The configuration will be maintained.</span></td>
|
257
|
</table>
|
258
|
</div>
|
259
|
</tr>
|
260
|
</td>
|
261
|
</table>
|
262
|
|
263
|
</form>
|
264
|
<?php endif; endif; ?>
|
265
|
<?php include("fend.inc"); ?>
|
266
|
</body>
|
267
|
</html>
|