Project

General

Profile

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

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

    
74
/* Handle manual upgrade */
75
if ($_POST && !file_exists($d_firmwarelock_path)) {
76
	
77
	unset($input_errors);
78
	unset($sig_warning);
79

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

    
115
					/* check digital signature */
116
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
117

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

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

    
132
			run_plugins("/usr/local/pkg/firmware_upgrade");
133

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

    
152
$pgtitle = array("Diagnostics","Firmware");
153
include("head.inc");
154

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

    
256
<?php endif; endif; ?>
257
<?php include("fend.inc"); ?>
258
</body>
259
</html>
(171-171/210)