Project

General

Profile

Download (8.4 KB) Statistics
| Branch: | Tag: | Revision:
1 4668f9f7 Scott Ullrich
<?php
2 b46bfcf5 Bill Marquette
/* $Id$ */
3 5b237745 Scott Ullrich
/*
4 580182e2 Colin Smith
	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 5b237745 Scott Ullrich
*/
31
32 3958d63b Colin Smith
$d_isfwfile = 1;
33 6605faea Scott Ullrich
require_once("guiconfig.inc");
34
require_once("xmlrpc_client.inc");
35 aa08f46b Bill Marquette
36 8b7c81d7 Scott Ullrich
/* if upgrade in progress, alert user */
37
if(file_exists($d_firmwarelock_path)) {
38
	$pgtitle = "System: Firmware: Manual Update";
39
	include("head.inc");
40
	echo "<body link=\"#0000CC\" vlink=\"#0000CC\" alink=\"#0000CC\">\n";
41
	include("fbegin.inc");
42
	echo "<p class=\"pgtitle\"><?=$pgtitle?></p>\n";
43
	echo "<div>\n";
44 11d46d11 Scott Ullrich
	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'>");
45 8b7c81d7 Scott Ullrich
	echo "</div>\n";
46
	include("fend.inc");
47
	echo "</body>";
48
	echo "</html>";
49
	exit;
50
}
51
52 aa08f46b Bill Marquette
/* Handle manual upgrade */
53 5b237745 Scott Ullrich
if ($_POST && !file_exists($d_firmwarelock_path)) {
54
55 580182e2 Colin Smith
	unset($input_errors);
56
	unset($sig_warning);
57
58
	if (stristr($_POST['Submit'], "Enable"))
59
		$mode = "enable";
60
	else if (stristr($_POST['Submit'], "Disable"))
61
		$mode = "disable";
62
	else if (stristr($_POST['Submit'], "Upgrade") || $_POST['sig_override'])
63
		$mode = "upgrade";
64
	else if ($_POST['sig_no']) {
65 709f48f0 Scott Ullrich
		if(file_exists("{$g['upload_path']}/firmware.tgz"))
66
				unlink("{$g['upload_path']}/firmware.tgz");
67 580182e2 Colin Smith
	}
68
	if ($mode) {
69
		if ($mode == "enable") {
70
			exec_rc_script("/etc/rc.firmware enable");
71 b6f67235 Scott Ullrich
			conf_mount_rw();
72 580182e2 Colin Smith
			touch($d_fwupenabled_path);
73
		} else if ($mode == "disable") {
74
			exec_rc_script("/etc/rc.firmware disable");
75 b6f67235 Scott Ullrich
			conf_mount_ro();
76 580182e2 Colin Smith
			if (file_exists($d_fwupenabled_path))
77
				unlink($d_fwupenabled_path);
78
		} else if ($mode == "upgrade") {
79
			if (is_uploaded_file($_FILES['ulfile']['tmp_name'])) {
80
				/* verify firmware image(s) */
81
				if (!stristr($_FILES['ulfile']['name'], $g['platform']) && !$_POST['sig_override'])
82 f44a6ab5 Bill Marquette
					$input_errors[] = "The uploaded image file is not for this platform ({$g['platform']}).";
83 580182e2 Colin Smith
				else if (!file_exists($_FILES['ulfile']['tmp_name'])) {
84
					/* probably out of memory for the MFS */
85
					$input_errors[] = "Image upload failed (out of memory?)";
86
					exec_rc_script("/etc/rc.firmware disable");
87
					if (file_exists($d_fwupenabled_path))
88
						unlink($d_fwupenabled_path);
89
				} else {
90
					/* move the image so PHP won't delete it */
91 1ef7b568 Scott Ullrich
					rename($_FILES['ulfile']['tmp_name'], "{$g['upload_path']}/firmware.tgz");
92 580182e2 Colin Smith
93
					/* check digital signature */
94 1ef7b568 Scott Ullrich
					$sigchk = verify_digital_signature("{$g['upload_path']}/firmware.tgz");
95 580182e2 Colin Smith
96
					if ($sigchk == 1)
97
						$sig_warning = "The digital signature on this image is invalid.";
98
					else if ($sigchk == 2)
99
						$sig_warning = "This image is not digitally signed.";
100
					else if (($sigchk == 3) || ($sigchk == 4))
101
						$sig_warning = "There has been an error verifying the signature on this image.";
102
103 709f48f0 Scott Ullrich
					if (!verify_gzip_file("{$g['upload_path']}/firmware.tgz")) {
104 580182e2 Colin Smith
						$input_errors[] = "The image file is corrupt.";
105 1ef7b568 Scott Ullrich
						unlink("{$g['upload_path']}/firmware.tgz");
106 580182e2 Colin Smith
					}
107
				}
108
			}
109
110 1ef7b568 Scott Ullrich
            /* Check for input errors, firmware locks, warnings, then check for firmware if sig_override is set */
111
            if (!$input_errors && !file_exists($d_firmwarelock_path) && (!$sig_warning || $_POST['sig_override'])) {
112
                    if (file_exists("{$g['upload_path']}/firmware.tgz")) {
113
                            /* fire up the update script in the background */
114
                            touch($d_firmwarelock_path);
115
                            $savemsg = "The firmware is now being updated. The firewall will reboot automatically.";
116
                            mwexec_bg("/etc/rc.firmware pfSenseupgrade {$g['upload_path']}/firmware.tgz");
117
                    } else {
118
                            $savemsg = "Firmware image missing or other error, please try again.";
119
                    }
120
            }
121 580182e2 Colin Smith
		}
122
	}
123 5b237745 Scott Ullrich
}
124 e2fa4962 Scott Ullrich
125 94656ba5 Bill Marquette
$pgtitle = "System: Firmware: Manual Update";
126 52380979 Scott Ullrich
include("head.inc");
127
128 5b237745 Scott Ullrich
?>
129 580182e2 Colin Smith
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
130
<?php include("fbegin.inc"); ?>
131 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
132 580182e2 Colin Smith
<?php if ($input_errors) print_input_errors($input_errors); ?>
133 1ef7b568 Scott Ullrich
<?php if ($savemsg) print_info_box($savemsg); ?>
134 580182e2 Colin Smith
<?php if ($fwinfo <> "") print_info_box($fwinfo); ?>
135 77720bd3 Colin Smith
<?php if ($sig_warning && !$input_errors): ?>
136 5b237745 Scott Ullrich
<form action="system_firmware.php" method="post">
137 4668f9f7 Scott Ullrich
<?php
138 5b237745 Scott Ullrich
$sig_warning = "<strong>" . $sig_warning . "</strong><br>This means that the image you uploaded " .
139 580182e2 Colin Smith
	"is not an official/supported image and may lead to unexpected behavior or security " .
140
	"compromises. Only install images that come from sources that you trust, and make sure ".
141
	"that the image has not been tampered with.<br><br>".
142
	"Do you want to install this image anyway (on your own risk)?";
143 5b237745 Scott Ullrich
print_info_box($sig_warning);
144
?>
145
<input name="sig_override" type="submit" class="formbtn" id="sig_override" value=" Yes ">
146
<input name="sig_no" type="submit" class="formbtn" id="sig_no" value=" No ">
147 819197a8 Scott Ullrich
</form>
148 5b237745 Scott Ullrich
<?php else: ?>
149
            <?php if (!file_exists($d_firmwarelock_path)): ?>
150 819197a8 Scott Ullrich
<form action="system_firmware.php" method="post" enctype="multipart/form-data">
151 580182e2 Colin Smith
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
152
	<tr>
153
		<td>
154 4820d297 Scott Ullrich
<?php
155
	$tab_array = array();
156
	$tab_array[0] = array("Manual Update", true, "system_firmware.php");
157 9b7d7aa9 Scott Ullrich
	//$tab_array[1] = array("Auto Update", false, "system_firmware_check.php");
158
	//$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
159 4820d297 Scott Ullrich
	display_top_tabs($tab_array);
160
?>
161 580182e2 Colin Smith
		</td>
162
	</tr>
163 222494af Colin Smith
  <tr>
164 e12d98ea Bill Marquette
    <td>
165
	<div id="mainarea">
166
              <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
167 3958d63b Colin Smith
                <tr>
168 580182e2 Colin Smith
		 <td colspan="2" class="listtopic">Invoke pfSense Manual Upgrade</td>
169
		</tr>
170
		  <td width="22%" valign="baseline" class="vncell">&nbsp;</td>
171 db7f4f2b Scott Ullrich
                  <td width="78%" class="vtable">
172 aa08f46b Bill Marquette
            <p>Click &quot;Enable firmware
173 3aed9904 Scott Ullrich
              upload&quot; below, then choose the image file (<?=$g['platform'];?>-*.tgz)
174 580182e2 Colin Smith
			  to be uploaded.<br>Click &quot;Upgrade firmware&quot;
175 aa08f46b Bill Marquette
              to start the upgrade process.</p>
176 03c64985 Scott Ullrich
                    <?php if (!file_exists($d_sysrebootreqd_path)): ?>
177 5b237745 Scott Ullrich
                    <?php if (!file_exists($d_fwupenabled_path)): ?>
178
                    <input name="Submit" type="submit" class="formbtn" value="Enable firmware upload">
179 580182e2 Colin Smith
				  <?php else: ?>
180
				   <input name="Submit" type="submit" class="formbtn" value="Disable firmware upload">
181 5b237745 Scott Ullrich
                    <br><br>
182 580182e2 Colin Smith
					<strong>Firmware image file: </strong>&nbsp;
183
					<input name="ulfile" type="file" class="formfld">
184 5b237745 Scott Ullrich
                    <br><br>
185 427a8ac9 Scott Ullrich
		    <input name="Submit" type="submit" class="formbtn" value="Upgrade firmware">
186 580182e2 Colin Smith
				  <?php endif; else: ?>
187 03c64985 Scott Ullrich
				    <strong>You must reboot the system before you can upgrade the firmware.</strong>
188 580182e2 Colin Smith
				  <?php endif; ?>
189 5b237745 Scott Ullrich
                  </td>
190 580182e2 Colin Smith
		</td>
191 5b237745 Scott Ullrich
                </tr>
192 4668f9f7 Scott Ullrich
                <tr>
193 5b237745 Scott Ullrich
                  <td width="22%" valign="top">&nbsp;</td>
194
                  <td width="78%"><span class="vexpl"><span class="red"><strong>Warning:<br>
195 4668f9f7 Scott Ullrich
                    </strong></span>DO NOT abort the firmware upgrade once it
196
                    has started. The firewall will reboot automatically after
197 5b237745 Scott Ullrich
                    storing the new firmware. The configuration will be maintained.</span></td>
198
              </table>
199 e12d98ea Bill Marquette
		</div>
200 580182e2 Colin Smith
		</tr>
201
		</td>
202 222494af Colin Smith
</table>
203 580182e2 Colin Smith
204 5b237745 Scott Ullrich
</form>
205 03c64985 Scott Ullrich
<?php endif; endif; ?>
206 5b237745 Scott Ullrich
<?php include("fend.inc"); ?>
207
</body>
208
</html>