Project

General

Profile

Download (9.73 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

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

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

    
47

    
48
require_once("xmlrpc_client.inc");
49

    
50
/* Allow additional execution time 0 = no limit. */
51
ini_set('max_execution_time', '3600');
52
ini_set('max_input_time', '3600');
53

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

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

    
76
/* Handle manual upgrade */
77
if ($_POST && !file_exists($d_firmwarelock_path)) {
78

    
79
	unset($input_errors);
80
	unset($sig_warning);
81

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

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

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

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

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

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

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

    
157
?>
158
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
159
<?php include("fbegin.inc"); ?>
160
<?php if ($input_errors) print_input_errors($input_errors); ?>
161
<?php if ($savemsg) print_info_box($savemsg); ?>
162
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
163
<?php if ($sig_warning && !$input_errors): ?>
164
<form action="system_firmware.php" method="post">
165
<?php
166
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
167
	"is not an official/supported image and may lead to unexpected behavior or security " .
168
	"compromises. Only install images that come from sources that you trust, and make sure ".
169
	"that the image has not been tampered with.<br><br>".
170
	"Do you want to install this image anyway (on your own risk)?";
171
print_info_box($sig_warning);
172
?>
173
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
174
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
175
</form>
176
<?php else: ?>
177
            <?php if (!file_exists($d_firmwarelock_path)): ?>
178
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
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
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
199
                  <td width="78%" class="vtable">
200
            <p>Click &quot;Enable firmware
201
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
202
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
203
              to start the upgrade process.</p>
204
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
205
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
206
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
207
				  <?php else: ?>
208
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
209
                    <br><br>
210
					<strong>Firmware image file: </strong>&nbsp;
211
					<input name="ulfile" type="file" class="formfld">
212
                    <br><br>
213
					  <?php
214
				  		if(!file_exists("/boot/kernel/pfsense_kernel.txt")) {
215
				  			if($g['platform'] == "pfSense") { 
216
								echo "Please select kernel type: ";
217
								echo "<select name='kerneltype'>";
218
								echo "<option value='SMP'>Multiprocessor kernel</option>";
219
								echo "<option value='single'>Uniprocessor kernel</option>";
220
								echo "<option value='wrap'>Embedded kernel</option>";
221
								echo "<option value='Developers'>Developers kernel</option>";
222
								echo "</select>";
223
								echo "<br><br>";
224
							}
225
						}
226
					  ?>
227
		    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
228
				  <?php endif; else: ?>
229
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
230
				  <?php endif; ?>
231
                  </td>
232
		</td>
233
                </tr>
234
                <tr>
235
                  <td width="22%" valign="top">&nbsp;</td>
236
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
237
                    </strong></span>DO NOT abort the firmware upgrade once it
238
                    has started. The firewall will reboot automatically after
239
                    storing the new firmware. The configuration will be maintained.</span></td>
240
              </table>
241
		</div>
242
		</tr>
243
		</td>
244
</table>
245

    
246
</form>
247
<?php endif; endif; ?>
248
<?php include("fend.inc"); ?>
249
</body>
250
</html>
(171-171/209)