Project

General

Profile

Download (12.2 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 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 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 0e88de0c Phil Davis
	if ($g['platform'] == "nanobsd") {
63
		if (stristr($ul_name, "nanobsd")) {
64 7475fc0b Scott Ullrich
			return true;
65 0e88de0c Phil Davis
		} else {
66 4b805dbc Renato Botelho
			return false;
67 0e88de0c Phil Davis
		}
68 7475fc0b Scott Ullrich
	}
69 e6d5af4b Ermal
	$_gb = exec("/usr/bin/tar xzf $filename -C /tmp/ etc/platform");
70
	unset($_gb);
71 0e88de0c Phil Davis
	if (!file_exists("/tmp/etc/platform")) {
72 fe38f1da Scott Ullrich
		return false;
73 0e88de0c Phil Davis
	}
74 e6d5af4b Ermal
	$upgrade_is_for_platform = trim(file_get_contents("/tmp/etc/platform", " \n\t\r"));
75
	if ($g['platform'] == $upgrade_is_for_platform) {
76
		@unlink("/tmp/etc/platform");
77 f0394a03 Scott Ullrich
		return true;
78
	}
79
	return false;
80
}
81
82 cdd3238d Scott Ullrich
function file_upload_error_message($error_code) {
83 4b805dbc Renato Botelho
	switch ($error_code) {
84 0e88de0c Phil Davis
		case UPLOAD_ERR_INI_SIZE:
85
			return gettext('The uploaded file exceeds the upload_max_filesize directive in php.ini');
86
		case UPLOAD_ERR_FORM_SIZE:
87
			return gettext('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form');
88
		case UPLOAD_ERR_PARTIAL:
89
			return gettext('The uploaded file was only partially uploaded');
90
		case UPLOAD_ERR_NO_FILE:
91
			return gettext('No file was uploaded');
92
		case UPLOAD_ERR_NO_TMP_DIR:
93
			return gettext('Missing a temporary folder');
94
		case UPLOAD_ERR_CANT_WRITE:
95
			return gettext('Failed to write file to disk');
96
		case UPLOAD_ERR_EXTENSION:
97
			return gettext('File upload stopped by extension');
98
		default:
99
			return gettext('Unknown upload error');
100 4b805dbc Renato Botelho
	}
101 cdd3238d Scott Ullrich
}
102
103 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
104 0e88de0c Phil Davis
if (is_subsystem_dirty('firmwarelock')) {
105
	$pgtitle = array(gettext("System"), gettext("Firmware"), gettext("Manual Update"));
106 8b7c81d7 Scott Ullrich
	include("head.inc");
107
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
108
	include("fbegin.inc");
109
	echo "<div>\n";
110 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>");
111 8b7c81d7 Scott Ullrich
	echo "</div>\n";
112
	include("fend.inc");
113
	echo "</body>";
114
	echo "</html>";
115
	exit;
116
}
117
118 0e88de0c Phil Davis
if ($_POST['backupbeforeupgrade']) {
119 b2a67b55 Scott Ullrich
	touch("/tmp/perform_full_backup.txt");
120 0e88de0c Phil Davis
}
121 b2a67b55 Scott Ullrich
122 aa08f46b Bill Marquette
/* Handle manual upgrade */
123 a368a026 Ermal Lu?i
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
124 4b805dbc Renato Botelho
125 580182e2 Colin Smith
	unset($input_errors);
126
	unset($sig_warning);
127
128 0e88de0c Phil Davis
	if (stristr($_POST['Submit'], gettext("Enable"))) {
129 580182e2 Colin Smith
		$mode = "enable";
130 0e88de0c Phil Davis
	} else if (stristr($_POST['Submit'], gettext("Disable"))) {
131 580182e2 Colin Smith
		$mode = "disable";
132 0e88de0c Phil Davis
	} else if (stristr($_POST['Submit'], gettext("Upgrade")) || $_POST['sig_override']) {
133 580182e2 Colin Smith
		$mode = "upgrade";
134 0e88de0c Phil Davis
	} else if ($_POST['sig_no']) {
135
		if (file_exists("{$g['upload_path']}/firmware.tgz")) {
136
			unlink("{$g['upload_path']}/firmware.tgz");
137
		}
138 580182e2 Colin Smith
	}
139
	if ($mode) {
140
		if ($mode == "enable") {
141 b6f67235 Scott Ullrich
			conf_mount_rw();
142 a368a026 Ermal Lu?i
			mark_subsystem_dirty('firmware');
143 580182e2 Colin Smith
		} else if ($mode == "disable") {
144 b6f67235 Scott Ullrich
			conf_mount_ro();
145 a368a026 Ermal Lu?i
			clear_subsystem_dirty('firmware');
146 580182e2 Colin Smith
		} else if ($mode == "upgrade") {
147 0e88de0c Phil Davis
			if ($_FILES['ulfile']['error']) {
148 4b805dbc Renato Botelho
				$errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
149 0e88de0c Phil Davis
			}
150 580182e2 Colin Smith
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
151
				/* verify firmware image(s) */
152 0e88de0c Phil Davis
				if (file_is_for_platform($_FILES['ulfile']['tmp_name'], $_FILES['ulfile']['name']) == false && !$_POST['sig_override']) {
153 33a2693c Chris Buechler
					$input_errors[] = gettext("The uploaded image file is not for this platform.");
154 0e88de0c Phil Davis
				} else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
155 580182e2 Colin Smith
					/* probably out of memory for the MFS */
156 1b4f376d Vinicius Coque
					$input_errors[] = gettext("Image upload failed (out of memory?)");
157 0d64af59 Ermal Lu?i
					mwexec("/etc/rc.firmware disable");
158 a368a026 Ermal Lu?i
					clear_subsystem_dirty('firmware');
159 580182e2 Colin Smith
				} else {
160
					/* move the image so PHP won't delete it */
161 1ef7b568 Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
162 580182e2 Colin Smith
163
					/* check digital signature */
164 1ef7b568 Scott Ullrich
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
165 580182e2 Colin Smith
166 0e88de0c Phil Davis
					if ($sigchk == 1) {
167 1b4f376d Vinicius Coque
						$sig_warning = gettext("The digital signature on this image is invalid.");
168 0e88de0c Phil Davis
					} else if ($sigchk == 2 && !isset($config['system']['firmware']['allowinvalidsig'])) {
169 1b4f376d Vinicius Coque
						$sig_warning = gettext("This image is not digitally signed.");
170 0e88de0c Phil Davis
					} else if (($sigchk >= 3)) {
171 1b4f376d Vinicius Coque
						$sig_warning = gettext("There has been an error verifying the signature on this image.");
172 0e88de0c Phil Davis
					}
173 580182e2 Colin Smith
174 709f48f0 Scott Ullrich
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
175 1b4f376d Vinicius Coque
						$input_errors[] = gettext("The image file is corrupt.");
176 1ef7b568 Scott Ullrich
						unlink("{$g['upload_path']}/firmware.tgz");
177 580182e2 Colin Smith
					}
178
				}
179
			}
180
181 1834f481 Scott Ullrich
			run_plugins("/usr/local/pkg/firmware_upgrade");
182
183 e6d5af4b Ermal
			/* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
184
			if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
185
				if (file_exists("{$g['upload_path']}/firmware.tgz")) {
186
					/* fire up the update script in the background */
187
					mark_subsystem_dirty('firmwarelock');
188
					$savemsg = gettext("The firmware is now being updated. The firewall will reboot automatically.");
189 0e88de0c Phil Davis
					if (stristr($_FILES['ulfile']['name'], "nanobsd") or $_POST['isnano'] == "yes") {
190 e6d5af4b Ermal
						mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
191 0e88de0c Phil Davis
					} else if (stristr($_FILES['ulfile']['name'], "bdiff")) {
192 e6d5af4b Ermal
						mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
193 6c07db48 Phil Davis
					} else {
194 0e88de0c Phil Davis
						if ($g['platform'] == "nanobsd") {
195 e6d5af4b Ermal
							$whichone = "pfSenseNanoBSDupgrade";
196 0e88de0c Phil Davis
						} else {
197 e6d5af4b Ermal
							$whichone = "pfSenseupgrade";
198 0e88de0c Phil Davis
						}
199 e6d5af4b Ermal
						mwexec_bg("/etc/rc.firmware {$whichone} {$g['upload_path']}/firmware.tgz");
200
						unset($whichone);
201
					}
202 0e88de0c Phil Davis
				} else {
203
					$savemsg = sprintf(gettext("Firmware image missing or other error, please try again %s."), $errortext);
204
				}
205 e6d5af4b Ermal
			}
206 580182e2 Colin Smith
		}
207
	}
208 5b237745 Scott Ullrich
}
209 e2fa4962 Scott Ullrich
210 0e88de0c Phil Davis
$pgtitle = array(gettext("System"), gettext("Firmware"));
211 52380979 Scott Ullrich
include("head.inc");
212
213 5b237745 Scott Ullrich
?>
214 4b805dbc Renato Botelho
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
215 afc04d58 Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
216
<?php
217
	/* Construct an upload_id for this session */
218 0e88de0c Phil Davis
	if (!session_id()) {
219 4111fcf5 Ermal
		$upload_id = uniqid();
220 0e88de0c Phil Davis
	} else {
221 4111fcf5 Ermal
		$upload_id = session_id();
222 0e88de0c Phil Davis
	}
223 afc04d58 Scott Ullrich
?>
224 4b805dbc Renato Botelho
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" />
225 580182e2 Colin Smith
<?php include("fbegin.inc"); ?>
226
<?php if ($input_errors) print_input_errors($input_errors); ?>
227 1ef7b568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
228 580182e2 Colin Smith
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
229 4668f9f7 Scott Ullrich
<?php
230 0e88de0c Phil Davis
	if ($sig_warning && !$input_errors):
231
		$sig_warning = "<strong>" . $sig_warning . "</strong><br />" . gettext("This means that the image you uploaded " .
232
			"is not an official/supported image and may lead to unexpected behavior or security " .
233
			"compromises. Only install images that come from sources that you trust, and make sure " .
234
			"that the image has not been tampered with.") . "<br /><br />" .
235
			gettext("Do you want to install this image anyway (on your own risk)?");
236
		print_info_box($sig_warning);
237
		if (stristr($_FILES['ulfile']['name'], "nanobsd")) {
238
			echo "<input type='hidden' name='isnano' id='isnano' value='yes' />\n";
239
		}
240 5b237745 Scott Ullrich
?>
241 02559d7d Colin Fleming
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" <?=gettext("Yes");?> " />
242
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" <?=gettext("No"); ?> " />
243 0e88de0c Phil Davis
<?php
244
	else:
245
		if (!is_subsystem_dirty('firmwarelock')):
246
?>
247 02559d7d Colin Fleming
	<table width="100%" border="0" cellpadding="0" cellspacing="0" summary="firmware">
248 77a89fb6 Scott Ullrich
		<tr>
249
			<td>
250 4820d297 Scott Ullrich
<?php
251 0e88de0c Phil Davis
			$tab_array = array();
252
			$tab_array[] = array(gettext("Manual Update"), true, "system_firmware.php");
253
			$tab_array[] = array(gettext("Auto Update"), false, "system_firmware_check.php");
254
			$tab_array[] = array(gettext("Updater Settings"), false, "system_firmware_settings.php");
255
			if ($g['hidedownloadbackup'] == false) {
256
				$tab_array[] = array(gettext("Restore Full Backup"), false, "system_firmware_restorefullbackup.php");
257
			}
258
			display_top_tabs($tab_array);
259 4820d297 Scott Ullrich
?>
260 77a89fb6 Scott Ullrich
			</td>
261 580182e2 Colin Smith
		</tr>
262 77a89fb6 Scott Ullrich
		<tr>
263
			<td>
264
				<div id="mainarea">
265 0e88de0c Phil Davis
				<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area">
266 4b805dbc Renato Botelho
					<tr>
267 6c07db48 Phil Davis
						<td colspan="2" class="listtopic"><?=gettext("Invoke") ." ". $g['product_name'] . " " . gettext("Manual Upgrade"); ?></td>
268 77a89fb6 Scott Ullrich
					</tr>
269
					<tr>
270 4b805dbc Renato Botelho
						<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
271
						<td width="78%" class="vtable">
272 0e88de0c Phil Davis
<?php
273
			if (!is_subsystem_dirty('rebootreq')):
274
				if (!is_subsystem_dirty('firmware')):
275
?>
276
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Enable firmware upload");?>" />
277
							<br />
278
							<?php printf(gettext('Click "Enable firmware upload" to begin.'), $g['firmware_update_text']);?>
279
							<br />
280
<?php
281
				else:
282
?>
283 02559d7d Colin Fleming
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Disable firmware upload");?>" />
284 0e88de0c Phil Davis
						</td>
285 e40d415a Scott Ullrich
					</tr>
286
					<tr>
287 4b805dbc Renato Botelho
						<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
288
						<td width="78%" class="vtable">
289
							<?php
290 0e88de0c Phil Davis
								if ($g['platform'] == "nanobsd") {
291 4b805dbc Renato Botelho
									$type = "*.img.gz";
292 0e88de0c Phil Davis
								} else {
293 4b805dbc Renato Botelho
									$type = "*.tgz";
294 0e88de0c Phil Davis
								}
295 4b805dbc Renato Botelho
							?>
296 e40d415a Scott Ullrich
							<strong><?=gettext("Firmware image file ($type):");?> </strong>
297 02559d7d Colin Fleming
							<input name="ulfile" type="file" class="formfld" />
298
							<br />
299 9beebb5e Renato Botelho
							<?php if ($g['hidebackupbeforeupgrade'] === false): ?>
300 02559d7d Colin Fleming
							<input type="checkbox" name='backupbeforeupgrade' id='backupbeforeupgrade' /> <?=gettext("Perform full backup prior to upgrade");?>
301 8cd558b6 ayvis
							<br />
302 9beebb5e Renato Botelho
							<?php endif; ?>
303 02559d7d Colin Fleming
							<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Upgrade firmware");?>" />
304 e40d415a Scott Ullrich
							<?=gettext('Click "Upgrade firmware" to start the upgrade process.');?>
305 0e88de0c Phil Davis
<?php
306
				endif;
307
			else:
308
?>
309 1b4f376d Vinicius Coque
							<strong><?=gettext("You must reboot the system before you can upgrade the firmware.");?></strong>
310 0e88de0c Phil Davis
<?php
311
			endif;
312
?>
313
						</td>
314
					</tr>
315
					<tr>
316
						<td width="22%" valign="top">&nbsp;</td>
317
						<td width="78%">
318 09b964a2 Scott Ullrich
						<?php if (is_subsystem_dirty('firmware')): ?>
319 0e88de0c Phil Davis
							<span class="vexpl">
320
								<span class="red">
321
									<strong>
322
										<?=gettext("Warning:");?><br />
323
									</strong>
324
								</span>
325
								<?=gettext("DO NOT abort the firmware upgrade once it " .
326
									"has started. The firewall will reboot automatically after " .
327
									"storing the new firmware. The configuration will be maintained.");?>
328
							</span>
329 09b964a2 Scott Ullrich
						<?php endif; ?>
330 0e88de0c Phil Davis
						</td>
331
					</tr>
332
				</table>
333
				</div>
334
			</td>
335
		</tr>
336
	</table>
337 afc04d58 Scott Ullrich
338 0e88de0c Phil Davis
<?php
339
		endif;
340
	endif;
341
?>
342 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
343 02559d7d Colin Fleming
</form>
344 5b237745 Scott Ullrich
</body>
345
</html>