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 = array("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
|
|
50
|
<form action="system_firmware_auto.php" method="post">
|
51
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
52
|
<tr>
|
53
|
<td>
|
54
|
<?php
|
55
|
$tab_array = array();
|
56
|
$tab_array[0] = array("Manual Update", false, "system_firmware.php");
|
57
|
$tab_array[1] = array("Auto Update", true, "system_firmware_check.php");
|
58
|
$tab_array[2] = array("Updater Settings", false, "system_firmware_settings.php");
|
59
|
display_top_tabs($tab_array);
|
60
|
?>
|
61
|
</td>
|
62
|
</tr>
|
63
|
<tr>
|
64
|
<td>
|
65
|
<div id="mainarea">
|
66
|
<table class="tabcont" 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='./themes/<?= $g['theme']; ?>/images/misc/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
|
</div>
|
85
|
</td>
|
86
|
</tr>
|
87
|
</table>
|
88
|
</form>
|
89
|
<?php include("fend.inc"); ?>
|
90
|
</body>
|
91
|
</html>
|
92
|
|
93
|
<?php
|
94
|
|
95
|
/* Define necessary variables. */
|
96
|
$update_types = array('full', 'diff');
|
97
|
$didupdate = false;
|
98
|
|
99
|
if($_GET['category'] == 'full') {
|
100
|
$tocheck = 'all';
|
101
|
$categories = array('firmware', 'kernel', 'base');
|
102
|
} else {
|
103
|
$tocheck = array($_GET['category']);
|
104
|
$categories = $tocheck;
|
105
|
}
|
106
|
|
107
|
$static_output = "Downloading current version information... ";
|
108
|
update_status($static_output);
|
109
|
update_output_window($static_output);
|
110
|
|
111
|
if(file_exists("/tmp/versioncheck.cache")) {
|
112
|
$versions = unserialize("/tmp/versioncheck.cache");
|
113
|
if(time() - $versions['cachetime'] > 300) { // Our cached data is stale, get a new copy.
|
114
|
$versions = check_firmware_version($tocheck);
|
115
|
} else { // Our cached data is relatively currently, remove the cachetime label.
|
116
|
unset($versions['cachetime']);
|
117
|
}
|
118
|
}
|
119
|
|
120
|
$static_output .= "done.\n";
|
121
|
update_output_window($static_output);
|
122
|
|
123
|
foreach($categories as $index => $key) {
|
124
|
$bdiff_errors = array();
|
125
|
if(is_array($versions[$key][0])) { // Make sure we really need to update this section.
|
126
|
$didupdate = true;
|
127
|
update_status("Found required " . $key . " updates. Downloading...");
|
128
|
$static_output .= "Downloading " . $key . " updates... ";
|
129
|
update_output_window($static_output);
|
130
|
foreach($versions[$key] as $ver) { // Begin system updates.
|
131
|
foreach($update_types as $type) if(in_array($type, array_keys($ver))) $url_type = $type;
|
132
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-" . ucfirst($key) . "-Update-" . $ver['version'] . ".tgz";
|
133
|
$static_output_bak = $static_output;
|
134
|
$static_output .= "\n\t" . $ver['version'] . "-" . $ver['name'] . " ";
|
135
|
update_output_window($static_output);
|
136
|
download_file_with_progress_bar("http://www.pfsense.com/updates/" . $tofetch, "/tmp/" . $tofetch);
|
137
|
if($url_type == "binary") {
|
138
|
exec("/etc/rc.firmware delta_update " . "/tmp/" . $tofetch, $bdiff_errors);
|
139
|
if(is_string($bdiff_errors[0])) {
|
140
|
unlink_if_exists("/tmp/" . $tofetch);
|
141
|
$static_output .= "failed!\n";
|
142
|
update_output_window($static_output);
|
143
|
break;
|
144
|
}
|
145
|
} else {
|
146
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-Update-" . $ver['version'] . ".tgz";
|
147
|
exec("/etc/rc.firmware pfSenseupgrade " . "/tmp/" . $tofetch);
|
148
|
unlink_if_exists("/tmp/" . $tofetch);
|
149
|
}
|
150
|
$static_output = $static_output_bak . "done.\n";
|
151
|
}
|
152
|
}
|
153
|
}
|
154
|
|
155
|
if($didupdate == true) {
|
156
|
update_status("Update finished. Rebooting...");
|
157
|
exec("/etc/rc.reboot");
|
158
|
} else {
|
159
|
update_status("No updates required.");
|
160
|
}
|
161
|
|
162
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
|
163
|
?>
|