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