Project

General

Profile

Download (9.8 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
	
13
	originally part of m0n0wall (http://m0n0.ch/wall)
14

    
15
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
16
	All rights reserved.
17

    
18
	Redistribution and use in source and binary forms, with or without
19
	modification, are permitted provided that the following conditions are met:
20

    
21
	1. Redistributions of source code must retain the above copyright notice,
22
	   this list of conditions and the following disclaimer.
23

    
24
	2. Redistributions in binary form must reproduce the above copyright
25
	   notice, this list of conditions and the following disclaimer in the
26
	   documentation and/or other materials provided with the distribution.
27

    
28
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
29
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
30
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
32
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37
	POSSIBILITY OF SUCH DAMAGE.
38
*/
39

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

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

    
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
/* if upgrade in progress, alert user */
53
if(file_exists($d_firmwarelock_path)) {
54
	$pgtitle = "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
	system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
69
}
70

    
71
/* Handle manual upgrade */
72
if ($_POST && !file_exists($d_firmwarelock_path)) {
73

    
74
	unset($input_errors);
75
	unset($sig_warning);
76

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

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

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

    
120
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
121
						$input_errors[] = "The image file is corrupt.";
122
						unlink("{$g['upload_path']}/firmware.tgz");
123
					}
124
				}
125
			}
126
			
127
			run_plugins("/usr/local/pkg/firmware_upgrade");
128
			
129
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
130
            if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
131
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
132
                            /* fire up the update script in the background */
133
                            touch($d_firmwarelock_path);
134
                            $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
135
							if(stristr($_FILES['ulfile']['name'],"nanobsd") or $_POST['isnano'] == "yes")
136
								mwexec_bg("/etc/rc.firmware pfSenseNanoBSDupgrade {$g['upload_path']}/firmware.tgz");
137
							else if(stristr($_FILES['ulfile']['name'],"bdiff"))
138
                            	mwexec_bg("/etc/rc.firmware delta_update {$g['upload_path']}/firmware.tgz");
139
							else 
140
								mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
141
                    } else {
142
                            $savemsg = "Firmware image missing or other error, please try again.";
143
                    }
144
            }
145
		}
146
	}
147
}
148

    
149
$pgtitle = "System: Firmware: Manual Update";
150
include("head.inc");
151

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

    
244
</form>
245
<?php endif; endif; ?>
246
<?php include("fend.inc"); ?>
247
</body>
248
</html>
(141-141/175)