Project

General

Profile

Download (7.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
/* Handle manual upgrade */
38
if ($_POST && !file_exists($d_firmwarelock_path)) {
39

    
40
	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
				$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
			}
99
		}
100
	}
101
}
102

    
103
/* upload progress bar id */
104
$id = rand() . '.' . time();
105
$mth = ini_get('upload_progress_meter.store_method');
106
$dir = ini_get('upload_progress_meter.file.filename_template');
107

    
108
$pgtitle = "System: Firmware";
109
include("head.inc");
110

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

    
192
</form>
193
<?php endif; endif; ?>
194
<?php include("fend.inc"); ?>
195
</body>
196
</html>
197

    
(105-105/128)