Project

General

Profile

Download (5.89 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php
2
<?php
3
/* $Id$ */
4
/*
5
	system_firmware_auto.php
6
	part of pfSense (http://www.pfsense.com)
7

    
8
	Copyright (C) 2005 Scott Ullrich and Colin Smith
9

    
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32

    
33
	TODO:
34
		* modify pfSense.com XMLRPC server to return md5 hashes of firmware updates.
35
*/
36

    
37
require_once("guiconfig.inc");
38
require_once("xmlrpc.inc");
39

    
40
?>
41
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
42
<html>
43
<head>
44
<title><?=gentitle("System: Firmware: Firmware Updater");?></title>
45
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
46
<link href="gui.css" rel="stylesheet" type="text/css">
47
</head>
48

    
49
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
50

    
51
<?php include("fbegin.inc"); ?>
52
<p class="pgtitle">System: Firmware: Firmware Updater</p>
53

    
54
<form action="system_firmware_auto.php" method="post">
55
<table width="100%" border="0" cellpadding="0" cellspacing="0">
56
  <tr>
57
    <td>
58
<?php
59
	$tab_array = array();
60
	$tab_array[0] = array("Manual Update", false, "system_firmware.php");
61
	$tab_array[1] = array("Auto Update", true, "system_firmware_check.php");
62
	$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
63
	display_top_tabs($tab_array);
64
?>
65
    </td>
66
  </tr>
67
	<tr>
68
	  <td class="tabcont">
69
	      <table width="100%" border="0" cellpadding="6" cellspacing="0">
70
		<tr>
71
		  <td>
72
		      <!-- progress bar -->
73
		      <center>
74
		      <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>
75
		      <br>
76
		      <!-- status box -->
77
		      <textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="1" name="status" id="status" wrap="hard">
78
		      Beginning system autoupdate...
79
		      </textarea>
80
		      <!-- command output box -->
81
		      <textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="25" name="output" id="output" wrap="hard">
82
		      </textarea>
83
		      </center>
84
		  </td>
85
		</tr>
86
	      </table>
87
	  </td>
88
	</tr>
89
</table>
90
</form>
91
<?php include("fend.inc"); ?>
92
</body>
93
</html>
94

    
95
<?php
96

    
97
/* Define necessary variables. */
98
$update_types = array('full', 'diff');
99
$didupdate = false;
100

    
101
if($_GET['category'] == 'full') {
102
	$tocheck = 'all';
103
	$categories = array('firmware', 'kernel', 'base');
104
} else {
105
	$tocheck = array($_GET['category']);
106
	$categories = $tocheck;
107
}
108

    
109
$static_output = "Downloading current version information... ";
110
update_status($static_output);
111
update_output_window($static_output);
112

    
113
if(file_exists("/tmp/versioncheck.cache")) {
114
	$versions = unserialize("/tmp/versioncheck.cache");
115
	if(time() - $versions['cachetime'] > 300) { // Our cached data is stale, get a new copy.
116
		$versions = check_firmware_version($tocheck);
117
	} else { // Our cached data is relatively currently, remove the cachetime label.
118
		unset($versions['cachetime']);
119
	}
120
}
121

    
122
$static_output .= "done.\n";
123
update_output_window($static_output);
124

    
125
foreach($categories as $index => $key) {
126
	$bdiff_errors = array();
127
	if(is_array($versions[$key][0])) { // Make sure we really need to update this section.
128
		$didupdate = true;
129
		update_status("Found required " . $key . " updates. Downloading...");
130
		$static_output .= "Downloading " . $key . " updates... ";
131
		update_output_window($static_output);
132
		foreach($versions[$key] as $ver) { // Begin system updates.
133
			foreach($update_types as $type) if(in_array($type, array_keys($ver))) $url_type = $type;
134
			$tofetch = "pfSense-" . ucfirst($url_type) . "-" . ucfirst($key) . "-Update-" . $ver['version'] . ".tgz";
135
			$static_output_bak = $static_output;
136
			$static_output .= "\n\t" . $ver['version'] . "-" . $ver['name'] . " ";
137
			update_output_window($static_output);
138
			download_file_with_progress_bar("http://www.pfsense.com/updates/" . $tofetch, "/tmp/" . $tofetch);
139
			if($url_type == "binary") {
140
				exec("/etc/rc.firmware delta_update " . "/tmp/" . $tofetch, $bdiff_errors);
141
				if(is_string($bdiff_errors[0])) {
142
					unlink_if_exists("/tmp/" . $tofetch);
143
					$static_output .= "failed!\n";
144
					update_output_window($static_output);
145
					break;
146
				}
147
			} else {
148
				$tofetch = "pfSense-" . ucfirst($url_type) . "-Update-" . $ver['version'] . ".tgz";
149
				exec("/etc/rc.firmware pfSenseupgrade " . "/tmp/" . $tofetch);
150
				unlink_if_exists("/tmp/" . $tofetch);
151
			}
152
			$static_output = $static_output_bak . "done.\n";
153
		}
154
	}
155
}
156

    
157
if($didupdate == true) {
158
	update_status("Update finished. Rebooting...");
159
	exec("/etc/rc.reboot");
160
} else {
161
	update_status("No updates required.");
162
}
163

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

    
166
?>
(105-105/127)