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