Project

General

Profile

Download (9.47 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
$d_isfwfile = 1;
35
require_once("guiconfig.inc");
36

    
37
$curcfg = $config['system']['firmware'];
38

    
39

    
40
require_once("xmlrpc_client.inc");
41

    
42
/* Allow additional execution time 0 = no limit. */
43
ini_set('max_execution_time', '3600');
44
ini_set('max_input_time', '3600');
45

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

    
61
if($_POST['kerneltype']) {
62
	if($_POST['kerneltype'] == "single") 
63
		system("touch /boot/kernel/pfsense_kernel.txt");
64
	else 
65
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
66
}
67

    
68
/* Handle manual upgrade */
69
if ($_POST && !file_exists($d_firmwarelock_path)) {
70

    
71
	unset($input_errors);
72
	unset($sig_warning);
73

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

    
109
					/* check digital signature */
110
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
111

    
112
					if ($sigchk == 1)
113
						$sig_warning = "The digital signature on this image is invalid.";
114
					else if ($sigchk == 2)
115
						$sig_warning = "This image is not digitally signed.";
116
					else if (($sigchk == 3) || ($sigchk == 4))
117
						$sig_warning = "There has been an error verifying the signature on this image.";
118

    
119
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
120
						$input_errors[] = "The image file is corrupt.";
121
						unlink("{$g['upload_path']}/firmware.tgz");
122
					}
123
				}
124
			}
125

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

    
144
$pgtitle = array("Diagnostics","Firmware");
145
include("head.inc");
146

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

    
236
</form>
237
<?php endif; endif; ?>
238
<?php include("fend.inc"); ?>
239
</body>
240
</html>
(150-150/197)