Project

General

Profile

Download (12 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 29aef6c4 Jim Thompson
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
7 1cecfbf7 Scott Ullrich
	All rights reserved.
8 580182e2 Colin Smith
9 1cecfbf7 Scott Ullrich
	originally part of m0n0wall (http://m0n0.ch/wall)
10 580182e2 Colin Smith
	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 5b237745 Scott Ullrich
*/
34 1d333258 Scott Ullrich
/*
35 4b805dbc Renato Botelho
	pfSense_BUILDER_BINARIES:	/usr/bin/tar
36 1d333258 Scott Ullrich
	pfSense_MODULE:	firmware
37
*/
38 5b237745 Scott Ullrich
39 6b07c15a Matthew Grooms
##|+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 3958d63b Colin Smith
$d_isfwfile = 1;
47 7385a6b4 Scott Ullrich
$nocsrf = true;
48
49 f0394a03 Scott Ullrich
require_once("globals.inc");
50 c1605b35 Scott Ullrich
require_once("functions.inc");
51 6605faea Scott Ullrich
require_once("guiconfig.inc");
52 f03ed350 Ermal
require_once("xmlrpc_client.inc");
53 da55e467 Scott Ullrich
54
$curcfg = $config['system']['firmware'];
55
56 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
57 8999038a Scott Ullrich
ini_set('max_execution_time', '9999');
58
ini_set('max_input_time', '9999');
59 0045dfd1 Scott Ullrich
60 d2d86ca3 Scott Ullrich
function file_is_for_platform($filename, $ul_name) {
61 f0394a03 Scott Ullrich
	global $g;
62 3350a691 Scott Ullrich
	if($g['platform'] == "nanobsd") {
63 d2d86ca3 Scott Ullrich
		if(stristr($ul_name, "nanobsd"))
64 7475fc0b Scott Ullrich
			return true;
65
		else
66 4b805dbc Renato Botelho
			return false;
67 7475fc0b Scott Ullrich
	}
68 e6d5af4b Ermal
	$_gb = exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
69
	unset($_gb);
70 4b805dbc Renato Botelho
	if(!file_exists("/tmp/etc/platform"))
71 fe38f1da Scott Ullrich
		return false;
72 e6d5af4b Ermal
	$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform", " \n\t\r"));
73
	if ($g['platform'] == $upgrade_is_for_platform) {
74
		@unlink("/tmp/etc/platform");
75 f0394a03 Scott Ullrich
		return true;
76
	}
77
	return false;
78
}
79
80 cdd3238d Scott Ullrich
function file_upload_error_message($error_code) {
81 4b805dbc Renato Botelho
	switch ($error_code) {
82
	case UPLOAD_ERR_INI_SIZE:
83
		return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
84
	case UPLOAD_ERR_FORM_SIZE:
85
		return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
86
	case UPLOAD_ERR_PARTIAL:
87
		return gettext('The uploaded file was only partially uploaded');
88
	case UPLOAD_ERR_NO_FILE:
89
		return gettext('No file was uploaded');
90
	case UPLOAD_ERR_NO_TMP_DIR:
91
		return gettext('Missing a temporary folder');
92
	case UPLOAD_ERR_CANT_WRITE:
93
		return gettext('Failed to write file to disk');
94
	case UPLOAD_ERR_EXTENSION:
95
		return gettext('File upload stopped by extension');
96
	default:
97
		return gettext('Unknown upload error');
98
	}
99 cdd3238d Scott Ullrich
}
100
101 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
102 a368a026 Ermal Lu?i
if(is_subsystem_dirty('firmwarelock')) {
103 1b4f376d Vinicius Coque
	$pgtitle = array(gettext("System"),gettext("Firmware"),gettext("Manual Update"));
104 8b7c81d7 Scott Ullrich
	include("head.inc");
105
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
106
	include("fbegin.inc");
107
	echo "<div>\n";
108 02559d7d Colin Fleming
	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>");
109 8b7c81d7 Scott Ullrich
	echo "</div>\n";
110
	include("fend.inc");
111
	echo "</body>";
112
	echo "</html>";
113
	exit;
114
}
115
116 4b805dbc Renato Botelho
if($_POST['backupbeforeupgrade'])
117 b2a67b55 Scott Ullrich
	touch("/tmp/perform_full_backup.txt");
118
119 aa08f46b Bill Marquette
/* Handle manual upgrade */
120 a368a026 Ermal Lu?i
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
121 4b805dbc Renato Botelho
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 4b805dbc Renato Botelho
				$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 33a2693c Chris Buechler
					$input_errors[] = gettext("The uploaded image file is not for this 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 e6d5af4b Ermal
			/* 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
						if($g['platform'] == "nanobsd")
189
							$whichone = "pfSenseNanoBSDupgrade";
190
						else
191
							$whichone = "pfSenseupgrade";
192
						mwexec_bg("/etc/rc.firmware {$whichone} {$g['upload_path']}/firmware.tgz");
193
						unset($whichone);
194
					}
195
				} else
196
					$savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."),$errortext);
197
			}
198 580182e2 Colin Smith
		}
199
	}
200 5b237745 Scott Ullrich
}
201 e2fa4962 Scott Ullrich
202 3c446c66 Erik Fonnesbeck
$pgtitle = array(gettext("System"),gettext("Firmware"));
203 52380979 Scott Ullrich
include("head.inc");
204
205 5b237745 Scott Ullrich
?>
206 4b805dbc Renato Botelho
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
207 afc04d58 Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
208
<?php
209
	/* Construct an upload_id for this session */
210 4111fcf5 Ermal
	if (!session_id())
211
		$upload_id = uniqid();
212
	else
213
		$upload_id = session_id();
214 afc04d58 Scott Ullrich
?>
215 4b805dbc Renato Botelho
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" />
216 580182e2 Colin Smith
<?php include("fbegin.inc"); ?>
217
<?php if ($input_errors) print_input_errors($input_errors); ?>
218 1ef7b568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
219 580182e2 Colin Smith
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
220 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
221 4668f9f7 Scott Ullrich
<?php
222 8cd558b6 ayvis
	$sig_warning = "<strong>" . $sig_warning . "</strong><br />" . gettext("This means that the image you uploaded " .
223 77a89fb6 Scott Ullrich
		"is not an official/supported image and may lead to unexpected behavior or security " .
224
		"compromises. Only install images that come from sources that you trust, and make sure ".
225 8cd558b6 ayvis
		"that the image has not been tampered with.") . "<br /><br />".
226 1b4f376d Vinicius Coque
		gettext("Do you want to install this image anyway (on your own risk)?");
227 5b237745 Scott Ullrich
print_info_box($sig_warning);
228 bfed48a4 Scott Ullrich
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
229 02559d7d Colin Fleming
	echo "<input type='hidden' name='isnano' id='isnano' value='yes' />\n";
230 5b237745 Scott Ullrich
?>
231 02559d7d Colin Fleming
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" <?=gettext("Yes");?> " />
232
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" <?=gettext("No"); ?> " />
233 5b237745 Scott Ullrich
<?php else: ?>
234 a368a026 Ermal Lu?i
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
235 02559d7d Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firmware">
236 77a89fb6 Scott Ullrich
		<tr>
237
			<td>
238 4820d297 Scott Ullrich
<?php
239
	$tab_array = array();
240 3ff39566 Scott Ullrich
	$tab_array[] = array(gettext("Manual Update"), true, "system_firmware.php");
241
	$tab_array[] = array(gettext("Auto Update"), false, "system_firmware_check.php");
242
	$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
243
	if($g['hidedownloadbackup'] == false)
244
		$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
245 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
246
?>
247 77a89fb6 Scott Ullrich
			</td>
248 580182e2 Colin Smith
		</tr>
249 77a89fb6 Scott Ullrich
		<tr>
250
			<td>
251
				<div id="mainarea">
252 02559d7d Colin Fleming
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
253 4b805dbc Renato Botelho
					<tr>
254 a6d8feb6 Renato Botelho
						<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] ." ".  gettext("Manual Upgrade"); ?></td>
255 77a89fb6 Scott Ullrich
					</tr>
256
					<tr>
257 4b805dbc Renato Botelho
						<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
258
						<td width="78%" class="vtable">
259 a368a026 Ermal Lu?i
						<?php if (!is_subsystem_dirty('rebootreq')): ?>
260
						<?php if (!is_subsystem_dirty('firmware')): ?>
261 02559d7d Colin Fleming
						<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>" />
262 8cd558b6 ayvis
						<br />
263 68e14a6b Scott Ullrich
							<?php printf(gettext('Click "Enable firmware upload" to begin.'),$g['firmware_update_text']);?>
264 8cd558b6 ayvis
						<br />
265 77a89fb6 Scott Ullrich
						<?php else: ?>
266 02559d7d Colin Fleming
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>" />
267 e40d415a Scott Ullrich
					</td>
268
					</tr>
269
					<tr>
270 4b805dbc Renato Botelho
						<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
271
						<td width="78%" class="vtable">
272
							<?php
273
								if ($g['platform'] == "nanobsd")
274
									$type = "*.img.gz";
275 e40d415a Scott Ullrich
								else
276 4b805dbc Renato Botelho
									$type = "*.tgz";
277
							?>
278 e40d415a Scott Ullrich
							<strong><?=gettext("Firmware image file ($type):");?> </strong>
279 02559d7d Colin Fleming
							<input name="ulfile" type="file" class="formfld" />
280
							<br />
281 9beebb5e Renato Botelho
							<?php if ($g['hidebackupbeforeupgrade'] === false): ?>
282 02559d7d Colin Fleming
							<input type="checkbox" name='backupbeforeupgrade' id='backupbeforeupgrade' /> <?=gettext("Perform full backup prior to upgrade");?>
283 8cd558b6 ayvis
							<br />
284 9beebb5e Renato Botelho
							<?php endif; ?>
285 02559d7d Colin Fleming
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>" />
286 e40d415a Scott Ullrich
							<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
287 77a89fb6 Scott Ullrich
						<?php endif; else: ?>
288 1b4f376d Vinicius Coque
							<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
289 77a89fb6 Scott Ullrich
						<?php endif; ?>
290 0045dfd1 Scott Ullrich
				</td>
291 77a89fb6 Scott Ullrich
			</tr>
292
			<tr>
293
				<td width="22%" valign="top">&nbsp;</td>
294 e40d415a Scott Ullrich
				<td width="78%">
295 09b964a2 Scott Ullrich
						<?php if (is_subsystem_dirty('firmware')): ?>
296 e40d415a Scott Ullrich
					<span class="vexpl">
297
						<span class="red">
298
							<strong>
299 8cd558b6 ayvis
								<?=gettext("Warning:");?><br />
300 e40d415a Scott Ullrich
							</strong>
301
						</span>
302
						<?=gettext("DO NOT abort the firmware upgrade once it " .
303 4b805dbc Renato Botelho
								"has started. The firewall will reboot automatically after " .
304
								"storing the new firmware. The configuration will be maintained.");?>
305 e40d415a Scott Ullrich
					</span>
306 09b964a2 Scott Ullrich
						<?php endif; ?>
307 02559d7d Colin Fleming
				</td></tr>
308 77a89fb6 Scott Ullrich
			</table>
309 e12d98ea Bill Marquette
		</div>
310 02559d7d Colin Fleming
	</td></tr>
311 222494af Colin Smith
</table>
312 afc04d58 Scott Ullrich
313 03c64985 Scott Ullrich
<?php endif; endif; ?>
314 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
315 02559d7d Colin Fleming
</form>
316 5b237745 Scott Ullrich
</body>
317
</html>