Project

General

Profile

Download (8.68 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 4668f9f7 Scott Ullrich
<?php
3 5b237745 Scott Ullrich
/*
4
	system_firmware.php
5
	part of m0n0wall (http://m0n0.ch/wall)
6 4668f9f7 Scott Ullrich
7 5b237745 Scott Ullrich
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
8
	All rights reserved.
9 4668f9f7 Scott Ullrich
10 5b237745 Scott Ullrich
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 4668f9f7 Scott Ullrich
13 5b237745 Scott Ullrich
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 4668f9f7 Scott Ullrich
16 5b237745 Scott Ullrich
	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 4668f9f7 Scott Ullrich
20 5b237745 Scott Ullrich
	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 4668f9f7 Scott Ullrich
$d_isfwfile = 1; require("guiconfig.inc");
33 5b237745 Scott Ullrich
34 18ff56f2 Scott Ullrich
if($_GET['autoupgrade'] <> "") {
35
    exec_rc_script_async("/etc/rc.firmware_auto");
36
    $savemsg = "pfSense is now auto upgrading.  The firewall will automatically reboot if it succeeds.";
37
}
38
39 5b237745 Scott Ullrich
/* checks with m0n0.ch to see if a newer firmware version is available;
40
   returns any HTML message it gets from the server */
41
function check_firmware_version() {
42
	global $g;
43 4668f9f7 Scott Ullrich
	$post = "platform=" . rawurlencode($g['platform']) .
44 5b237745 Scott Ullrich
		"&version=" . rawurlencode(trim(file_get_contents("/etc/version")));
45 4668f9f7 Scott Ullrich
46 643a50c3 Scott Ullrich
	$rfd = @fsockopen("pfSense", 80, $errno, $errstr, 3);
47 5b237745 Scott Ullrich
	if ($rfd) {
48 643a50c3 Scott Ullrich
		$hdr = "POST /pfSense/checkversion.php HTTP/1.0\r\n";
49 5b237745 Scott Ullrich
		$hdr .= "Content-Type: application/x-www-form-urlencoded\r\n";
50 6ab78253 Scott Ullrich
		$hdr .= "User-Agent: pfSense-webConfigurator/1.0\r\n";
51 5b237745 Scott Ullrich
		$hdr .= "Host: m0n0.ch\r\n";
52
		$hdr .= "Content-Length: " . strlen($post) . "\r\n\r\n";
53 4668f9f7 Scott Ullrich
54 5b237745 Scott Ullrich
		fwrite($rfd, $hdr);
55
		fwrite($rfd, $post);
56 4668f9f7 Scott Ullrich
57 5b237745 Scott Ullrich
		$inhdr = true;
58
		$resp = "";
59
		while (!feof($rfd)) {
60
			$line = fgets($rfd);
61
			if ($inhdr) {
62
				if (trim($line) == "")
63
					$inhdr = false;
64
			} else {
65
				$resp .= $line;
66
			}
67
		}
68 4668f9f7 Scott Ullrich
69 5b237745 Scott Ullrich
		fclose($rfd);
70 4668f9f7 Scott Ullrich
71 5b237745 Scott Ullrich
		return $resp;
72
	}
73 4668f9f7 Scott Ullrich
74 5b237745 Scott Ullrich
	return null;
75
}
76
77
if ($_POST && !file_exists($d_firmwarelock_path)) {
78
79
	unset($input_errors);
80
	unset($sig_warning);
81 4668f9f7 Scott Ullrich
82 5b237745 Scott Ullrich
	if (stristr($_POST['Submit'], "Enable"))
83
		$mode = "enable";
84
	else if (stristr($_POST['Submit'], "Disable"))
85
		$mode = "disable";
86
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
87
		$mode = "upgrade";
88 67965af4 Scott Ullrich
	else if ($_POST['sig_no']) {
89 5424dedc Scott Ullrich
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
90
				unlink("{$g['tmp_path']}/firmware.tgz");
91 67965af4 Scott Ullrich
    }
92 4668f9f7 Scott Ullrich
93 5b237745 Scott Ullrich
	if ($mode) {
94
		if ($mode == "enable") {
95
			exec_rc_script("/etc/rc.firmware enable");
96
			touch($d_fwupenabled_path);
97
		} else if ($mode == "disable") {
98
			exec_rc_script("/etc/rc.firmware disable");
99
			if (file_exists($d_fwupenabled_path))
100
				unlink($d_fwupenabled_path);
101
		} else if ($mode == "upgrade") {
102
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
103
				/* verify firmware image(s) */
104
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
105
					$input_errors[] = "The uploaded image file is not for this platfom ({$g['platform']}).";
106
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
107
					/* probably out of memory for the MFS */
108
					$input_errors[] = "Image upload failed (out of memory?)";
109
					exec_rc_script("/etc/rc.firmware disable");
110
					if (file_exists($d_fwupenabled_path))
111
						unlink($d_fwupenabled_path);
112
				} else {
113
					/* move the image so PHP won't delete it */
114 5424dedc Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
115 4668f9f7 Scott Ullrich
116 5b237745 Scott Ullrich
					/* check digital signature */
117 5424dedc Scott Ullrich
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
118 4668f9f7 Scott Ullrich
119 5b237745 Scott Ullrich
					if ($sigchk == 1)
120
						$sig_warning = "The digital signature on this image is invalid.";
121
					else if ($sigchk == 2)
122
						$sig_warning = "This image is not digitally signed.";
123
					else if (($sigchk == 3) || ($sigchk == 4))
124
						$sig_warning = "There has been an error verifying the signature on this image.";
125 4668f9f7 Scott Ullrich
126 5424dedc Scott Ullrich
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
127 5b237745 Scott Ullrich
						$input_errors[] = "The image file is corrupt.";
128 5424dedc Scott Ullrich
						unlink("{$g['tmp_path']}/firmware.tgz");
129 5b237745 Scott Ullrich
					}
130
				}
131
			}
132
133 4668f9f7 Scott Ullrich
			if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
134 5b237745 Scott Ullrich
				/* fire up the update script in the background */
135
				touch($d_firmwarelock_path);
136 5424dedc Scott Ullrich
				exec_rc_script_async("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
137 4668f9f7 Scott Ullrich
138 5b237745 Scott Ullrich
				$savemsg = "The firmware is now being installed. The firewall will reboot automatically.";
139
			}
140
		}
141
	}
142
} else {
143
	if (!isset($config['system']['disablefirmwarecheck']))
144
		$fwinfo = check_firmware_version();
145
}
146
?>
147
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
148
<html>
149
<head>
150
<title><?=gentitle("System: Firmware");?></title>
151
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
152
<link href="gui.css" rel="stylesheet" type="text/css">
153
</head>
154
155
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
156
<?php include("fbegin.inc"); ?>
157
<p class="pgtitle">System: Firmware</p>
158
<?php if ($input_errors) print_input_errors($input_errors); ?>
159
<?php if ($savemsg) print_info_box($savemsg); ?>
160
<?php if ($fwinfo) echo $fwinfo; ?>
161
<?php if (!in_array($g['platform'], $fwupplatforms)): ?>
162
<p><strong>Firmware uploading is not supported on this platform.</strong></p>
163
<?php elseif ($sig_warning && !$input_errors): ?>
164
<form action="system_firmware.php" method="post">
165 4668f9f7 Scott Ullrich
<?php
166 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
167
	"is not an official/supported image and may lead to unexpected behavior or security " .
168
	"compromises. Only install images that come from sources that you trust, and make sure ".
169
	"that the image has not been tampered with.<br><br>".
170
	"Do you want to install this image anyway (on your own risk)?";
171
print_info_box($sig_warning);
172
?>
173
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
174
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
175
</form>
176
<?php else: ?>
177
            <?php if (!file_exists($d_firmwarelock_path)): ?>
178 4668f9f7 Scott Ullrich
            <p>Click &quot;Enable firmware
179 5b237745 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.img)
180 4668f9f7 Scott Ullrich
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
181 5b237745 Scott Ullrich
              to start the upgrade process.</p>
182
            <form action="system_firmware.php" method="post" enctype="multipart/form-data">
183
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
184 4668f9f7 Scott Ullrich
                <tr>
185 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
186 4668f9f7 Scott Ullrich
                  <td width="78%">
187 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
188
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
189
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
190
				  <?php else: ?>
191
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
192
                    <br><br>
193
					<strong>Firmware image file: </strong>&nbsp;<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
                </tr>
201 4668f9f7 Scott Ullrich
                <tr>
202 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
203
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
204 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
205
                    has started. The firewall will reboot automatically after
206 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
207
                </tr>
208 18ff56f2 Scott Ullrich
209
		<tr>
210
		 <td colspan="2">&nbsp;</td>
211
		</tr>
212
		<tr>
213
		 <td colspan="2" class="listtopic">Invoke pfSense Auto Upgrade</td>
214
		</tr>
215
		<tr>
216
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
217
		  <td width="78%" class="vtable">
218 81b8cb2e Scott Ullrich
		  <p> Click this button to automatically upgrade pfSense in the background.  This may take a while.<br>
219 18ff56f2 Scott Ullrich
		  <br>
220
		  <a href="system_firmware.php?autoupgrade=true">Invoke Auto Upgrade</a>
221
		</tr>
222
223 5b237745 Scott Ullrich
              </table>
224
</form>
225
<?php endif; endif; ?>
226
<?php include("fend.inc"); ?>
227
</body>
228
</html>