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 7385a6b4 Scott Ullrich
$nocsrf = true;
47
48 f0394a03 Scott Ullrich
require_once("globals.inc");
49 6605faea Scott Ullrich
require_once("guiconfig.inc");
50 da55e467 Scott Ullrich
51
$curcfg = $config['system']['firmware'];
52
53 6605faea Scott Ullrich
require_once("xmlrpc_client.inc");
54 aa08f46b Bill Marquette
55 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
56 8999038a Scott Ullrich
ini_set('max_execution_time', '9999');
57
ini_set('max_input_time', '9999');
58 0045dfd1 Scott Ullrich
59 d2d86ca3 Scott Ullrich
function file_is_for_platform($filename, $ul_name) {
60 f0394a03 Scott Ullrich
	global $g;
61 3350a691 Scott Ullrich
	if($g['platform'] == "nanobsd") {
62 d2d86ca3 Scott Ullrich
		if(stristr($ul_name, "nanobsd"))
63 7475fc0b Scott Ullrich
			return true;
64
		else
65
			return false;		
66
	}
67 1d333258 Scott Ullrich
	exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
68 fe38f1da Scott Ullrich
	if(!file_exists("/tmp/etc/platform")) 
69
		return false;
70
	$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform"));
71 f0394a03 Scott Ullrich
	if($g['platform'] == $upgrade_is_for_platform) {
72 fb05887a Scott Ullrich
		unlink("/tmp/etc/platform");
73 f0394a03 Scott Ullrich
		return true;
74
	}
75
	return false;
76
}
77
78 cdd3238d Scott Ullrich
function file_upload_error_message($error_code) {
79
    switch ($error_code) {
80
        case UPLOAD_ERR_INI_SIZE:
81 1b4f376d Vinicius Coque
            return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
82 cdd3238d Scott Ullrich
        case UPLOAD_ERR_FORM_SIZE:
83 1b4f376d Vinicius Coque
            return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
84 cdd3238d Scott Ullrich
        case UPLOAD_ERR_PARTIAL:
85 1b4f376d Vinicius Coque
            return gettext('The uploaded file was only partially uploaded');
86 cdd3238d Scott Ullrich
        case UPLOAD_ERR_NO_FILE:
87 1b4f376d Vinicius Coque
            return gettext('No file was uploaded');
88 cdd3238d Scott Ullrich
        case UPLOAD_ERR_NO_TMP_DIR:
89 1b4f376d Vinicius Coque
            return gettext('Missing a temporary folder');
90 cdd3238d Scott Ullrich
        case UPLOAD_ERR_CANT_WRITE:
91 1b4f376d Vinicius Coque
            return gettext('Failed to write file to disk');
92 cdd3238d Scott Ullrich
        case UPLOAD_ERR_EXTENSION:
93 1b4f376d Vinicius Coque
            return gettext('File upload stopped by extension');
94 cdd3238d Scott Ullrich
        default:
95 1b4f376d Vinicius Coque
            return gettext('Unknown upload error');
96 cdd3238d Scott Ullrich
    }
97
}
98
99 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
100 a368a026 Ermal Lu?i
if(is_subsystem_dirty('firmwarelock')) {
101 1b4f376d Vinicius Coque
	$pgtitle = array(gettext("System"),gettext("Firmware"),gettext("Manual Update"));
102 8b7c81d7 Scott Ullrich
	include("head.inc");
103
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
104
	include("fbegin.inc");
105
	echo "<div>\n";
106 19e76a0b Scott Ullrich
	print_info_box(gettext("An upgrade is currently in progress.<p>The firewall will reboot when the operation is complete.") . "<p><img src='/themes/{$g['theme']}/images/icons/icon_fw-update.gif'>");
107 8b7c81d7 Scott Ullrich
	echo "</div>\n";
108
	include("fend.inc");
109
	echo "</body>";
110
	echo "</html>";
111
	exit;
112
}
113
114 afa829bb Scott Ullrich
if($_POST['kerneltype']) {
115
	if($_POST['kerneltype'] == "single") 
116
		system("touch /boot/kernel/pfsense_kernel.txt");
117
	else 
118
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
119
}
120
121 aa08f46b Bill Marquette
/* Handle manual upgrade */
122 a368a026 Ermal Lu?i
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
123 77a89fb6 Scott Ullrich
	
124 580182e2 Colin Smith
	unset($input_errors);
125
	unset($sig_warning);
126
127 4134b5e6 Carlos Eduardo Ramos
	if (stristr($_POST['Submit'], gettext("Enable")))
128 580182e2 Colin Smith
		$mode = "enable";
129 4134b5e6 Carlos Eduardo Ramos
	else if (stristr($_POST['Submit'], gettext("Disable")))
130 580182e2 Colin Smith
		$mode = "disable";
131 4134b5e6 Carlos Eduardo Ramos
	else if (stristr($_POST['Submit'], gettext("Upgrade")) || $_POST['sig_override'])
132 580182e2 Colin Smith
		$mode = "upgrade";
133
	else if ($_POST['sig_no']) {
134 709f48f0 Scott Ullrich
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
135
				unlink("{$g['upload_path']}/firmware.tgz");
136 580182e2 Colin Smith
	}
137
	if ($mode) {
138
		if ($mode == "enable") {
139 b6f67235 Scott Ullrich
			conf_mount_rw();
140 a368a026 Ermal Lu?i
			mark_subsystem_dirty('firmware');
141 580182e2 Colin Smith
		} else if ($mode == "disable") {
142 b6f67235 Scott Ullrich
			conf_mount_ro();
143 a368a026 Ermal Lu?i
			clear_subsystem_dirty('firmware');
144 580182e2 Colin Smith
		} else if ($mode == "upgrade") {
145 cdd3238d Scott Ullrich
			if ($_FILES['ulfile']['error'])
146
			    $errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
147 580182e2 Colin Smith
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
148
				/* verify firmware image(s) */
149 d2d86ca3 Scott Ullrich
				if (file_is_for_platform($_FILES['ulfile']['tmp_name'], $_FILES['ulfile']['name']) == false && !$_POST['sig_override'])
150 33a2693c Chris Buechler
					$input_errors[] = gettext("The uploaded image file is not for this platform.");
151 580182e2 Colin Smith
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
152
					/* probably out of memory for the MFS */
153 1b4f376d Vinicius Coque
					$input_errors[] = gettext("Image upload failed (out of memory?)");
154 0d64af59 Ermal Lu?i
					mwexec("/etc/rc.firmware disable");
155 a368a026 Ermal Lu?i
					clear_subsystem_dirty('firmware');
156 580182e2 Colin Smith
				} else {
157
					/* move the image so PHP won't delete it */
158 1ef7b568 Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
159 580182e2 Colin Smith
160
					/* check digital signature */
161 1ef7b568 Scott Ullrich
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
162 580182e2 Colin Smith
163
					if ($sigchk == 1)
164 1b4f376d Vinicius Coque
						$sig_warning = gettext("The digital signature on this image is invalid.");
165 a0116247 Ermal
					else if ($sigchk == 2 && !isset($config['system']['firmware']['allowinvalidsig']))
166 1b4f376d Vinicius Coque
						$sig_warning = gettext("This image is not digitally signed.");
167 a0116247 Ermal
					else if (($sigchk >= 3))
168 1b4f376d Vinicius Coque
						$sig_warning = gettext("There has been an error verifying the signature on this image.");
169 580182e2 Colin Smith
170 709f48f0 Scott Ullrich
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
171 1b4f376d Vinicius Coque
						$input_errors[] = gettext("The image file is corrupt.");
172 1ef7b568 Scott Ullrich
						unlink("{$g['upload_path']}/firmware.tgz");
173 580182e2 Colin Smith
					}
174
				}
175
			}
176
177 1834f481 Scott Ullrich
			run_plugins("/usr/local/pkg/firmware_upgrade");
178
179 1ef7b568 Scott Ullrich
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
180 a368a026 Ermal Lu?i
            if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
181 1ef7b568 Scott Ullrich
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
182
                            /* fire up the update script in the background */
183 14442033 Scott Ullrich
							mark_subsystem_dirty('firmwarelock');
184 1b4f376d Vinicius Coque
                            $savemsg = gettext("The firmware is now being updated. The firewall will reboot automatically.");
185 bfed48a4 Scott Ullrich
							if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
186 b2d15ced Scott Ullrich
								mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
187 69769bcc Scott Ullrich
							else if(stristr($_FILES['ulfile']['name'],"bdiff"))
188 e1aea2cd Scott Ullrich
                            	mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
189
							else 
190
								mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
191 1ef7b568 Scott Ullrich
                    } else {
192 1b4f376d Vinicius Coque
                            $savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."),$errortext);
193 1ef7b568 Scott Ullrich
                    }
194
            }
195 580182e2 Colin Smith
		}
196
	}
197 5b237745 Scott Ullrich
}
198 e2fa4962 Scott Ullrich
199 3c446c66 Erik Fonnesbeck
$pgtitle = array(gettext("System"),gettext("Firmware"));
200 52380979 Scott Ullrich
include("head.inc");
201
202 5b237745 Scott Ullrich
?>
203 0045dfd1 Scott Ullrich
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">	
204 afc04d58 Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
205
<?php
206
	/* Construct an upload_id for this session */
207
	$upload_id = "up". $_SESSION['Username'];
208
?>
209
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" /> 
210 580182e2 Colin Smith
<?php include("fbegin.inc"); ?>
211
<?php if ($input_errors) print_input_errors($input_errors); ?>
212 1ef7b568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
213 580182e2 Colin Smith
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
214 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
215 4668f9f7 Scott Ullrich
<?php
216 1b4f376d Vinicius Coque
	$sig_warning = "<strong>" . $sig_warning . "</strong><br>" . gettext("This means that the image you uploaded " .
217 77a89fb6 Scott Ullrich
		"is not an official/supported image and may lead to unexpected behavior or security " .
218
		"compromises. Only install images that come from sources that you trust, and make sure ".
219 1b4f376d Vinicius Coque
		"that the image has not been tampered with.") . "<br><br>".
220
		gettext("Do you want to install this image anyway (on your own risk)?");
221 5b237745 Scott Ullrich
print_info_box($sig_warning);
222 bfed48a4 Scott Ullrich
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
223
	echo "<input type='hidden' name='isnano' id='isnano' value='yes'>\n";
224 5b237745 Scott Ullrich
?>
225 4134b5e6 Carlos Eduardo Ramos
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" <?=gettext("Yes");?> ">
226
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" <?=gettext("No"); ?> ">
227 5b237745 Scott Ullrich
<?php else: ?>
228 a368a026 Ermal Lu?i
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
229 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
230 77a89fb6 Scott Ullrich
		<tr>
231
			<td>
232 4820d297 Scott Ullrich
<?php
233
	$tab_array = array();
234 1b4f376d Vinicius Coque
	$tab_array[0] = array(gettext("Manual Update"), true, "system_firmware.php");
235
	$tab_array[1] = array(gettext("Auto Update"), false, "system_firmware_check.php");
236
	$tab_array[2] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
237 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
238
?>
239 77a89fb6 Scott Ullrich
			</td>
240 580182e2 Colin Smith
		</tr>
241 77a89fb6 Scott Ullrich
		<tr>
242
			<td>
243
				<div id="mainarea">
244
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
245
                	<tr>
246 a6d8feb6 Renato Botelho
						<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] ." ".  gettext("Manual Upgrade"); ?></td>
247 77a89fb6 Scott Ullrich
					</tr>
248
					<tr>
249
		  				<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
250
                  		<td width="78%" class="vtable">
251
						<p>
252 4d473c89 Vinicius Coque
							<?php printf(gettext('Click "Enable firmware '.
253
							'upload" below, then choose the image file (%s) '.
254
							'to be uploaded.'),$g['firmware_update_text']);?>
255 77a89fb6 Scott Ullrich
							<br>
256 1b4f376d Vinicius Coque
							<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
257 77a89fb6 Scott Ullrich
						</p>
258 a368a026 Ermal Lu?i
						<?php if (!is_subsystem_dirty('rebootreq')): ?>
259
						<?php if (!is_subsystem_dirty('firmware')): ?>
260 1b4f376d Vinicius Coque
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>">
261 77a89fb6 Scott Ullrich
						<?php else: ?>
262 1b4f376d Vinicius Coque
				  			<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>">
263 afc04d58 Scott Ullrich
							<br><br>
264 ea53e38f Renato Botelho
							<strong><?=gettext("Firmware image file:");?> </strong>&nbsp;
265 77a89fb6 Scott Ullrich
							<input name="ulfile" type="file" class="formfld">
266
							<br><br>
267 07356178 jim-p
							<?php if ($g['platform'] == "nanobsd"): ?>
268 1b4f376d Vinicius Coque
							<b><?=gettext("NOTE: You must upload a .img.gz image, not an uncompressed image!");?></b>
269 07356178 jim-p
							<?php else: ?>
270 1b4f376d Vinicius Coque
							<b><?=gettext("NOTE: You must upload a .tgz image, not an uncompressed image!");?></b>
271 07356178 jim-p
							<?php endif; ?>
272 7ce55201 Scott Ullrich
							<br><br>
273 77a89fb6 Scott Ullrich
							<?php
274
						  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
275
						  			if($g['platform'] == "pfSense") { 
276 79eaddf4 Renato Botelho
										echo gettext("Please select kernel type") , ": ";
277 77a89fb6 Scott Ullrich
										echo "<select name='kerneltype'>";
278 1b4f376d Vinicius Coque
										echo "<option value='SMP'>" . gettext("Multiprocessor kernel") . "</option>";
279
										echo "<option value='single'>". gettext("Uniprocessor kernel") . "</option>";
280
										echo "<option value='wrap'>" . gettext("Embedded kernel") . "</option>";
281
										echo "<option value='Developers'>" . gettext("Developers kernel") . "</option>";
282 77a89fb6 Scott Ullrich
										echo "</select>";
283
										echo "<br><br>";
284
									}
285
								}
286
							?>
287 afc04d58 Scott Ullrich
							<?php
288
								/*
289
								<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;">
290
								*/
291
							?>
292 4134b5e6 Carlos Eduardo Ramos
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>">
293 77a89fb6 Scott Ullrich
						<?php endif; else: ?>
294 1b4f376d Vinicius Coque
							<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
295 77a89fb6 Scott Ullrich
						<?php endif; ?>
296
					</td>
297 0045dfd1 Scott Ullrich
				</td>
298 77a89fb6 Scott Ullrich
			</tr>
299
			<tr>
300
				<td width="22%" valign="top">&nbsp;</td>
301 ea53e38f Renato Botelho
				<td width="78%"><span class="vexpl"><span class="red"><strong><?=gettext("Warning:");?><br>
302 0e94685b Renato Botelho
				</strong></span><?=gettext("DO NOT abort the firmware upgrade once it " .
303
				"has started. The firewall will reboot automatically after " .
304
				"storing the new firmware. The configuration will be maintained.");?></span></td>
305 77a89fb6 Scott Ullrich
			</table>
306 e12d98ea Bill Marquette
		</div>
307 77a89fb6 Scott Ullrich
	</tr>
308 222494af Colin Smith
</table>
309 afc04d58 Scott Ullrich
310 03c64985 Scott Ullrich
<?php endif; endif; ?>
311 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
312
</body>
313
</html>