Project

General

Profile

Download (12.6 KB) Statistics
| Branch: | Tag: | Revision:
1 4668f9f7 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 580182e2 Colin Smith
	system_firmware.php
5 1cecfbf7 Scott Ullrich
	Copyright (C) 2008 Scott Ullrich <sullrich@gmail.com>
6
	All rights reserved.
7 580182e2 Colin Smith
8 1cecfbf7 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
9 580182e2 Colin Smith
	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 5b237745 Scott Ullrich
*/
33 1d333258 Scott Ullrich
/*
34
	pfSense_BUILDER_BINARIES:	/usr/bin/tar	
35
	pfSense_MODULE:	firmware
36
*/
37 5b237745 Scott Ullrich
38 6b07c15a Matthew Grooms
##|+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 3958d63b Colin Smith
$d_isfwfile = 1;
46 f0394a03 Scott Ullrich
require_once("globals.inc");
47 6605faea Scott Ullrich
require_once("guiconfig.inc");
48 da55e467 Scott Ullrich
49
$curcfg = $config['system']['firmware'];
50
51 6605faea Scott Ullrich
require_once("xmlrpc_client.inc");
52 aa08f46b Bill Marquette
53 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
54 8999038a Scott Ullrich
ini_set('max_execution_time', '9999');
55
ini_set('max_input_time', '9999');
56 0045dfd1 Scott Ullrich
57 d2d86ca3 Scott Ullrich
function file_is_for_platform($filename, $ul_name) {
58 f0394a03 Scott Ullrich
	global $g;
59 3350a691 Scott Ullrich
	if($g['platform'] == "nanobsd") {
60 d2d86ca3 Scott Ullrich
		if(stristr($ul_name, "nanobsd"))
61 7475fc0b Scott Ullrich
			return true;
62
		else
63
			return false;		
64
	}
65 1d333258 Scott Ullrich
	exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
66 fe38f1da Scott Ullrich
	if(!file_exists("/tmp/etc/platform")) 
67
		return false;
68
	$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform"));
69 f0394a03 Scott Ullrich
	if($g['platform'] == $upgrade_is_for_platform) {
70 fb05887a Scott Ullrich
		unlink("/tmp/etc/platform");
71 f0394a03 Scott Ullrich
		return true;
72
	}
73
	return false;
74
}
75
76 cdd3238d Scott Ullrich
function file_upload_error_message($error_code) {
77
    switch ($error_code) {
78
        case UPLOAD_ERR_INI_SIZE:
79 1b4f376d Vinicius Coque
            return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
80 cdd3238d Scott Ullrich
        case UPLOAD_ERR_FORM_SIZE:
81 1b4f376d Vinicius Coque
            return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
82 cdd3238d Scott Ullrich
        case UPLOAD_ERR_PARTIAL:
83 1b4f376d Vinicius Coque
            return gettext('The uploaded file was only partially uploaded');
84 cdd3238d Scott Ullrich
        case UPLOAD_ERR_NO_FILE:
85 1b4f376d Vinicius Coque
            return gettext('No file was uploaded');
86 cdd3238d Scott Ullrich
        case UPLOAD_ERR_NO_TMP_DIR:
87 1b4f376d Vinicius Coque
            return gettext('Missing a temporary folder');
88 cdd3238d Scott Ullrich
        case UPLOAD_ERR_CANT_WRITE:
89 1b4f376d Vinicius Coque
            return gettext('Failed to write file to disk');
90 cdd3238d Scott Ullrich
        case UPLOAD_ERR_EXTENSION:
91 1b4f376d Vinicius Coque
            return gettext('File upload stopped by extension');
92 cdd3238d Scott Ullrich
        default:
93 1b4f376d Vinicius Coque
            return gettext('Unknown upload error');
94 cdd3238d Scott Ullrich
    }
95
}
96
97 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
98 a368a026 Ermal Lu?i
if(is_subsystem_dirty('firmwarelock')) {
99 1b4f376d Vinicius Coque
	$pgtitle = array(gettext("System"),gettext("Firmware"),gettext("Manual Update"));
100 8b7c81d7 Scott Ullrich
	include("head.inc");
101
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
102
	include("fbegin.inc");
103
	echo "<div>\n";
104 1b4f376d Vinicius Coque
	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 8b7c81d7 Scott Ullrich
	echo "</div>\n";
106
	include("fend.inc");
107
	echo "</body>";
108
	echo "</html>";
109
	exit;
110
}
111
112 afa829bb Scott Ullrich
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 aa08f46b Bill Marquette
/* Handle manual upgrade */
120 a368a026 Ermal Lu?i
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
121 77a89fb6 Scott Ullrich
	
122 580182e2 Colin Smith
	unset($input_errors);
123
	unset($sig_warning);
124
125 4134b5e6 Carlos Eduardo Ramos
	if (stristr($_POST['Submit'], gettext("Enable")))
126 580182e2 Colin Smith
		$mode = "enable";
127 4134b5e6 Carlos Eduardo Ramos
	else if (stristr($_POST['Submit'], gettext("Disable")))
128 580182e2 Colin Smith
		$mode = "disable";
129 4134b5e6 Carlos Eduardo Ramos
	else if (stristr($_POST['Submit'], gettext("Upgrade")) || $_POST['sig_override'])
130 580182e2 Colin Smith
		$mode = "upgrade";
131
	else if ($_POST['sig_no']) {
132 709f48f0 Scott Ullrich
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
133
				unlink("{$g['upload_path']}/firmware.tgz");
134 580182e2 Colin Smith
	}
135
	if ($mode) {
136
		if ($mode == "enable") {
137 b6f67235 Scott Ullrich
			conf_mount_rw();
138 a368a026 Ermal Lu?i
			mark_subsystem_dirty('firmware');
139 580182e2 Colin Smith
		} else if ($mode == "disable") {
140 b6f67235 Scott Ullrich
			conf_mount_ro();
141 a368a026 Ermal Lu?i
			clear_subsystem_dirty('firmware');
142 580182e2 Colin Smith
		} else if ($mode == "upgrade") {
143 cdd3238d Scott Ullrich
			if ($_FILES['ulfile']['error'])
144
			    $errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
145 580182e2 Colin Smith
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
146
				/* verify firmware image(s) */
147 d2d86ca3 Scott Ullrich
				if (file_is_for_platform($_FILES['ulfile']['tmp_name'], $_FILES['ulfile']['name']) == false && !$_POST['sig_override'])
148 1b4f376d Vinicius Coque
					$input_errors[] = gettext("The uploaded image file is not for this platform") . " ({$g['platform']})";
149 580182e2 Colin Smith
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
150
					/* probably out of memory for the MFS */
151 1b4f376d Vinicius Coque
					$input_errors[] = gettext("Image upload failed (out of memory?)");
152 0d64af59 Ermal Lu?i
					mwexec("/etc/rc.firmware disable");
153 a368a026 Ermal Lu?i
					clear_subsystem_dirty('firmware');
154 580182e2 Colin Smith
				} else {
155
					/* move the image so PHP won't delete it */
156 1ef7b568 Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
157 580182e2 Colin Smith
158
					/* check digital signature */
159 1ef7b568 Scott Ullrich
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
160 580182e2 Colin Smith
161
					if ($sigchk == 1)
162 1b4f376d Vinicius Coque
						$sig_warning = gettext("The digital signature on this image is invalid.");
163 a0116247 Ermal
					else if ($sigchk == 2 && !isset($config['system']['firmware']['allowinvalidsig']))
164 1b4f376d Vinicius Coque
						$sig_warning = gettext("This image is not digitally signed.");
165 a0116247 Ermal
					else if (($sigchk >= 3))
166 1b4f376d Vinicius Coque
						$sig_warning = gettext("There has been an error verifying the signature on this image.");
167 580182e2 Colin Smith
168 709f48f0 Scott Ullrich
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
169 1b4f376d Vinicius Coque
						$input_errors[] = gettext("The image file is corrupt.");
170 1ef7b568 Scott Ullrich
						unlink("{$g['upload_path']}/firmware.tgz");
171 580182e2 Colin Smith
					}
172
				}
173
			}
174
175 1834f481 Scott Ullrich
			run_plugins("/usr/local/pkg/firmware_upgrade");
176
177 1ef7b568 Scott Ullrich
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
178 a368a026 Ermal Lu?i
            if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
179 1ef7b568 Scott Ullrich
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
180
                            /* fire up the update script in the background */
181 14442033 Scott Ullrich
							mark_subsystem_dirty('firmwarelock');
182 1b4f376d Vinicius Coque
                            $savemsg = gettext("The firmware is now being updated. The firewall will reboot automatically.");
183 bfed48a4 Scott Ullrich
							if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
184 b2d15ced Scott Ullrich
								mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
185 69769bcc Scott Ullrich
							else if(stristr($_FILES['ulfile']['name'],"bdiff"))
186 e1aea2cd Scott Ullrich
                            	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 1ef7b568 Scott Ullrich
                    } else {
190 1b4f376d Vinicius Coque
                            $savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."),$errortext);
191 1ef7b568 Scott Ullrich
                    }
192
            }
193 580182e2 Colin Smith
		}
194
	}
195 5b237745 Scott Ullrich
}
196 e2fa4962 Scott Ullrich
197 3c446c66 Erik Fonnesbeck
$pgtitle = array(gettext("System"),gettext("Firmware"));
198 52380979 Scott Ullrich
include("head.inc");
199
200 5b237745 Scott Ullrich
?>
201 0045dfd1 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">	
202 afc04d58 Scott Ullrich
<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 580182e2 Colin Smith
<?php include("fbegin.inc"); ?>
209
<?php if ($input_errors) print_input_errors($input_errors); ?>
210 1ef7b568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
211 580182e2 Colin Smith
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
212 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
213 4668f9f7 Scott Ullrich
<?php
214 1b4f376d Vinicius Coque
	$sig_warning = "<strong>" . $sig_warning . "</strong><br>" . gettext("This means that the image you uploaded " .
215 77a89fb6 Scott Ullrich
		"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 1b4f376d Vinicius Coque
		"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 5b237745 Scott Ullrich
print_info_box($sig_warning);
220 bfed48a4 Scott Ullrich
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
221
	echo "<input type='hidden' name='isnano' id='isnano' value='yes'>\n";
222 5b237745 Scott Ullrich
?>
223 4134b5e6 Carlos Eduardo Ramos
<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 5b237745 Scott Ullrich
<?php else: ?>
226 a368a026 Ermal Lu?i
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
227 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
228 77a89fb6 Scott Ullrich
		<tr>
229
			<td>
230 4820d297 Scott Ullrich
<?php
231
	$tab_array = array();
232 1b4f376d Vinicius Coque
	$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 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
236
?>
237 77a89fb6 Scott Ullrich
			</td>
238 580182e2 Colin Smith
		</tr>
239 77a89fb6 Scott Ullrich
		<tr>
240
			<td>
241
				<div id="mainarea">
242
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
243
                	<tr>
244 a6d8feb6 Renato Botelho
						<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] ." ".  gettext("Manual Upgrade"); ?></td>
245 77a89fb6 Scott Ullrich
					</tr>
246
					<tr>
247
		  				<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
248
                  		<td width="78%" class="vtable">
249
						<p>
250 4d473c89 Vinicius Coque
							<?php printf(gettext('Click "Enable firmware '.
251
							'upload" below, then choose the image file (%s) '.
252
							'to be uploaded.'),$g['firmware_update_text']);?>
253 77a89fb6 Scott Ullrich
							<br>
254 1b4f376d Vinicius Coque
							<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
255 77a89fb6 Scott Ullrich
						</p>
256 a368a026 Ermal Lu?i
						<?php if (!is_subsystem_dirty('rebootreq')): ?>
257
						<?php if (!is_subsystem_dirty('firmware')): ?>
258 1b4f376d Vinicius Coque
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>">
259 77a89fb6 Scott Ullrich
						<?php else: ?>
260 1b4f376d Vinicius Coque
				  			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>">
261 afc04d58 Scott Ullrich
							<br><br>
262 ea53e38f Renato Botelho
							<strong><?=gettext("Firmware image file:");?> </strong>&nbsp;
263 77a89fb6 Scott Ullrich
							<input name="ulfile" type="file" class="formfld">
264
							<br><br>
265 07356178 jim-p
							<?php if ($g['platform'] == "nanobsd"): ?>
266 1b4f376d Vinicius Coque
							<b><?=gettext("NOTE: You must upload a .img.gz image, not an uncompressed image!");?></b>
267 07356178 jim-p
							<?php else: ?>
268 1b4f376d Vinicius Coque
							<b><?=gettext("NOTE: You must upload a .tgz image, not an uncompressed image!");?></b>
269 07356178 jim-p
							<?php endif; ?>
270 7ce55201 Scott Ullrich
							<br><br>
271 77a89fb6 Scott Ullrich
							<?php
272
						  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
273
						  			if($g['platform'] == "pfSense") { 
274 79eaddf4 Renato Botelho
										echo gettext("Please select kernel type") , ": ";
275 77a89fb6 Scott Ullrich
										echo "<select name='kerneltype'>";
276 1b4f376d Vinicius Coque
										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 77a89fb6 Scott Ullrich
										echo "</select>";
281
										echo "<br><br>";
282
									}
283
								}
284
							?>
285 afc04d58 Scott Ullrich
							<?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 4134b5e6 Carlos Eduardo Ramos
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>">
291 77a89fb6 Scott Ullrich
						<?php endif; else: ?>
292 1b4f376d Vinicius Coque
							<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
293 77a89fb6 Scott Ullrich
						<?php endif; ?>
294
					</td>
295 0045dfd1 Scott Ullrich
				</td>
296 77a89fb6 Scott Ullrich
			</tr>
297
			<tr>
298
				<td width="22%" valign="top">&nbsp;</td>
299 ea53e38f Renato Botelho
				<td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Warning:");?><br>
300 0e94685b Renato Botelho
				</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 77a89fb6 Scott Ullrich
			</table>
304 e12d98ea Bill Marquette
		</div>
305 77a89fb6 Scott Ullrich
	</tr>
306 222494af Colin Smith
</table>
307 afc04d58 Scott Ullrich
308 03c64985 Scott Ullrich
<?php endif; endif; ?>
309 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
310
</body>
311
</html>