Project

General

Profile

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

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

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

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

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

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

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

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

    
53
/* Handle manual upgrade */
54
if ($_POST && !file_exists($d_firmwarelock_path)) {
55

    
56
	unset($input_errors);
57
	unset($sig_warning);
58

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

    
92
					/* check digital signature */
93
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
94

    
95
					if ($sigchk == 1)
96
						$sig_warning = "The digital signature on this image is invalid.";
97
					else if ($sigchk == 2)
98
						$sig_warning = "This image is not digitally signed.";
99
					else if (($sigchk == 3) || ($sigchk == 4))
100
						$sig_warning = "There has been an error verifying the signature on this image.";
101

    
102
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
103
						$input_errors[] = "The image file is corrupt.";
104
						unlink("{$g['tmp_path']}/firmware.tgz");
105
					}
106
				}
107
			}
108

    
109
                        /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
110
                        if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
111
                                if (file_exists("{$g['tmp_path']}/firmware.tgz")) {
112
                                        /* fire up the update script in the background */
113
                                        touch($d_firmwarelock_path);
114
                                        $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
115
                                        mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
116
                                } else {
117
                                        $savemsg = "Firmware image missing or other error, please try again.";
118
                                }
119
                        }
120
		}
121
	}
122
}
123

    
124
/* upload progress bar id */
125
$id = rand() . '.' . time();
126
$mth = ini_get('upload_progress_meter.store_method');
127
$dir = ini_get('upload_progress_meter.file.filename_template');
128

    
129
$pgtitle = "System: Firmware: Manual Update";
130
include("head.inc");
131

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

    
214
</form>
215
<?php endif; endif; ?>
216
<?php include("fend.inc"); ?>
217
</body>
218
</html>
(120-120/153)