Project

General

Profile

Download (10.1 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', '3600');
50
ini_set('max_input_time', '3600');
51

    
52
/* Construct an upload_id for this session */
53
$upload_id = $_SERVER['REQUEST_TIME'] . $_SESSION['Username'];
54

    
55
/* if upgrade in progress, alert user */
56
if(file_exists($d_firmwarelock_path)) {
57
	$pgtitle = array("System","Firmware","Manual Update");
58
	include("head.inc");
59
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
60
	include("fbegin.inc");
61
	echo "<div>\n";
62
	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'>");
63
	echo "</div>\n";
64
	include("fend.inc");
65
	echo "</body>";
66
	echo "</html>";
67
	exit;
68
}
69

    
70
if($_POST['kerneltype']) {
71
	if($_POST['kerneltype'] == "single") 
72
		system("touch /boot/kernel/pfsense_kernel.txt");
73
	else 
74
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
75
}
76

    
77
/* Handle manual upgrade */
78
if ($_POST && !file_exists($d_firmwarelock_path)) {
79
	
80
	unset($input_errors);
81
	unset($sig_warning);
82

    
83
	if (stristr($_POST['Submit'], "Enable"))
84
		$mode = "enable";
85
	else if (stristr($_POST['Submit'], "Disable"))
86
		$mode = "disable";
87
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
88
		$mode = "upgrade";
89
	else if ($_POST['sig_no']) {
90
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
91
				unlink("{$g['upload_path']}/firmware.tgz");
92
	}
93
	if ($mode) {
94
		if ($mode == "enable") {
95
			exec_rc_script("/etc/rc.firmware enable");
96
			conf_mount_rw();
97
			touch($d_fwupenabled_path);
98
		} else if ($mode == "disable") {
99
			exec_rc_script("/etc/rc.firmware disable");
100
			conf_mount_ro();
101
			if (file_exists($d_fwupenabled_path))
102
				unlink($d_fwupenabled_path);
103
		} else if ($mode == "upgrade") {
104
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
105
				/* verify firmware image(s) */
106
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
107
					$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
108
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
109
					/* probably out of memory for the MFS */
110
					$input_errors[] = "Image upload failed (out of memory?)";
111
					exec_rc_script("/etc/rc.firmware disable");
112
					if (file_exists($d_fwupenabled_path))
113
						unlink($d_fwupenabled_path);
114
				} else {
115
					/* move the image so PHP won't delete it */
116
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
117

    
118
					/* check digital signature */
119
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
120

    
121
					if ($sigchk == 1)
122
						$sig_warning = "The digital signature on this image is invalid.";
123
					else if ($sigchk == 2)
124
						$sig_warning = "This image is not digitally signed.";
125
					else if (($sigchk == 3) || ($sigchk == 4))
126
						$sig_warning = "There has been an error verifying the signature on this image.";
127

    
128
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
129
						$input_errors[] = "The image file is corrupt.";
130
						unlink("{$g['upload_path']}/firmware.tgz");
131
					}
132
				}
133
			}
134

    
135
			run_plugins("/usr/local/pkg/firmware_upgrade");
136

    
137
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
138
            if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
139
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
140
                            /* fire up the update script in the background */
141
                            touch($d_firmwarelock_path);
142
                            $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
143
							if(stristr($_FILES['ulfile']['tmp_name'],"bdiff"))
144
                            	mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
145
							else 
146
								mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
147
                    } else {
148
                            $savemsg = "Firmware image missing or other error, please try again.";
149
                    }
150
            }
151
		}
152
	}
153
}
154

    
155
$pgtitle = array("Diagnostics","Firmware");
156
include("head.inc");
157

    
158
?>
159
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">	
160
<?php include("fbegin.inc"); ?>
161
<?php if ($input_errors) print_input_errors($input_errors); ?>
162
<?php if ($savemsg) print_info_box($savemsg); ?>
163
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
164
<?php if ($sig_warning && !$input_errors): ?>
165
<form action="system_firmware.php" method="post">
166
<?php
167
	$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
168
		"is not an official/supported image and may lead to unexpected behavior or security " .
169
		"compromises. Only install images that come from sources that you trust, and make sure ".
170
		"that the image has not been tampered with.<br><br>".
171
		"Do you want to install this image anyway (on your own risk)?";
172
print_info_box($sig_warning);
173
?>
174
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
175
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
176
</form>
177
<?php else: ?>
178
<?php if (!file_exists($d_firmwarelock_path)): ?>
179
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
180
		<tr>
181
			<td>
182
<?php
183
	$tab_array = array();
184
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
185
	$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
186
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
187
	display_top_tabs($tab_array);
188
?>
189
			</td>
190
		</tr>
191
		<tr>
192
			<td>
193
				<div id="mainarea">
194
					<table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
195
                	<tr>
196
		 				<td colspan="2" class="listtopic">Invoke <?=$g['product_name']?> Manual Upgrade</td>
197
					</tr>
198
					<tr>
199
		  				<td width="22%" valign="baseline" class="vncell">&nbsp;</td>
200
                  		<td width="78%" class="vtable">
201
						<p>
202
							Click &quot;Enable firmware
203
							upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
204
							to be uploaded.
205
							<br>
206
							Click &quot;Upgrade firmware&quot;
207
							to start the upgrade process.
208
						</p>
209
						<?php if (!file_exists($d_sysrebootreqd_path)): ?>
210
                   		<?php if (!file_exists($d_fwupenabled_path)): ?>
211
							<form action="system_firmware.php" method="post">	
212
                   			<input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
213
							</form>
214
						<?php else: ?>
215
							<form action="system_firmware.php" method="post">	
216
				  			<input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
217
							</form>
218
							<br><br>
219
							</form>
220
							<form action="system_firmware.php" method="post" enctype="multipart/form-data">
221
							<input type="hidden" name="APC_UPLOAD_PROGRESS" value="<?=$upload_id?>" />
222
							<strong>Firmware image file: </strong>&nbsp;
223
							<input name="ulfile" type="file" class="formfld">
224
							<br><br>
225
							<?php
226
						  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
227
						  			if($g['platform'] == "pfSense") { 
228
										echo "Please select kernel type: ";
229
										echo "<select name='kerneltype'>";
230
										echo "<option value='SMP'>Multiprocessor kernel</option>";
231
										echo "<option value='single'>Uniprocessor kernel</option>";
232
										echo "<option value='wrap'>Embedded kernel</option>";
233
										echo "<option value='Developers'>Developers kernel</option>";
234
										echo "</select>";
235
										echo "<br><br>";
236
									}
237
								}
238
							?>
239
							<input name="Submit" type="submit" class="formbtn" value="Upgrade firmware" onClick="window.open('progress.php?uploadid=<?=$upload_id?>','UploadMeter','width=370,height=115', true); return true;">
240
						<?php endif; else: ?>
241
							<strong>You must reboot the system before you can upgrade the firmware.</strong>
242
						<?php endif; ?>
243
					</td>
244
				</td>
245
			</tr>
246
			<tr>
247
				<td width="22%" valign="top">&nbsp;</td>
248
				<td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
249
				</strong></span>DO NOT abort the firmware upgrade once it
250
				has started. The firewall will reboot automatically after
251
				storing the new firmware. The configuration will be maintained.</span></td>
252
			</table>
253
		</div>
254
	</tr>
255
</table>
256
</form>
257
<?php endif; endif; ?>
258
<?php include("fend.inc"); ?>
259
</body>
260
</html>
(173-173/212)