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
|
Redistribution and use in source and binary forms, with or without
|
13
|
modification, are permitted provided that the following conditions are met:
|
14
|
|
15
|
1. Redistributions of source code must retain the above copyright notice,
|
16
|
this list of conditions and the following disclaimer.
|
17
|
|
18
|
2. Redistributions in binary form must reproduce the above copyright
|
19
|
notice, this list of conditions and the following disclaimer in the
|
20
|
documentation and/or other materials provided with the distribution.
|
21
|
|
22
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
23
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
24
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
25
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
26
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
27
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
29
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
30
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
31
|
POSSIBILITY OF SUCH DAMAGE.
|
32
|
*/
|
33
|
/*
|
34
|
pfSense_BUILDER_BINARIES: /usr/bin/tar
|
35
|
pfSense_MODULE: firmware
|
36
|
*/
|
37
|
|
38
|
##|+PRIV
|
39
|
##|*IDENT=page-system-firmware-manualupdate
|
40
|
##|*NAME=System: Firmware: Manual Update page
|
41
|
##|*DESCR=Allow access to the 'System: Firmware: Manual Update' page.
|
42
|
##|*MATCH=system_firmware.php*
|
43
|
##|-PRIV
|
44
|
|
45
|
$d_isfwfile = 1;
|
46
|
$nocsrf = true;
|
47
|
|
48
|
require_once("globals.inc");
|
49
|
require_once("functions.inc");
|
50
|
require_once("guiconfig.inc");
|
51
|
|
52
|
$curcfg = $config['system']['firmware'];
|
53
|
|
54
|
$kerneltypes = array(
|
55
|
'SMP' => gettext("Standard Kernel"),
|
56
|
'wrap' => gettext("Embedded Kernel"),
|
57
|
);
|
58
|
|
59
|
require_once("xmlrpc_client.inc");
|
60
|
|
61
|
/* Allow additional execution time 0 = no limit. */
|
62
|
ini_set('max_execution_time', '9999');
|
63
|
ini_set('max_input_time', '9999');
|
64
|
|
65
|
function file_is_for_platform($filename, $ul_name) {
|
66
|
global $g;
|
67
|
if($g['platform'] == "nanobsd") {
|
68
|
if(stristr($ul_name, "nanobsd"))
|
69
|
return true;
|
70
|
else
|
71
|
return false;
|
72
|
}
|
73
|
$_gb = exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
|
74
|
unset($_gb);
|
75
|
if(!file_exists("/tmp/etc/platform"))
|
76
|
return false;
|
77
|
$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform", " \n\t\r"));
|
78
|
if ($g['platform'] == $upgrade_is_for_platform) {
|
79
|
@unlink("/tmp/etc/platform");
|
80
|
return true;
|
81
|
}
|
82
|
return false;
|
83
|
}
|
84
|
|
85
|
function file_upload_error_message($error_code) {
|
86
|
switch ($error_code) {
|
87
|
case UPLOAD_ERR_INI_SIZE:
|
88
|
return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
|
89
|
case UPLOAD_ERR_FORM_SIZE:
|
90
|
return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
|
91
|
case UPLOAD_ERR_PARTIAL:
|
92
|
return gettext('The uploaded file was only partially uploaded');
|
93
|
case UPLOAD_ERR_NO_FILE:
|
94
|
return gettext('No file was uploaded');
|
95
|
case UPLOAD_ERR_NO_TMP_DIR:
|
96
|
return gettext('Missing a temporary folder');
|
97
|
case UPLOAD_ERR_CANT_WRITE:
|
98
|
return gettext('Failed to write file to disk');
|
99
|
case UPLOAD_ERR_EXTENSION:
|
100
|
return gettext('File upload stopped by extension');
|
101
|
default:
|
102
|
return gettext('Unknown upload error');
|
103
|
}
|
104
|
}
|
105
|
|
106
|
/* if upgrade in progress, alert user */
|
107
|
if(is_subsystem_dirty('firmwarelock')) {
|
108
|
$pgtitle = array(gettext("System"),gettext("Firmware"),gettext("Manual Update"));
|
109
|
include("head.inc");
|
110
|
echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
|
111
|
include("fbegin.inc");
|
112
|
echo "<div>\n";
|
113
|
print_info_box(gettext("An upgrade is currently in progress.<p>The firewall will reboot when the operation is complete.") . "</p><p><img src='/themes/{$g['theme']}/images/icons/icon_fw-update.gif' alt='update' /></p>");
|
114
|
echo "</div>\n";
|
115
|
include("fend.inc");
|
116
|
echo "</body>";
|
117
|
echo "</html>";
|
118
|
exit;
|
119
|
}
|
120
|
|
121
|
if($_POST['backupbeforeupgrade'])
|
122
|
touch("/tmp/perform_full_backup.txt");
|
123
|
|
124
|
if ($_POST['kerneltype'] && in_array($_POST['kerneltype'], array_keys($kerneltypes)))
|
125
|
file_put_contents("/boot/kernel/pfsense_kernel.txt", $_POST['kerneltype']);
|
126
|
|
127
|
/* Handle manual upgrade */
|
128
|
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
|
129
|
|
130
|
unset($input_errors);
|
131
|
unset($sig_warning);
|
132
|
|
133
|
if (stristr($_POST['Submit'], gettext("Enable")))
|
134
|
$mode = "enable";
|
135
|
else if (stristr($_POST['Submit'], gettext("Disable")))
|
136
|
$mode = "disable";
|
137
|
else if (stristr($_POST['Submit'], gettext("Upgrade")) || $_POST['sig_override'])
|
138
|
$mode = "upgrade";
|
139
|
else if ($_POST['sig_no']) {
|
140
|
if(file_exists("{$g['upload_path']}/firmware.tgz"))
|
141
|
unlink("{$g['upload_path']}/firmware.tgz");
|
142
|
}
|
143
|
if ($mode) {
|
144
|
if ($mode == "enable") {
|
145
|
conf_mount_rw();
|
146
|
mark_subsystem_dirty('firmware');
|
147
|
} else if ($mode == "disable") {
|
148
|
conf_mount_ro();
|
149
|
clear_subsystem_dirty('firmware');
|
150
|
} else if ($mode == "upgrade") {
|
151
|
if ($_FILES['ulfile']['error'])
|
152
|
$errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
|
153
|
if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
|
154
|
/* verify firmware image(s) */
|
155
|
if (file_is_for_platform($_FILES['ulfile']['tmp_name'], $_FILES['ulfile']['name']) == false && !$_POST['sig_override'])
|
156
|
$input_errors[] = gettext("The uploaded image file is not for this platform.");
|
157
|
else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
|
158
|
/* probably out of memory for the MFS */
|
159
|
$input_errors[] = gettext("Image upload failed (out of memory?)");
|
160
|
mwexec("/etc/rc.firmware disable");
|
161
|
clear_subsystem_dirty('firmware');
|
162
|
} else {
|
163
|
/* move the image so PHP won't delete it */
|
164
|
rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
|
165
|
|
166
|
/* check digital signature */
|
167
|
$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
|
168
|
|
169
|
if ($sigchk == 1)
|
170
|
$sig_warning = gettext("The digital signature on this image is invalid.");
|
171
|
else if ($sigchk == 2 && !isset($config['system']['firmware']['allowinvalidsig']))
|
172
|
$sig_warning = gettext("This image is not digitally signed.");
|
173
|
else if (($sigchk >= 3))
|
174
|
$sig_warning = gettext("There has been an error verifying the signature on this image.");
|
175
|
|
176
|
if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
|
177
|
$input_errors[] = gettext("The image file is corrupt.");
|
178
|
unlink("{$g['upload_path']}/firmware.tgz");
|
179
|
}
|
180
|
}
|
181
|
}
|
182
|
|
183
|
run_plugins("/usr/local/pkg/firmware_upgrade");
|
184
|
|
185
|
/* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
|
186
|
if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
|
187
|
if (file_exists("{$g['upload_path']}/firmware.tgz")) {
|
188
|
/* fire up the update script in the background */
|
189
|
mark_subsystem_dirty('firmwarelock');
|
190
|
$savemsg = gettext("The firmware is now being updated. The firewall will reboot automatically.");
|
191
|
if (stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
|
192
|
mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
|
193
|
else if(stristr($_FILES['ulfile']['name'],"bdiff"))
|
194
|
mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
|
195
|
else {
|
196
|
if($g['platform'] == "nanobsd")
|
197
|
$whichone = "pfSenseNanoBSDupgrade";
|
198
|
else
|
199
|
$whichone = "pfSenseupgrade";
|
200
|
mwexec_bg("/etc/rc.firmware {$whichone} {$g['upload_path']}/firmware.tgz");
|
201
|
unset($whichone);
|
202
|
}
|
203
|
} else
|
204
|
$savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."),$errortext);
|
205
|
}
|
206
|
}
|
207
|
}
|
208
|
}
|
209
|
|
210
|
$pgtitle = array(gettext("System"),gettext("Firmware"));
|
211
|
include("head.inc");
|
212
|
|
213
|
?>
|
214
|
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
|
215
|
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
|
216
|
<?php
|
217
|
/* Construct an upload_id for this session */
|
218
|
if (!session_id())
|
219
|
$upload_id = uniqid();
|
220
|
else
|
221
|
$upload_id = session_id();
|
222
|
?>
|
223
|
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" />
|
224
|
<?php include("fbegin.inc"); ?>
|
225
|
<?php if ($input_errors) print_input_errors($input_errors); ?>
|
226
|
<?php if ($savemsg) print_info_box($savemsg); ?>
|
227
|
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
|
228
|
<?php if ($sig_warning && !$input_errors): ?>
|
229
|
<?php
|
230
|
$sig_warning = "<strong>" . $sig_warning . "</strong><br/>" . gettext("This means that the image you uploaded " .
|
231
|
"is not an official/supported image and may lead to unexpected behavior or security " .
|
232
|
"compromises. Only install images that come from sources that you trust, and make sure ".
|
233
|
"that the image has not been tampered with.") . "<br/><br/>".
|
234
|
gettext("Do you want to install this image anyway (on your own risk)?");
|
235
|
print_info_box($sig_warning);
|
236
|
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
|
237
|
echo "<input type='hidden' name='isnano' id='isnano' value='yes' />\n";
|
238
|
?>
|
239
|
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" <?=gettext("Yes");?> " />
|
240
|
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" <?=gettext("No"); ?> " />
|
241
|
<?php else: ?>
|
242
|
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
|
243
|
<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firmware">
|
244
|
<tr>
|
245
|
<td>
|
246
|
<?php
|
247
|
$tab_array = array();
|
248
|
$tab_array[] = array(gettext("Manual Update"), true, "system_firmware.php");
|
249
|
$tab_array[] = array(gettext("Auto Update"), false, "system_firmware_check.php");
|
250
|
$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
|
251
|
if($g['hidedownloadbackup'] == false)
|
252
|
$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
|
253
|
display_top_tabs($tab_array);
|
254
|
?>
|
255
|
</td>
|
256
|
</tr>
|
257
|
<tr>
|
258
|
<td>
|
259
|
<div id="mainarea">
|
260
|
<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
|
261
|
<tr>
|
262
|
<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] ." ". gettext("Manual Upgrade"); ?></td>
|
263
|
</tr>
|
264
|
<tr>
|
265
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
266
|
<td width="78%" class="vtable">
|
267
|
<?php if (!is_subsystem_dirty('rebootreq')): ?>
|
268
|
<?php if (!is_subsystem_dirty('firmware')): ?>
|
269
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>" />
|
270
|
<br/>
|
271
|
<?php printf(gettext('Click "Enable firmware upload" to begin.'),$g['firmware_update_text']);?>
|
272
|
<br/>
|
273
|
<?php else: ?>
|
274
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>" />
|
275
|
</td>
|
276
|
</tr>
|
277
|
<tr>
|
278
|
<td width="22%" valign="baseline" class="vncell"> </td>
|
279
|
<td width="78%" class="vtable">
|
280
|
<?php
|
281
|
if ($g['platform'] == "nanobsd")
|
282
|
$type = "*.img.gz";
|
283
|
else
|
284
|
$type = "*.tgz";
|
285
|
?>
|
286
|
<strong><?=gettext("Firmware image file ($type):");?> </strong>
|
287
|
<input name="ulfile" type="file" class="formfld" />
|
288
|
<br />
|
289
|
<?php
|
290
|
if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
|
291
|
if($g['platform'] == "pfSense") {
|
292
|
echo gettext("Please select kernel type") , ": ";
|
293
|
echo "<select name='kerneltype'>";
|
294
|
foreach($kerneltypes as $kerntype => $kerndescr) {
|
295
|
echo "<option value='{$kerntype}'>{$kerndescr}</option>";
|
296
|
}
|
297
|
echo "</select>";
|
298
|
echo "<br/>";
|
299
|
}
|
300
|
}
|
301
|
?>
|
302
|
<?php if ($g['hidebackupbeforeupgrade'] === false): ?>
|
303
|
<input type="checkbox" name='backupbeforeupgrade' id='backupbeforeupgrade' /> <?=gettext("Perform full backup prior to upgrade");?>
|
304
|
<br/>
|
305
|
<?php endif; ?>
|
306
|
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>" />
|
307
|
<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
|
308
|
<?php endif; else: ?>
|
309
|
<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
|
310
|
<?php endif; ?>
|
311
|
</td>
|
312
|
</tr>
|
313
|
<tr>
|
314
|
<td width="22%" valign="top"> </td>
|
315
|
<td width="78%">
|
316
|
<?php if (is_subsystem_dirty('firmware')): ?>
|
317
|
<span class="vexpl">
|
318
|
<span class="red">
|
319
|
<strong>
|
320
|
<?=gettext("Warning:");?><br/>
|
321
|
</strong>
|
322
|
</span>
|
323
|
<?=gettext("DO NOT abort the firmware upgrade once it " .
|
324
|
"has started. The firewall will reboot automatically after " .
|
325
|
"storing the new firmware. The configuration will be maintained.");?>
|
326
|
</span>
|
327
|
<?php endif; ?>
|
328
|
</td></tr>
|
329
|
</table>
|
330
|
</div>
|
331
|
</td></tr>
|
332
|
</table>
|
333
|
|
334
|
<?php endif; endif; ?>
|
335
|
<?php include("fend.inc"); ?>
|
336
|
</form>
|
337
|
</body>
|
338
|
</html>
|