Project

General

Profile

Download (5.72 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
require_once("guiconfig.inc");
37
require_once("xmlrpc.inc");
38

    
39
$pgtitle = "System: Firmware: Auto Update";
40
include("head.inc");
41

    
42
?>
43

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

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

    
91
<?php
92

    
93
/* Define necessary variables. */
94
$update_types = array('full', 'diff');
95
$didupdate = false;
96

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

    
105
$static_output = "Downloading current version information... ";
106
update_status($static_output);
107
update_output_window($static_output);
108

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

    
118
$static_output .= "done.\n";
119
update_output_window($static_output);
120

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

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

    
160
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
161
?>
(127-127/160)