Project

General

Profile

Download (7.98 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php
2 4668f9f7 Scott Ullrich
<?php
3 b46bfcf5 Bill Marquette
/* $Id$ */
4 5b237745 Scott Ullrich
/*
5 580182e2 Colin Smith
	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 5b237745 Scott Ullrich
*/
32
33 3958d63b Colin Smith
$d_isfwfile = 1;
34 6605faea Scott Ullrich
require_once("guiconfig.inc");
35
require_once("xmlrpc_client.inc");
36 aa08f46b Bill Marquette
37
/* Handle manual upgrade */
38 5b237745 Scott Ullrich
if ($_POST && !file_exists($d_firmwarelock_path)) {
39
40 580182e2 Colin Smith
	unset($input_errors);
41
	unset($sig_warning);
42
43
	if (stristr($_POST['Submit'], "Enable"))
44
		$mode = "enable";
45
	else if (stristr($_POST['Submit'], "Disable"))
46
		$mode = "disable";
47
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
48
		$mode = "upgrade";
49
	else if ($_POST['sig_no']) {
50
		if(file_exists("{$g['tmp_path']}/firmware.tgz"))
51
				unlink("{$g['tmp_path']}/firmware.tgz");
52
	}
53
	if ($mode) {
54
		if ($mode == "enable") {
55
			exec_rc_script("/etc/rc.firmware enable");
56
			touch($d_fwupenabled_path);
57
		} else if ($mode == "disable") {
58
			exec_rc_script("/etc/rc.firmware disable");
59
			if (file_exists($d_fwupenabled_path))
60
				unlink($d_fwupenabled_path);
61
		} else if ($mode == "upgrade") {
62
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
63
				/* verify firmware image(s) */
64
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
65
					$input_errors[] = "The uploaded image file is not for this platfom ({$g['platform']}).";
66
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
67
					/* probably out of memory for the MFS */
68
					$input_errors[] = "Image upload failed (out of memory?)";
69
					exec_rc_script("/etc/rc.firmware disable");
70
					if (file_exists($d_fwupenabled_path))
71
						unlink($d_fwupenabled_path);
72
				} else {
73
					/* move the image so PHP won't delete it */
74
					rename($_FILES['ulfile']['tmp_name'], "{$g['tmp_path']}/firmware.tgz");
75
76
					/* check digital signature */
77
					$sigchk = verify_digital_signature("{$g['tmp_path']}/firmware.tgz");
78
79
					if ($sigchk == 1)
80
						$sig_warning = "The digital signature on this image is invalid.";
81
					else if ($sigchk == 2)
82
						$sig_warning = "This image is not digitally signed.";
83
					else if (($sigchk == 3) || ($sigchk == 4))
84
						$sig_warning = "There has been an error verifying the signature on this image.";
85
86
					if (!verify_gzip_file("{$g['tmp_path']}/firmware.tgz")) {
87
						$input_errors[] = "The image file is corrupt.";
88
						unlink("{$g['tmp_path']}/firmware.tgz");
89
					}
90
				}
91
			}
92
93
			if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
94
				/* fire up the update script in the background */
95
				touch($d_firmwarelock_path);
96 59fe3cdf Scott Ullrich
				$savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
97
				mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['tmp_path']}/firmware.tgz");
98 580182e2 Colin Smith
			}
99
		}
100
	}
101 5b237745 Scott Ullrich
}
102 e2fa4962 Scott Ullrich
103 97a9a675 Scott Ullrich
/* upload progress bar id */
104 e2fa4962 Scott Ullrich
$id = rand() . '.' . time();
105
$mth = ini_get('upload_progress_meter.store_method');
106
$dir = ini_get('upload_progress_meter.file.filename_template');
107
108 5b237745 Scott Ullrich
?>
109
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
110
<html>
111
<head>
112 580182e2 Colin Smith
<title><?=gentitle("System: Firmware");?></title>
113 5b237745 Scott Ullrich
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
114
<link href="gui.css" rel="stylesheet" type="text/css">
115
</head>
116 580182e2 Colin Smith
<!--
117
generated new UPLOAD_IDENTIFIER = <?=$id?>
118
php-config.upload_progress_meter.store_method = <?=$mth?>
119
php-config.upload_progress_meter.file.filename_template = <?=$dir?>
120
-->
121
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
122
<?php include("fbegin.inc"); ?>
123
<p class="pgtitle">System: Firmware</p>
124
<?php if ($input_errors) print_input_errors($input_errors); ?>
125
<?php if ($savemsg) print_info_box($savemsg); ?>  	 
126
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
127 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
128 5b237745 Scott Ullrich
<form action="system_firmware.php" method="post">
129 4668f9f7 Scott Ullrich
<?php
130 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
131 580182e2 Colin Smith
	"is not an official/supported image and may lead to unexpected behavior or security " .
132
	"compromises. Only install images that come from sources that you trust, and make sure ".
133
	"that the image has not been tampered with.<br><br>".
134 d28303ed Scott Ullrich
	"Please note that we do not sign alpha and or beta images.<br><br>".
135 580182e2 Colin Smith
	"Do you want to install this image anyway (on your own risk)?";
136 5b237745 Scott Ullrich
print_info_box($sig_warning);
137
?>
138
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
139
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
140
</form>
141
<?php else: ?>
142
            <?php if (!file_exists($d_firmwarelock_path)): ?>
143 52d69e6a Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
144 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
145
	<tr>
146
		<td>
147
			<ul id="tabnav">
148 d9ff08b7 Scott Ullrich
				<li class="tabact">Manual Update</a></li>
149 ebe916cf Colin Smith
				<li class="tabinact"><a href="system_firmware_check.php">Auto Update</a></li>
150 580182e2 Colin Smith
			</ul>
151
		</td>
152
	</tr>
153 222494af Colin Smith
  <tr>
154
    <td class="tabcont">
155 580182e2 Colin Smith
              <table width="100%" border="0" cellpadding="6" cellspacing="0">
156 3958d63b Colin Smith
                <tr>
157 580182e2 Colin Smith
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
158
		</tr>
159
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
160 db7f4f2b Scott Ullrich
                  <td width="78%" class="vtable">
161 aa08f46b Bill Marquette
            <p>Click &quot;Enable firmware
162 3aed9904 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
163 580182e2 Colin Smith
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
164 aa08f46b Bill Marquette
              to start the upgrade process.</p>
165 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
166
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
167
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
168 580182e2 Colin Smith
				  <?php else: ?>
169
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
170 5b237745 Scott Ullrich
                    <br><br>
171 580182e2 Colin Smith
					<strong>Firmware image file: </strong>&nbsp;
172
					<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?=$id?>">
173
					<input name="ulfile" type="file" class="formfld">
174 5b237745 Scott Ullrich
                    <br><br>
175 580182e2 Colin Smith
		    <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; ">
176
				  <?php endif; else: ?>
177
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
178
				  <?php endif; ?>
179 5b237745 Scott Ullrich
                  </td>
180 580182e2 Colin Smith
		</td>
181 5b237745 Scott Ullrich
                </tr>
182 4668f9f7 Scott Ullrich
                <tr>
183 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
184
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
185 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
186
                    has started. The firewall will reboot automatically after
187 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
188
              </table>
189 580182e2 Colin Smith
		</tr>
190
		</td>
191 222494af Colin Smith
</table>
192 580182e2 Colin Smith
193 5b237745 Scott Ullrich
</form>
194
<?php endif; endif; ?>
195
<?php include("fend.inc"); ?>
196
</body>
197
</html>