Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:
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
require_once("globals.inc");
47
require_once("guiconfig.inc");
48

    
49
$curcfg = $config['system']['firmware'];
50

    
51
require_once("xmlrpc_client.inc");
52

    
53
/* Allow additional execution time 0 = no limit. */
54
ini_set('max_execution_time', '9999');
55
ini_set('max_input_time', '9999');
56

    
57
function file_is_for_platform($filename, $ul_name) {
58
	global $g;
59
	if($g['platform'] == "nanobsd") {
60
		if(stristr($ul_name, "nanobsd"))
61
			return true;
62
		else
63
			return false;		
64
	}
65
	exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
66
	if(!file_exists("/tmp/etc/platform")) 
67
		return false;
68
	$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform"));
69
	if($g['platform'] == $upgrade_is_for_platform) {
70
		unlink("/tmp/etc/platform");
71
		return true;
72
	}
73
	return false;
74
}
75

    
76
function file_upload_error_message($error_code) {
77
    switch ($error_code) {
78
        case UPLOAD_ERR_INI_SIZE:
79
            return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
80
        case UPLOAD_ERR_FORM_SIZE:
81
            return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
82
        case UPLOAD_ERR_PARTIAL:
83
            return gettext('The uploaded file was only partially uploaded');
84
        case UPLOAD_ERR_NO_FILE:
85
            return gettext('No file was uploaded');
86
        case UPLOAD_ERR_NO_TMP_DIR:
87
            return gettext('Missing a temporary folder');
88
        case UPLOAD_ERR_CANT_WRITE:
89
            return gettext('Failed to write file to disk');
90
        case UPLOAD_ERR_EXTENSION:
91
            return gettext('File upload stopped by extension');
92
        default:
93
            return gettext('Unknown upload error');
94
    }
95
}
96

    
97
/* if upgrade in progress, alert user */
98
if(is_subsystem_dirty('firmwarelock')) {
99
	$pgtitle = array(gettext("System"),gettext("Firmware"),gettext("Manual Update"));
100
	include("head.inc");
101
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
102
	include("fbegin.inc");
103
	echo "<div>\n";
104
	print_info_box(gettext("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'>");
105
	echo "</div>\n";
106
	include("fend.inc");
107
	echo "</body>";
108
	echo "</html>";
109
	exit;
110
}
111

    
112
if($_POST['kerneltype']) {
113
	if($_POST['kerneltype'] == "single") 
114
		system("touch /boot/kernel/pfsense_kernel.txt");
115
	else 
116
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
117
}
118

    
119
/* Handle manual upgrade */
120
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
121
	
122
	unset($input_errors);
123
	unset($sig_warning);
124

    
125
	if (stristr($_POST['Submit'], gettext("Enable")))
126
		$mode = "enable";
127
	else if (stristr($_POST['Submit'], gettext("Disable")))
128
		$mode = "disable";
129
	else if (stristr($_POST['Submit'], gettext("Upgrade")) || $_POST['sig_override'])
130
		$mode = "upgrade";
131
	else if ($_POST['sig_no']) {
132
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
133
				unlink("{$g['upload_path']}/firmware.tgz");
134
	}
135
	if ($mode) {
136
		if ($mode == "enable") {
137
			conf_mount_rw();
138
			mark_subsystem_dirty('firmware');
139
		} else if ($mode == "disable") {
140
			conf_mount_ro();
141
			clear_subsystem_dirty('firmware');
142
		} else if ($mode == "upgrade") {
143
			if ($_FILES['ulfile']['error'])
144
			    $errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
145
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
146
				/* verify firmware image(s) */
147
				if (file_is_for_platform($_FILES['ulfile']['tmp_name'], $_FILES['ulfile']['name']) == false && !$_POST['sig_override'])
148
					$input_errors[] = gettext("The uploaded image file is not for this platform") . " ({$g['platform']})";
149
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
150
					/* probably out of memory for the MFS */
151
					$input_errors[] = gettext("Image upload failed (out of memory?)");
152
					mwexec("/etc/rc.firmware disable");
153
					clear_subsystem_dirty('firmware');
154
				} else {
155
					/* move the image so PHP won't delete it */
156
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
157

    
158
					/* check digital signature */
159
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
160

    
161
					if ($sigchk == 1)
162
						$sig_warning = gettext("The digital signature on this image is invalid.");
163
					else if ($sigchk == 2 && !isset($config['system']['firmware']['allowinvalidsig']))
164
						$sig_warning = gettext("This image is not digitally signed.");
165
					else if (($sigchk >= 3))
166
						$sig_warning = gettext("There has been an error verifying the signature on this image.");
167

    
168
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
169
						$input_errors[] = gettext("The image file is corrupt.");
170
						unlink("{$g['upload_path']}/firmware.tgz");
171
					}
172
				}
173
			}
174

    
175
			run_plugins("/usr/local/pkg/firmware_upgrade");
176

    
177
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
178
            if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
179
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
180
                            /* fire up the update script in the background */
181
							mark_subsystem_dirty('firmwarelock');
182
                            $savemsg = gettext("The firmware is now being updated. The firewall will reboot automatically.");
183
							if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
184
								mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
185
							else if(stristr($_FILES['ulfile']['name'],"bdiff"))
186
                            	mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
187
							else 
188
								mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
189
                    } else {
190
                            $savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."),$errortext);
191
                    }
192
            }
193
		}
194
	}
195
}
196

    
197
$pgtitle = array(gettext("System"),gettext("Firmware"));
198
include("head.inc");
199

    
200
?>
201
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">	
202
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
203
<?php
204
	/* Construct an upload_id for this session */
205
	$upload_id = "up". $_SESSION['Username'];
206
?>
207
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" /> 
208
<?php include("fbegin.inc"); ?>
209
<?php if ($input_errors) print_input_errors($input_errors); ?>
210
<?php if ($savemsg) print_info_box($savemsg); ?>
211
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
212
<?php if ($sig_warning && !$input_errors): ?>
213
<?php
214
	$sig_warning = "<strong>" . $sig_warning . "</strong><br>" . gettext("This means that the image you uploaded " .
215
		"is not an official/supported image and may lead to unexpected behavior or security " .
216
		"compromises. Only install images that come from sources that you trust, and make sure ".
217
		"that the image has not been tampered with.") . "<br><br>".
218
		gettext("Do you want to install this image anyway (on your own risk)?");
219
print_info_box($sig_warning);
220
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
221
	echo "<input type='hidden' name='isnano' id='isnano' value='yes'>\n";
222
?>
223
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" <?=gettext("Yes");?> ">
224
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" <?=gettext("No"); ?> ">
225
<?php else: ?>
226
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
227
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
228
		<tr>
229
			<td>
230
<?php
231
	$tab_array = array();
232
	$tab_array[0] = array(gettext("Manual Update"), true, "system_firmware.php");
233
	$tab_array[1] = array(gettext("Auto Update"), false, "system_firmware_check.php");
234
	$tab_array[2] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
235
	display_top_tabs($tab_array);
236
?>
237
			</td>
238
		</tr>
239
		<tr>
240
			<td>
241
				<div id="mainarea">
242
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
243
                	<tr>
244
						<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] ." ".  gettext("Manual Upgrade"); ?></td>
245
					</tr>
246
					<tr>
247
		  				<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
248
                  		<td width="78%" class="vtable">
249
						<p>
250
							<?php printf(gettext('Click "Enable firmware '.
251
							'upload" below, then choose the image file (%s) '.
252
							'to be uploaded.'),$g['firmware_update_text']);?>
253
							<br>
254
							<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
255
						</p>
256
						<?php if (!is_subsystem_dirty('rebootreq')): ?>
257
						<?php if (!is_subsystem_dirty('firmware')): ?>
258
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>">
259
						<?php else: ?>
260
				  			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>">
261
							<br><br>
262
							<strong><?=gettext("Firmware image file");?>: </strong>&nbsp;
263
							<input name="ulfile" type="file" class="formfld">
264
							<br><br>
265
							<?php if ($g['platform'] == "nanobsd"): ?>
266
							<b><?=gettext("NOTE: You must upload a .img.gz image, not an uncompressed image!");?></b>
267
							<?php else: ?>
268
							<b><?=gettext("NOTE: You must upload a .tgz image, not an uncompressed image!");?></b>
269
							<?php endif; ?>
270
							<br><br>
271
							<?php
272
						  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
273
						  			if($g['platform'] == "pfSense") { 
274
										echo gettext("Please select kernel type") , ": ";
275
										echo "<select name='kerneltype'>";
276
										echo "<option value='SMP'>" . gettext("Multiprocessor kernel") . "</option>";
277
										echo "<option value='single'>". gettext("Uniprocessor kernel") . "</option>";
278
										echo "<option value='wrap'>" . gettext("Embedded kernel") . "</option>";
279
										echo "<option value='Developers'>" . gettext("Developers kernel") . "</option>";
280
										echo "</select>";
281
										echo "<br><br>";
282
									}
283
								}
284
							?>
285
							<?php
286
								/*
287
								<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware" onClick="window.open('upload_progress.php?upload_id=<?=$upload_id?>','UploadMeter','width=370,height=115', true); return true;">
288
								*/
289
							?>
290
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>">
291
						<?php endif; else: ?>
292
							<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
293
						<?php endif; ?>
294
					</td>
295
				</td>
296
			</tr>
297
			<tr>
298
				<td width="22%" valign="top">&nbsp;</td>
299
				<td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Warning");?>:<br>
300
				</strong></span><?=gettext("DO NOT abort the firmware upgrade once it " .
301
				"has started. The firewall will reboot automatically after " .
302
				"storing the new firmware. The configuration will be maintained.");?></span></td>
303
			</table>
304
		</div>
305
	</tr>
306
</table>
307

    
308
<?php endif; endif; ?>
309
<?php include("fend.inc"); ?>
310
</body>
311
</html>
(181-181/221)