Project

General

Profile

Download (11 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
##|+PRIV
35
##|*IDENT=page-system-firmware-manualupdate
36
##|*NAME=System: Firmware: Manual Update page
37
##|*DESCR=Allow access to the 'System: Firmware: Manual Update' page.
38
##|*MATCH=system_firmware.php*
39
##|-PRIV
40

    
41
$d_isfwfile = 1;
42
require_once("guiconfig.inc");
43

    
44
$curcfg = $config['system']['firmware'];
45

    
46
require_once("xmlrpc_client.inc");
47

    
48
/* Allow additional execution time 0 = no limit. */
49
ini_set('max_execution_time', '9999');
50
ini_set('max_input_time', '9999');
51

    
52
function file_upload_error_message($error_code) {
53
    switch ($error_code) {
54
        case UPLOAD_ERR_INI_SIZE:
55
            return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
56
        case UPLOAD_ERR_FORM_SIZE:
57
            return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
58
        case UPLOAD_ERR_PARTIAL:
59
            return 'The uploaded file was only partially uploaded';
60
        case UPLOAD_ERR_NO_FILE:
61
            return 'No file was uploaded';
62
        case UPLOAD_ERR_NO_TMP_DIR:
63
            return 'Missing a temporary folder';
64
        case UPLOAD_ERR_CANT_WRITE:
65
            return 'Failed to write file to disk';
66
        case UPLOAD_ERR_EXTENSION:
67
            return 'File upload stopped by extension';
68
        default:
69
            return 'Unknown upload error';
70
    }
71
}
72

    
73
/* if upgrade in progress, alert user */
74
if(is_subsystem_dirty('firmwarelock')) {
75
	$pgtitle = array("System","Firmware","Manual Update");
76
	include("head.inc");
77
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
78
	include("fbegin.inc");
79
	echo "<div>\n";
80
	print_info_box("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'>");
81
	echo "</div>\n";
82
	include("fend.inc");
83
	echo "</body>";
84
	echo "</html>";
85
	exit;
86
}
87

    
88
if($_POST['kerneltype']) {
89
	if($_POST['kerneltype'] == "single") 
90
		system("touch /boot/kernel/pfsense_kernel.txt");
91
	else 
92
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
93
}
94

    
95
/* Handle manual upgrade */
96
if ($_POST && !is_subsystem_dirty('firmwarelock')) {
97
	
98
	unset($input_errors);
99
	unset($sig_warning);
100

    
101
	if (stristr($_POST['Submit'], "Enable"))
102
		$mode = "enable";
103
	else if (stristr($_POST['Submit'], "Disable"))
104
		$mode = "disable";
105
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
106
		$mode = "upgrade";
107
	else if ($_POST['sig_no']) {
108
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
109
				unlink("{$g['upload_path']}/firmware.tgz");
110
	}
111
	if ($mode) {
112
		if ($mode == "enable") {
113
			conf_mount_rw();
114
			mark_subsystem_dirty('firmware');
115
		} else if ($mode == "disable") {
116
			conf_mount_ro();
117
			clear_subsystem_dirty('firmware');
118
		} else if ($mode == "upgrade") {
119
			if ($_FILES['ulfile']['error'])
120
			    $errortext = "(" . file_upload_error_message($_FILES['ulfile']['error']) . ")";
121
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
122
				/* verify firmware image(s) */
123
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
124
					$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
125
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
126
					/* probably out of memory for the MFS */
127
					$input_errors[] = "Image upload failed (out of memory?)";
128
					mwexec("/etc/rc.firmware disable");
129
					clear_subsystem_dirty('firmware');
130
				} else {
131
					/* move the image so PHP won't delete it */
132
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
133

    
134
					/* check digital signature */
135
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
136

    
137
					if ($sigchk == 1)
138
						$sig_warning = "The digital signature on this image is invalid.";
139
					else if ($sigchk == 2)
140
						$sig_warning = "This image is not digitally signed.";
141
					else if (($sigchk == 3) || ($sigchk == 4))
142
						$sig_warning = "There has been an error verifying the signature on this image.";
143

    
144
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
145
						$input_errors[] = "The image file is corrupt.";
146
						unlink("{$g['upload_path']}/firmware.tgz");
147
					}
148
				}
149
			}
150

    
151
			run_plugins("/usr/local/pkg/firmware_upgrade");
152

    
153
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
154
            if (!$input_errors && !is_subsystem_dirty('firmwarelock') && (!$sig_warning || $_POST['sig_override'])) {
155
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
156
                            /* fire up the update script in the background */
157
							mark_subsystem_dirty('firmwarelock');
158
                            $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
159
							if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
160
								mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
161
							else if(stristr($_FILES['ulfile']['name'],"bdiff"))
162
                            	mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
163
							else 
164
								mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
165
                    } else {
166
                            $savemsg = "Firmware image missing or other error, please try again {$errortext}.";
167
                    }
168
            }
169
		}
170
	}
171
}
172

    
173
$pgtitle = array("Diagnostics","Firmware");
174
include("head.inc");
175

    
176
?>
177
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">	
178
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
179
<?php
180
	/* Construct an upload_id for this session */
181
	$upload_id = "up". $_SESSION['Username'];
182
?>
183
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $upload_id;?>" /> 
184
<?php include("fbegin.inc"); ?>
185
<?php if ($input_errors) print_input_errors($input_errors); ?>
186
<?php if ($savemsg) print_info_box($savemsg); ?>
187
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
188
<?php if ($sig_warning && !$input_errors): ?>
189
<?php
190
	$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
191
		"is not an official/supported image and may lead to unexpected behavior or security " .
192
		"compromises. Only install images that come from sources that you trust, and make sure ".
193
		"that the image has not been tampered with.<br><br>".
194
		"Do you want to install this image anyway (on your own risk)?";
195
print_info_box($sig_warning);
196
if(stristr($_FILES['ulfile']['name'],"nanobsd"))
197
	echo "<input type='hidden' name='isnano' id='isnano' value='yes'>\n";
198
?>
199
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
200
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
201
<?php else: ?>
202
<?php if (!is_subsystem_dirty('firmwarelock')): ?>
203
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
204
		<tr>
205
			<td>
206
<?php
207
	$tab_array = array();
208
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
209
	$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
210
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
211
	display_top_tabs($tab_array);
212
?>
213
			</td>
214
		</tr>
215
		<tr>
216
			<td>
217
				<div id="mainarea">
218
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
219
                	<tr>
220
		 				<td colspan="2" class="listtopic">Invoke <?=$g['product_name']?> Manual Upgrade</td>
221
					</tr>
222
					<tr>
223
		  				<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
224
                  		<td width="78%" class="vtable">
225
						<p>
226
							Click &quot;Enable firmware
227
							upload&quot; below, then choose the image file (<?=$g['firmware_update_text'];?>)
228
							to be uploaded.
229
							<br>
230
							Click &quot;Upgrade firmware&quot;
231
							to start the upgrade process.
232
						</p>
233
						<?php if (!is_subsystem_dirty('rebootreq')): ?>
234
						<?php if (!is_subsystem_dirty('firmware')): ?>
235
							<input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
236
						<?php else: ?>
237
				  			<input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
238
							<br><br>
239
							<strong>Firmware image file: </strong>&nbsp;
240
							<input name="ulfile" type="file" class="formfld">
241
							<br><br>
242
							<?php
243
						  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
244
						  			if($g['platform'] == "pfSense") { 
245
										echo "Please select kernel type: ";
246
										echo "<select name='kerneltype'>";
247
										echo "<option value='SMP'>Multiprocessor kernel</option>";
248
										echo "<option value='single'>Uniprocessor kernel</option>";
249
										echo "<option value='wrap'>Embedded kernel</option>";
250
										echo "<option value='Developers'>Developers kernel</option>";
251
										echo "</select>";
252
										echo "<br><br>";
253
									}
254
								}
255
							?>
256
							<?php
257
								/*
258
								<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;">
259
								*/
260
							?>
261
							<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
262
						<?php endif; else: ?>
263
							<strong>You must reboot the system before you can upgrade the firmware.</strong>
264
						<?php endif; ?>
265
					</td>
266
				</td>
267
			</tr>
268
			<tr>
269
				<td width="22%" valign="top">&nbsp;</td>
270
				<td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
271
				</strong></span>DO NOT abort the firmware upgrade once it
272
				has started. The firewall will reboot automatically after
273
				storing the new firmware. The configuration will be maintained.</span></td>
274
			</table>
275
		</div>
276
	</tr>
277
</table>
278

    
279
<?php endif; endif; ?>
280
<?php include("fend.inc"); ?>
281
</body>
282
</html>
(179-179/218)