1 |
25682561
|
Scott Ullrich
|
#!/usr/local/bin/php
|
2 |
|
|
<?php
|
3 |
|
|
/* $Id$ */
|
4 |
|
|
/*
|
5 |
|
|
system_firmware_auto.php
|
6 |
853167d2
|
Colin Smith
|
part of pfSense (http://www.pfsense.com)
|
7 |
5c59c339
|
Scott Ullrich
|
|
8 |
222494af
|
Colin Smith
|
Copyright (C) 2005 Scott Ullrich and Colin Smith
|
9 |
5c59c339
|
Scott Ullrich
|
|
10 |
25682561
|
Scott Ullrich
|
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 |
15581b1e
|
Colin Smith
|
|
33 |
|
|
TODO:
|
34 |
|
|
* modify pfSense.com XMLRPC server to return md5 hashes of firmware updates.
|
35 |
25682561
|
Scott Ullrich
|
*/
|
36 |
|
|
|
37 |
36f1a6d7
|
Colin Smith
|
require_once("guiconfig.inc");
|
38 |
233d5b0f
|
Colin Smith
|
require_once("xmlrpc.inc");
|
39 |
25682561
|
Scott Ullrich
|
|
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 |
d40b3c36
|
Colin Smith
|
<p class="pgtitle">System: Firmware: Auto Upgrade</p>
|
53 |
25682561
|
Scott Ullrich
|
|
54 |
|
|
<form action="system_firmware_auto.php" method="post">
|
55 |
3a023f99
|
Colin Smith
|
<table width="100%" border="0" cellpadding="0" cellspacing="0">
|
56 |
|
|
<tr>
|
57 |
|
|
<td>
|
58 |
|
|
<ul id="tabnav">
|
59 |
d9ff08b7
|
Scott Ullrich
|
<li class="tabinact"><a href="system_firmware.php">Manual Update</a></li>
|
60 |
ebe916cf
|
Colin Smith
|
<li class="tabact">Auto Update</a></li>
|
61 |
3a023f99
|
Colin Smith
|
</ul>
|
62 |
|
|
</td>
|
63 |
|
|
</tr>
|
64 |
25682561
|
Scott Ullrich
|
<tr>
|
65 |
|
|
<td class="tabcont">
|
66 |
|
|
<table width="100%" border="0" cellpadding="6" cellspacing="0">
|
67 |
1c0e3b99
|
Scott Ullrich
|
<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 |
222494af
|
Colin Smith
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="1" name="status" id="status" wrap="hard">
|
75 |
853167d2
|
Colin Smith
|
Beginning system autoupdate...
|
76 |
3db58e13
|
Scott Ullrich
|
</textarea>
|
77 |
1c0e3b99
|
Scott Ullrich
|
<!-- command output box -->
|
78 |
222494af
|
Colin Smith
|
<textarea border='1' bordercolordark='#000000' bordercolorlight='#000000' cols="60" rows="25" name="output" id="output" wrap="hard">
|
79 |
3db58e13
|
Scott Ullrich
|
</textarea>
|
80 |
1c0e3b99
|
Scott Ullrich
|
</center>
|
81 |
|
|
</td>
|
82 |
|
|
</tr>
|
83 |
25682561
|
Scott Ullrich
|
</table>
|
84 |
|
|
</td>
|
85 |
|
|
</tr>
|
86 |
1c0e3b99
|
Scott Ullrich
|
</table>
|
87 |
25682561
|
Scott Ullrich
|
</form>
|
88 |
|
|
<?php include("fend.inc"); ?>
|
89 |
|
|
</body>
|
90 |
|
|
</html>
|
91 |
|
|
|
92 |
|
|
<?php
|
93 |
|
|
|
94 |
5c59c339
|
Scott Ullrich
|
/* Define necessary variables. */
|
95 |
d40b3c36
|
Colin Smith
|
$update_types = array('full', 'diff');
|
96 |
ebe916cf
|
Colin Smith
|
$didupdate = false;
|
97 |
d40b3c36
|
Colin Smith
|
|
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 |
cdb0117c
|
Scott Ullrich
|
|
106 |
45497dd7
|
Colin Smith
|
$static_output = "Downloading current version information... ";
|
107 |
|
|
update_status($static_output);
|
108 |
|
|
update_output_window($static_output);
|
109 |
d40b3c36
|
Colin Smith
|
|
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 |
ea041900
|
Colin Smith
|
}
|
118 |
d40b3c36
|
Colin Smith
|
|
119 |
45497dd7
|
Colin Smith
|
$static_output .= "done.\n";
|
120 |
|
|
update_output_window($static_output);
|
121 |
cdb0117c
|
Scott Ullrich
|
|
122 |
d40b3c36
|
Colin Smith
|
foreach($categories as $index => $key) {
|
123 |
1c62837e
|
Colin Smith
|
$bdiff_errors = array();
|
124 |
d40b3c36
|
Colin Smith
|
if(is_array($versions[$key][0])) { // Make sure we really need to update this section.
|
125 |
ebe916cf
|
Colin Smith
|
$didupdate = true;
|
126 |
d40b3c36
|
Colin Smith
|
update_status("Found required " . $key . " updates. Downloading...");
|
127 |
45497dd7
|
Colin Smith
|
$static_output .= "Downloading " . $key . " updates... ";
|
128 |
|
|
update_output_window($static_output);
|
129 |
d40b3c36
|
Colin Smith
|
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 |
b451b6ab
|
Colin Smith
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-" . ucfirst($key) . "-Update-" . $ver['version'] . ".tgz";
|
132 |
45497dd7
|
Colin Smith
|
$static_output_bak = $static_output;
|
133 |
|
|
$static_output .= "\n\t" . $ver['version'] . "-" . $ver['name'] . " ";
|
134 |
|
|
update_output_window($static_output);
|
135 |
d40b3c36
|
Colin Smith
|
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 |
b3a93cb0
|
Colin Smith
|
unlink_if_exists("/tmp/" . $tofetch);
|
140 |
45497dd7
|
Colin Smith
|
$static_output .= "failed!\n";
|
141 |
|
|
update_output_window($static_output);
|
142 |
d40b3c36
|
Colin Smith
|
break;
|
143 |
5f69494b
|
Colin Smith
|
}
|
144 |
d40b3c36
|
Colin Smith
|
} else {
|
145 |
b451b6ab
|
Colin Smith
|
$tofetch = "pfSense-" . ucfirst($url_type) . "-Update-" . $ver['version'] . ".tgz";
|
146 |
d40b3c36
|
Colin Smith
|
exec("/etc/rc.firmware pfSenseupgrade " . "/tmp/" . $tofetch);
|
147 |
b3a93cb0
|
Colin Smith
|
unlink_if_exists("/tmp/" . $tofetch);
|
148 |
5f69494b
|
Colin Smith
|
}
|
149 |
45497dd7
|
Colin Smith
|
$static_output = $static_output_bak . "done.\n";
|
150 |
5f69494b
|
Colin Smith
|
}
|
151 |
ea041900
|
Colin Smith
|
}
|
152 |
|
|
}
|
153 |
ebe916cf
|
Colin Smith
|
|
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 |
853167d2
|
Colin Smith
|
|
161 |
1c0e3b99
|
Scott Ullrich
|
echo "\n<script language=\"JavaScript\">document.progressbar.style.visibility='hidden';\n</script>";
|
162 |
bb76326d
|
Scott Ullrich
|
|
163 |
29f96f5a
|
Colin Smith
|
?>
|