Project

General

Profile

Download (9.18 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	system_firmware.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6

    
7
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9

    
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12

    
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15

    
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19

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

    
32
$d_isfwfile = 1;
33
require_once("guiconfig.inc");
34
require_once("xmlrpc_client.inc");
35

    
36
/* if upgrade in progress, alert user */
37
if(file_exists($d_firmwarelock_path)) {
38
	$pgtitle = array("System","Firmware","Manual Update");
39
	include("head.inc");
40
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
41
	include("fbegin.inc");
42
	echo "<div>\n";
43
	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'>");
44
	echo "</div>\n";
45
	include("fend.inc");
46
	echo "</body>";
47
	echo "</html>";
48
	exit;
49
}
50

    
51
if($_POST['kerneltype']) {
52
	if($_POST['kerneltype'] == "single") 
53
		system("touch /boot/kernel/pfsense_kernel.txt");
54
	else 
55
		system("echo {$_POST['kerneltype']} > /boot/kernel/pfsense_kernel.txt");
56
}
57

    
58
/* Handle manual upgrade */
59
if ($_POST && !file_exists($d_firmwarelock_path)) {
60

    
61
	unset($input_errors);
62
	unset($sig_warning);
63

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

    
99
					/* check digital signature */
100
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
101

    
102
					if ($sigchk == 1)
103
						$sig_warning = "The digital signature on this image is invalid.";
104
					else if ($sigchk == 2)
105
						$sig_warning = "This image is not digitally signed.";
106
					else if (($sigchk == 3) || ($sigchk == 4))
107
						$sig_warning = "There has been an error verifying the signature on this image.";
108

    
109
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
110
						$input_errors[] = "The image file is corrupt.";
111
						unlink("{$g['upload_path']}/firmware.tgz");
112
					}
113
				}
114
			}
115

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

    
134
include("head.inc");
135

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

    
225
</form>
226
<?php endif; endif; ?>
227
<?php include("fend.inc"); ?>
228
</body>
229
</html>
(147-147/189)