Project

General

Profile

Download (5.76 KB) Statistics
| Branch: | Tag: | Revision:
1 25682561 Scott Ullrich
<?php
2
/* $Id$ */
3
/*
4
	system_firmware_auto.php
5 853167d2 Colin Smith
	part of pfSense (http://www.pfsense.com)
6 5c59c339 Scott Ullrich
7 222494af Colin Smith
	Copyright (C) 2005 Scott Ullrich and Colin Smith
8 5c59c339 Scott Ullrich
9 25682561 Scott Ullrich
	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 15581b1e Colin Smith
32
	TODO:
33
		* modify pfSense.com XMLRPC server to return md5 hashes of firmware updates.
34 25682561 Scott Ullrich
*/
35
36 9b7d7aa9 Scott Ullrich
Header("Location: system_firmware.php");
37
exit;
38
39 36f1a6d7 Colin Smith
require_once("guiconfig.inc");
40 233d5b0f Colin Smith
require_once("xmlrpc.inc");
41 25682561 Scott Ullrich
42 52380979 Scott Ullrich
$pgtitle = "System: Firmware: Auto Update";
43
include("head.inc");
44
45 25682561 Scott Ullrich
?>
46
47
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
48
<?php include("fbegin.inc"); ?>
49 74f446e8 Bill Marquette
<p class="pgtitle"><?=$pgtitle?></p>
50 25682561 Scott Ullrich
51
<form action="system_firmware_auto.php" method="post">
52 3a023f99 Colin Smith
<table width="100%" border="0" cellpadding="0" cellspacing="0">
53
  <tr>
54
    <td>
55 4820d297 Scott Ullrich
<?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 3a023f99 Colin Smith
    </td>
63
  </tr>
64 25682561 Scott Ullrich
	<tr>
65 e12d98ea Bill Marquette
	  <td>
66
	      <div id="mainarea">
67
	      <table class="tabcont" width="100%" border="0" cellpadding="6" cellspacing="0">
68 1c0e3b99 Scott Ullrich
		<tr>
69
		  <td>
70
		      <!-- progress bar -->
71
		      <center>
72 677c0869 Erik Kristensen
		      <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 1c0e3b99 Scott Ullrich
		      <br>
74
		      <!-- status box -->
75 222494af Colin Smith
		      <textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="1" name="status" id="status" wrap="hard">
76 853167d2 Colin Smith
		      Beginning system autoupdate...
77 3db58e13 Scott Ullrich
		      </textarea>
78 1c0e3b99 Scott Ullrich
		      <!-- command output box -->
79 222494af Colin Smith
		      <textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="25" name="output" id="output" wrap="hard">
80 3db58e13 Scott Ullrich
		      </textarea>
81 1c0e3b99 Scott Ullrich
		      </center>
82
		  </td>
83
		</tr>
84 25682561 Scott Ullrich
	      </table>
85 e12d98ea Bill Marquette
	      </div>
86 25682561 Scott Ullrich
	  </td>
87
	</tr>
88 1c0e3b99 Scott Ullrich
</table>
89 25682561 Scott Ullrich
</form>
90
<?php include("fend.inc"); ?>
91
</body>
92
</html>
93
94
<?php
95
96 5c59c339 Scott Ullrich
/* Define necessary variables. */
97 d40b3c36 Colin Smith
$update_types = array('full', 'diff');
98 ebe916cf Colin Smith
$didupdate = false;
99 d40b3c36 Colin Smith
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 cdb0117c Scott Ullrich
108 45497dd7 Colin Smith
$static_output = "Downloading current version information... ";
109
update_status($static_output);
110
update_output_window($static_output);
111 d40b3c36 Colin Smith
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 ea041900 Colin Smith
}
120 d40b3c36 Colin Smith
121 45497dd7 Colin Smith
$static_output .= "done.\n";
122
update_output_window($static_output);
123 cdb0117c Scott Ullrich
124 d40b3c36 Colin Smith
foreach($categories as $index => $key) {
125 1c62837e Colin Smith
	$bdiff_errors = array();
126 d40b3c36 Colin Smith
	if(is_array($versions[$key][0])) { // Make sure we really need to update this section.
127 ebe916cf Colin Smith
		$didupdate = true;
128 d40b3c36 Colin Smith
		update_status("Found required " . $key . " updates. Downloading...");
129 45497dd7 Colin Smith
		$static_output .= "Downloading " . $key . " updates... ";
130
		update_output_window($static_output);
131 d40b3c36 Colin Smith
		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 b451b6ab Colin Smith
			$tofetch = "pfSense-" . ucfirst($url_type) . "-" . ucfirst($key) . "-Update-" . $ver['version'] . ".tgz";
134 45497dd7 Colin Smith
			$static_output_bak = $static_output;
135
			$static_output .= "\n\t" . $ver['version'] . "-" . $ver['name'] . " ";
136
			update_output_window($static_output);
137 d40b3c36 Colin Smith
			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 b3a93cb0 Colin Smith
					unlink_if_exists("/tmp/" . $tofetch);
142 45497dd7 Colin Smith
					$static_output .= "failed!\n";
143
					update_output_window($static_output);
144 d40b3c36 Colin Smith
					break;
145 5f69494b Colin Smith
				}
146 d40b3c36 Colin Smith
			} else {
147 b451b6ab Colin Smith
				$tofetch = "pfSense-" . ucfirst($url_type) . "-Update-" . $ver['version'] . ".tgz";
148 d40b3c36 Colin Smith
				exec("/etc/rc.firmware pfSenseupgrade " . "/tmp/" . $tofetch);
149 b3a93cb0 Colin Smith
				unlink_if_exists("/tmp/" . $tofetch);
150 5f69494b Colin Smith
			}
151 45497dd7 Colin Smith
			$static_output = $static_output_bak . "done.\n";
152 5f69494b Colin Smith
		}
153 ea041900 Colin Smith
	}
154
}
155 ebe916cf Colin Smith
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 853167d2 Colin Smith
163 1c0e3b99 Scott Ullrich
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
164 29f96f5a Colin Smith
?>