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: Invoke Auto Upgrade");?></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: Auto Upgrade</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
|
<ul id="tabnav">
|
59
|
<li class="tabinact"><a href="system_firmware.php">Manual Update</a></li>
|
60
|
<li class="tabact">Auto Update</a></li>
|
61
|
</ul>
|
62
|
</td>
|
63
|
</tr>
|
64
|
<tr>
|
65
|
<td class="tabcont">
|
66
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
67
|
<tr>
|
68
|
<td>
|
69
|
<!-- progress bar -->
|
70
|
<center>
|
71
|
<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>
|
72
|
<br>
|
73
|
<!-- status box -->
|
74
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="1" name="status" id="status" wrap="hard">
|
75
|
Beginning system autoupdate...
|
76
|
</textarea>
|
77
|
<!-- command output box -->
|
78
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="25" name="output" id="output" wrap="hard">
|
79
|
</textarea>
|
80
|
</center>
|
81
|
</td>
|
82
|
</tr>
|
83
|
</table>
|
84
|
</td>
|
85
|
</tr>
|
86
|
</table>
|
87
|
</form>
|
88
|
<?php include("fend.inc"); ?>
|
89
|
</body>
|
90
|
</html>
|
91
|
|
92
|
<?php
|
93
|
|
94
|
/* Define necessary variables. */
|
95
|
$update_types = array('full', 'diff');
|
96
|
$didupdate = false;
|
97
|
|
98
|
if($_GET['category'] == 'full') {
|
99
|
$tocheck = 'all';
|
100
|
$categories = array('firmware', 'kernel', 'base');
|
101
|
} else {
|
102
|
$tocheck = array($_GET['category']);
|
103
|
$categories = $tocheck;
|
104
|
}
|
105
|
|
106
|
$static_output = "Downloading current version information... ";
|
107
|
update_status($static_output);
|
108
|
update_output_window($static_output);
|
109
|
|
110
|
if(file_exists("/tmp/versioncheck.cache")) {
|
111
|
$versions = unserialize("/tmp/versioncheck.cache");
|
112
|
if(time() - $versions['cachetime'] > 300) { // Our cached data is stale, get a new copy.
|
113
|
$versions = check_firmware_version($tocheck);
|
114
|
} else { // Our cached data is relatively currently, remove the cachetime label.
|
115
|
unset($versions['cachetime']);
|
116
|
}
|
117
|
}
|
118
|
|
119
|
$static_output .= "done.\n";
|
120
|
update_output_window($static_output);
|
121
|
|
122
|
foreach($categories as $index => $key) {
|
123
|
$bdiff_errors = array();
|
124
|
if(is_array($versions[$key][0])) { // Make sure we really need to update this section.
|
125
|
$didupdate = true;
|
126
|
update_status("Found required " . $key . " updates. Downloading...");
|
127
|
$static_output .= "Downloading " . $key . " updates... ";
|
128
|
update_output_window($static_output);
|
129
|
foreach($versions[$key] as $ver) { // Begin system updates.
|
130
|
foreach($update_types as $type) if(in_array($type, array_keys($ver))) $url_type = $type;
|
131
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-" . ucfirst($key) . "-Update-" . $ver['version'] . ".tgz";
|
132
|
$static_output_bak = $static_output;
|
133
|
$static_output .= "\n\t" . $ver['version'] . "-" . $ver['name'] . " ";
|
134
|
update_output_window($static_output);
|
135
|
download_file_with_progress_bar("http://www.pfsense.com/updates/" . $tofetch, "/tmp/" . $tofetch);
|
136
|
if($url_type == "binary") {
|
137
|
exec("/etc/rc.firmware delta_update " . "/tmp/" . $tofetch, $bdiff_errors);
|
138
|
if(is_string($bdiff_errors[0])) {
|
139
|
unlink_if_exists("/tmp/" . $tofetch);
|
140
|
$static_output .= "failed!\n";
|
141
|
update_output_window($static_output);
|
142
|
break;
|
143
|
}
|
144
|
} else {
|
145
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-Update-" . $ver['version'] . ".tgz";
|
146
|
exec("/etc/rc.firmware pfSenseupgrade " . "/tmp/" . $tofetch);
|
147
|
unlink_if_exists("/tmp/" . $tofetch);
|
148
|
}
|
149
|
$static_output = $static_output_bak . "done.\n";
|
150
|
}
|
151
|
}
|
152
|
}
|
153
|
|
154
|
if($didupdate == true) {
|
155
|
update_status("Update finished. Rebooting...");
|
156
|
exec("/etc/rc.reboot");
|
157
|
} else {
|
158
|
update_status("No updates required.");
|
159
|
}
|
160
|
|
161
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
|
162
|
|
163
|
?>
|