Project

General

Profile

Download (8.73 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("guiconfig.inc");
35

    
36
/* Handle auto upgrade */
37
if($_POST) {
38
	if (stristr($_POST['autoupgrade'], "Auto")) {
39
		auto_upgrade();
40
		$savemsg = "pfSense is now auto upgrading.  The firewall will automatically reboot if it succeeds.";
41
	}
42
}
43

    
44
/* Handle manual upgrade */
45
if ($_POST && !file_exists($d_firmwarelock_path)) {
46

    
47
	unset($input_errors);
48
	unset($sig_warning);
49

    
50
	if (stristr($_POST['Submit'], "Enable"))
51
		$mode = "enable";
52
	else if (stristr($_POST['Submit'], "Disable"))
53
		$mode = "disable";
54
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
55
		$mode = "upgrade";
56
	else if ($_POST['sig_no']) {
57
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
58
				unlink("{$g['tmp_path']}/firmware.tgz");
59
    }
60

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

    
84
					/* check digital signature */
85
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
86

    
87
					if ($sigchk == 1)
88
						$sig_warning = "The digital signature on this image is invalid.";
89
					else if ($sigchk == 2)
90
						$sig_warning = "This image is not digitally signed.";
91
					else if (($sigchk == 3) || ($sigchk == 4))
92
						$sig_warning = "There has been an error verifying the signature on this image.";
93

    
94
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
95
						$input_errors[] = "The image file is corrupt.";
96
						unlink("{$g['tmp_path']}/firmware.tgz");
97
					}
98
				}
99
			}
100

    
101
			if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
102
				/* fire up the update script in the background */
103
				touch($d_firmwarelock_path);
104
				exec_rc_script_async("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
105

    
106
				$savemsg = "The firmware is now being installed. The firewall will reboot automatically.";
107
			}
108
		}
109
	}
110
} else {
111
	/* Only check firmware version if we're setup to go against pfsense.org  and user wants us to */
112
	if (!isset($config['system']['disablefirmwarecheck'])) {
113
		$fwinfo = check_firmware_version();
114
		if(is_null($fwinfo)) {
115
			$fwinfo = "Unable to determine if a new firmware version is available.";
116
		}
117
	}
118
}
119

    
120
/* upload progress bar id */
121
$id = rand() . '.' . time();
122
$mth = ini_get('upload_progress_meter.store_method');
123
$dir = ini_get('upload_progress_meter.file.filename_template');
124

    
125
?>
126
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
127
<html>
128
<head>
129
<title><?=gentitle("System: Firmware");?></title>
130
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
131
<link href="gui.css" rel="stylesheet" type="text/css">
132
</head>
133

    
134
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
135
<!--
136
generated new UPLOAD_IDENTIFIER = <?=$id?>
137
php-config.upload_progress_meter.store_method = <?=$mth?>
138
php-config.upload_progress_meter.file.filename_template = <?=$dir?>
139
-->
140
<?php include("fbegin.inc"); ?>
141
<p class="pgtitle">System: Firmware</p>
142
<?php if ($input_errors) print_input_errors($input_errors); ?>
143
<?php if ($savemsg) print_info_box($savemsg); ?>
144
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
145
<?php if (!in_array($g['platform'], $fwupplatforms)): ?>
146
<p><strong>Firmware uploading is not supported on this platform.</strong></p>
147
<?php elseif ($sig_warning && !$input_errors): ?>
148
<form action="system_firmware.php" method="post">
149
<?php
150
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
151
	"is not an official/supported image and may lead to unexpected behavior or security " .
152
	"compromises. Only install images that come from sources that you trust, and make sure ".
153
	"that the image has not been tampered with.<br><br>".
154
	"Do you want to install this image anyway (on your own risk)?";
155
print_info_box($sig_warning);
156
?>
157
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
158
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
159
</form>
160
<?php else: ?>
161
            <?php if (!file_exists($d_firmwarelock_path)): ?>
162
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
163
<?php if($savemsg == ""): ?>
164

    
165
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
166
		<tr>
167
		 <td colspan="2" class="listtopic">Invoke pfSense Auto Upgrade</td>
168
		</tr>
169
		<tr>
170
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
171
		  <td width="78%" class="vtable">
172
		  <p> Click this button to automatically upgrade pfSense in the background.  This may take a while.<br>
173
		  <br>
174
		  <input name="autoupgrade" type="submit" class="formbtn" value="Invoke Auto Upgrade">
175
		</tr>
176
		<tr><td>&nbsp;</td></tr>
177
                <tr>
178
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
179
		</tr>
180
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
181
                  <td width="78%" class="vtable">
182
            <p>Click &quot;Enable firmware
183
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
184
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
185
              to start the upgrade process.</p>
186
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
187
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
188
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
189
				  <?php else: ?>
190
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
191
                    <br><br>
192
					<strong>Firmware image file: </strong>&nbsp;
193
					<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?=$id?>">
194
					<input name="ulfile" type="file" class="formfld">
195
                    <br><br>
196

    
197
                    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware" onClick="window.open('progress.php?UPLOAD_IDENTIFIER=<?=$id?>','UploadMeter','width=400,height=200', true); return true; ">
198
				  <?php endif; else: ?>
199
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
200
				  <?php endif; ?>
201
                  </td>
202
                </tr>
203
                <tr>
204
                  <td width="22%" valign="top">&nbsp;</td>
205
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
206
                    </strong></span>DO NOT abort the firmware upgrade once it
207
                    has started. The firewall will reboot automatically after
208
                    storing the new firmware. The configuration will be maintained.</span></td>
209
                </tr>
210

    
211
              </table>
212
<?php endif ?>
213

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