Project

General

Profile

Download (6.97 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
require("xmlrpc_client.inc");
36

    
37
function old_checkversion() {
38
        global $g;
39
        $versioncheck_base_url = 'www.pfSense.com';
40
        $versioncheck_path = '/pfSense/checkversion.php';
41
        $post = "platform=" . rawurlencode(trim(file_get_contents("/etc/platform"))) .
42
                "&version=" . rawurlencode(trim(file_get_contents("/etc/version")));
43
        $rfd = @fsockopen($versioncheck_base_url, 80, $errno, $errstr, 3);
44
        if ($rfd) {
45
                $hdr = "POST {$versioncheck_path} HTTP/1.0\r\n";
46
                $hdr .= "Content-Type: application/x-www-form-urlencoded\r\n";
47
                $hdr .= "User-Agent: pfSense-webConfigurator/1.0\r\n";
48
                $hdr .= "Host: www.pfSense.com\r\n";
49
                $hdr .= "Content-Length: " . strlen($post) . "\r\n\r\n";
50

    
51
                fwrite($rfd, $hdr);
52
                fwrite($rfd, $post);
53

    
54
                $inhdr = true;
55
                $resp = "";
56
                while (!feof($rfd)) {
57
                        $line = fgets($rfd);
58
                        if ($inhdr) {
59
                                if (trim($line) == "")
60
                                        $inhdr = false;
61
                        } else {
62
                                $resp .= $line;
63
                        }
64
                }
65

    
66
                fclose($rfd);
67

    
68
                if($_GET['autoupgrade'] <> "")
69
                    return;
70

    
71
                return $resp;
72
        }
73

    
74
        return null;
75
}
76

    
77
?>
78
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
79
<html>
80
<head>
81
<title><?=gentitle("System: Firmware: Invoke Auto Upgrade");?></title>
82
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
83
<link href="gui.css" rel="stylesheet" type="text/css">
84
</head>
85

    
86
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
87

    
88
<?php include("fbegin.inc"); ?>
89
<p class="pgtitle">System: Firmware: Auto Upgrade</p>
90

    
91
<form action="system_firmware_auto.php" method="post">
92
<table width="100%" border="0" cellpadding="0" cellspacing="0">
93
  <tr>
94
    <td>
95
      <ul id="tabnav">
96
        <li class="tabact">Auto Update</a></li>
97
	<li class="tabinact"><a href="system_firmware.php">Firmware Update</a></li>
98
      </ul>
99
    </td>
100
  </tr>
101
	<tr>
102
	  <td class="tabcont">
103
	      <table width="100%" border="0" cellpadding="6" cellspacing="0">
104
		<tr>
105
		  <td>
106
		      <!-- progress bar -->
107
		      <center>
108
		      <table id="progholder" name="progholder" height='20' border='1' bordercolor='black' width='420' bordercolordark='#000000' bordercolorlight='#000000' style='border-collapse: collapse' colspacing='2' cellpadding='2' cellspacing='2'><tr><td><img border='0' src='progress_bar.gif' width='280' height='23' name='progressbar' id='progressbar'></td></tr></table>
109
		      <br>                      
110
		      <!-- command output box -->
111
		      <textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols='60' rows='7' name='output' id='output' wrap='hard'>
112
		      </textarea>                      
113
		      </center>
114
                      <p>
115
                      <center><input type="submit" value="Invoke Auto Upgrade">
116
		  </td>
117
		</tr>
118
	      </table>
119
	  </td>
120
	</tr>
121
</table>
122

    
123
<p>
124

    
125
<?php
126

    
127
/* Define necessary variables. */
128
$platform =		trim(file_get_contents('/etc/platform'));
129
$firmware_version =	trim(file_get_contents('/etc/version'));
130
$kernel_version =	trim(file_get_contents('/etc/version_kernel'));
131
$base_version =		trim(file_get_contents('/etc/version_base'));
132
$use_old_checkversion = true;
133

    
134
$static_text = "Downloading current version information... ";
135
update_output_window($static_text);
136
if($use_old_checkversion == true) {
137
	$versions = old_checkversion();
138
} else {
139
	$versions = check_firmware_version();
140
}
141
$static_text .= "done.\n";
142
update_output_window($static_text);
143

    
144
if($use_old_checkversion == false) {
145
	$upgrades = array('firmware', 'kernel', 'base');
146
	$bdiff_errors = array();
147
	if(array_shift($versions) == true) {
148
		$i = 0;
149
		$need_update = array();
150
		update_output_window("Found required updates");
151
		foreach($versions as $ver) {
152
			if(is_string($ver[0])) {
153
				$static_text .= ucfirst($upgrades[$i]) . "\n\tInstalled: " . $firmware_version . "\n\tCurrent: " . $ver[count($ver) -1] . "\n";
154
				$needupdate[] = true;
155
			} else {
156
				$needupdate[] = false;
157
			}
158
			$i++;
159
		}
160
		$i = 0;
161
		//              if(isset($versions[3])) $static_text = $versions[4] . '\n'; // If we have additional data (a CHANGELOG etc) to display, do so.
162
	} else {
163
		update_output_window("No updates required.");
164
	}
165

    
166

    
167
} else {
168
	if($versions != "") {
169
		update_output_window("There are updates available: \n\n" . $versions . "\n\n");
170
		$http_auth_username = "";
171
		$http_auth_password = "";
172
		if($config['system']['proxy_auth_username'])
173
			$http_auth_username = $config['system']['proxy_auth_username'];
174
		if($config['system']['proxy_auth_password'])
175
			$http_auth_password = $config['system']['proxy_auth_password'];
176

    
177
		/* custom firmware option */
178
		if (isset($config['system']['alt_firmware_url']['enabled'])) {
179
			$firmwareurl=$config['system']['alt_firmware_url']['firmware_base_url'];
180
			$firmwarename=$config['system']['alt_firmware_url']['firmware_filename'];
181
		} else {
182
			$firmwareurl=$g['firmwarebaseurl'];
183
			$firmwarename=$g['firmwarefilename'];
184
		}
185
	} elseif($versions == "") {
186
		update_output_window("You are running the latest version of pfSense.");
187
	} elseif(is_null($versions)) {
188
		update_output_window("Unable to receive version information from pfSense.com.");
189
	} else {
190
		update_output_window("An unknown error occurred.");
191
	}
192
}
193

    
194
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
195

    
196
?>
197

    
198
</form>
199
<?php include("fend.inc"); ?>
200
</body>
201
</html>
202

    
203

    
204
</body>
205
</html>
(96-96/112)