]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/updates.cgi
5 # This code is distributed under the terms of the GPL
7 # (c) The SmoothWall Team
9 # $Id: updates.cgi,v 1.9.2.22 2005/12/01 20:41:53 franck78 Exp $
16 # enable only the following on debugging purpose
18 #use CGI::Carp 'fatalsToBrowser';
20 require 'CONFIG_ROOT/general-functions.pl';
21 require "${General::swroot}/lang.pl";
22 require "${General::swroot}/header.pl";
24 #workaround to suppress a warning when a variable is used only once
25 my @dummy = ( $General::version
);
32 &Header
::showhttpheaders
();
34 my %uploadsettings=();
35 $uploadsettings{'ACTION'} = '';
37 &Header
::getcgihash
(\
%uploadsettings, {'wantfile' => 1, 'filevar' => 'FH'});
39 if ($uploadsettings{'ACTION'} eq $Lang::tr
{'upload'}) {
40 # This code do not serve a lot because $General::version cannot change while the module is loaded. So no change
41 # can appear. More, this call should be called 'after' update is done !
42 # my $return = &downloadlist();
43 # if ($return && $return->is_success) {
44 # if (open(LIST, ">${General::swroot}/patches/available")){
46 # my @this = split(/----START LIST----\n/,$return->content);
47 # print LIST $this[1];
50 # $errormessage = $Lang::tr{'could not open available updates file'};
53 # if (open(LIST, "<${General::swroot}/patches/available")) {
57 # $warnmessage = $Lang::tr{'could not download the available updates list'};
61 if (copy
($uploadsettings{'FH'}, "/var/patches/patch-$$.tar.gz.gpg") != 1) {
64 my $exitcode = system("/usr/local/bin/installpackage $$ > /dev/null") >> 8;
66 #Hack to get correct version displayed after update
67 open (XX
,"perl -e \"require'${General::swroot}/general-functions.pl';print \\\$General::version\"|");
68 $General::version
=<XX
>;
70 &General
::log("$Lang::tr{'the following update was successfully installed'} ($General::version)");
72 elsif($exitcode == 2) {
73 $errormessage = "$Lang::tr{'could not create directory'}";
75 elsif($exitcode == 3) {
76 $errormessage = "$Lang::tr{'this is not an authorised update'}";
78 elsif($exitcode == 4) {
79 $errormessage = "$Lang::tr{'this is not a valid archive'}";
81 elsif($exitcode == 5) {
82 $errormessage = "$Lang::tr{'could not open update information file'}";
84 elsif($exitcode == 6) {
85 $errormessage = "$Lang::tr{'could not open installed updates file'}";
87 elsif($exitcode == 7) {
88 $errormessage = "$Lang::tr{'this update is already installed'}";
90 elsif($exitcode == 11) {
91 $errormessage = "$Lang::tr{'not enough disk space'}";
93 $errormessage = "$Lang::tr{'package failed to install'}";
97 elsif ($uploadsettings{'ACTION'} eq $Lang::tr
{'refresh update list'}) {
98 my $return = &downloadlist
();
99 if ($return && $return->is_success) {
100 if (open(LIST
, ">${General::swroot}/patches/available")) {
102 my @this = split(/----START LIST----\n/,$return->content);
105 &General
::log($Lang::tr
{'successfully refreshed updates list'});
107 $errormessage = $Lang::tr
{'could not open available updates file'};
110 $errormessage = $Lang::tr
{'could not download the available updates list'};
113 elsif ($uploadsettings{'ACTION'} eq "$Lang::tr{'clear cache'} (squid)") {
114 system('/usr/local/bin/restartsquid','-f');
117 if (!open(AV
, "<${General::swroot}/patches/available")) {
118 $errormessage = $Lang::tr
{'could not open available updates file'};
123 if (!open (PF
, "<${General::swroot}/patches/installed")) {
124 $errormessage = $Lang::tr
{'could not open installed updates file'};
128 #substract installed patch from list displayed (AV list may not be updated)
129 foreach my $P (@pf) {
133 foreach my $A (@av) {
135 if ($1 eq $order) { # match
144 &Header
::openpage
($Lang::tr
{'updates'}, 1, '');
146 &Header
::openbigbox
('100%', 'left', 'download.png', $errormessage);
149 &Header
::openbox
('100%', 'left', $Lang::tr
{'error messages'});
156 &Header
::openbox
('100%', 'LEFT', "$Lang::tr{'warning messages'}:");
157 print "<CLASS NAME='base'>$warnmessage \n";
158 print " </CLASS>\n";
163 &Header
::openbox
('100%', 'left', $Lang::tr
{'available updates'});
165 if ( defined $av[0] ) {
166 print $Lang::tr
{'there are updates available'};
167 print qq|<table width
='100%' border
='0' cellpadding
='2' cellspacing
='0'>
169 <td width
='5%'><b
>$Lang::tr
{'id'}</b></td
>
170 <td width
='15%'><b
>$Lang::tr
{'title'}</b></td
>
171 <td width
='50%'><b
>$Lang::tr
{'description'}</b></td
>
172 <td width
='15%'><b
>$Lang::tr
{'released'}</b></td
>
173 <td width
='15%'> 
;</td
>
177 my @temp = split(/\|/,$_);
178 print "<tr><td valign='top'>$temp[0]</td><td valign='top'>$temp[1]</td><td valign='top'>$temp[2]</td><td valign='top'>$temp[3]</td><td valign='top'><a href='$temp[4]' target='_new'>$Lang::tr{'info'}</a></td></tr>";
184 print $Lang::tr
{'all updates installed'};
188 $Lang::tr
{'to install an update'}
190 <form method
='post' action
='/cgi-bin/updates.cgi' enctype
='multipart/form-data'>
193 <td align
='right' class='base'>
194 <b
>$Lang::tr
{'upload update file'}</b></td
>
195 <td
><input type
="file" size
='40' name
="FH" /> <input type='submit' name='ACTION' value='$Lang::tr{'upload'}' />
199 print "<b>$Lang::tr{'disk usage'}</b>";
200 open (XX
,'df -h / /var/log|');
203 print "<table cellpadding='2'>";
204 map ( $_ =~ s/ +/<td>/g,@df); # tablify each line!
205 print "<tr><td>$df[0]</tr>";
206 print "<tr><td>$df[1]</tr>";
207 print "<tr><td>$df[2]<td><input type='submit' name='ACTION' value='$Lang::tr{'clear cache'} (squid)' /></tr>";
211 print "\n<table width='100%'>\n<tr>";
212 print "\n\t<td width='50%'> </td>";
213 print "\n\t<td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh update list'}' /></td></tr>";
214 print "\n</table>\n";
219 &Header
::openbox
('100%', 'LEFT', $Lang::tr
{'installed updates'});
221 print qq|<table width
='100%' border
='0' cellpadding
='2' cellspacing
='0'>
223 <td width
='5%'><b
>$Lang::tr
{'id'}</b></td
>
224 <td width
='15%'><b
>$Lang::tr
{'title'}</b></td
>
225 <td width
='50%'><b
>$Lang::tr
{'description'}</b></td
>
226 <td width
='15%'><b
>$Lang::tr
{'released'}</b></td
>
227 <td width
='15%'><b
>$Lang::tr
{'installed'}</b></td
>
231 foreach my $pf (@pf) {
232 next if $pf =~ m/^#/;
233 my @temp = split(/\|/,$pf);
234 #??? @av = grep(!/^$temp[0]/, @av);
235 print "<tr><td valign='top'>" . join("</td><td valign='top'>",@temp) . "</td></tr>";
243 &Header
::closebigbox
();
245 &Header
::closepage
();
248 unless (-e
"${General::swroot}/red/active") {
252 my $downloader = LWP
::UserAgent
->new;
253 $downloader->timeout(5);
255 my %proxysettings=();
256 &General
::readhash
("${General::swroot}/proxy/settings", \
%proxysettings);
258 if ($_=$proxysettings{'UPSTREAM_PROXY'}) {
259 my ($peer, $peerport) = (/^(?:[a-zA-Z ]+\:\/\
/)?(?:[A-Za-z0-9\_\.\-]*?(?:\:[A-Za-z0-9\_\.\-]*?)?\@)?([a-zA-Z0-9\.\_\-]*?)(?:\:([0-9]{1,5}))?(?:\/.*?
)?
$/);
260 if ($proxysettings{'UPSTREAM_USER'}) {
261 $downloader->proxy("http","http://$proxysettings{'UPSTREAM_USER'}:$proxysettings{'UPSTREAM_PASSWORD'}@"."$peer:$peerport/");
263 $downloader->proxy("http","http://$peer:$peerport/");
267 return $downloader->get("http://www.ipcop.org/patches/${General::version}", 'Cache-Control', 'no-cache');