Project

General

Profile

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

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

    
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
	TODO:
33
		* modify pfSense.com XMLRPC server to return md5 hashes of firmware updates.
34
*/
35

    
36
Header("Location: system_firmware.php");
37
exit;
38

    
39
require_once("guiconfig.inc");
40
require_once("xmlrpc.inc");
41

    
42
$pgtitle = "System: Firmware: Auto Update";
43
include("head.inc");
44

    
45
?>
46

    
47
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
48
<?php include("fbegin.inc"); ?>
49
<p class="pgtitle"><?=$pgtitle?></p>
50

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

    
94
<?php
95

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

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

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

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

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

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

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

    
163
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
164
?>
(129-129/162)