]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/updates.cgi
SMP-Config angepasst.. CGIs usw. wurden im Windoof-Format gespeichert... muss noch...
[ipfire-2.x.git] / html / cgi-bin / updates.cgi
CommitLineData
ac1cfefa
MT
1#!/usr/bin/perl
2#
3# SmoothWall CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The SmoothWall Team
8#
9# $Id: updates.cgi,v 1.9.2.22 2005/12/01 20:41:53 franck78 Exp $
10#
11
12use LWP::UserAgent;
13use File::Copy;
14use strict;
15
16# enable only the following on debugging purpose
17#use warnings;
18#use CGI::Carp 'fatalsToBrowser';
19
20require 'CONFIG_ROOT/general-functions.pl';
21require "${General::swroot}/lang.pl";
22require "${General::swroot}/header.pl";
23
24#workaround to suppress a warning when a variable is used only once
25my @dummy = ( $General::version );
26undef (@dummy);
27my $warnmessage='';
28my $errormessage='';
29my @av=('');
30my @pf=('');
31
32&Header::showhttpheaders();
33
34my %uploadsettings=();
35$uploadsettings{'ACTION'} = '';
36
37&Header::getcgihash(\%uploadsettings, {'wantfile' => 1, 'filevar' => 'FH'});
38
39if ($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")){
45# flock LIST, 2;
46# my @this = split(/----START LIST----\n/,$return->content);
47# print LIST $this[1];
48# close(LIST);
49# } else {
50# $errormessage = $Lang::tr{'could not open available updates file'};
51# }
52# } else {
53# if (open(LIST, "<${General::swroot}/patches/available")) {
54# my @list = <LIST>;
55# close(LIST);
56# }
57# $warnmessage = $Lang::tr{'could not download the available updates list'};
58# }
59
60
61 if (copy ($uploadsettings{'FH'}, "/var/patches/patch-$$.tar.gz.gpg") != 1) {
62 $errormessage = $!;
63 } else {
64 my $exitcode = system("/usr/local/bin/installpackage $$ > /dev/null") >> 8;
65 if ($exitcode == 0) {
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>;
69 close (XX);
70 &General::log("$Lang::tr{'the following update was successfully installed'} ($General::version)");
71 }
72 elsif($exitcode == 2) {
73 $errormessage = "$Lang::tr{'could not create directory'}";
74 }
75 elsif($exitcode == 3) {
76 $errormessage = "$Lang::tr{'this is not an authorised update'}";
77 }
78 elsif($exitcode == 4) {
79 $errormessage = "$Lang::tr{'this is not a valid archive'}";
80 }
81 elsif($exitcode == 5) {
82 $errormessage = "$Lang::tr{'could not open update information file'}";
83 }
84 elsif($exitcode == 6) {
85 $errormessage = "$Lang::tr{'could not open installed updates file'}";
86 }
87 elsif($exitcode == 7) {
88 $errormessage = "$Lang::tr{'this update is already installed'}";
89 }
90 elsif($exitcode == 11) {
91 $errormessage = "$Lang::tr{'not enough disk space'}";
92 } else {
93 $errormessage = "$Lang::tr{'package failed to install'}";
94 }
95 }
96}
97elsif ($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")) {
101 flock LIST, 2;
102 my @this = split(/----START LIST----\n/,$return->content);
103 print LIST $this[1];
104 close(LIST);
105 &General::log($Lang::tr{'successfully refreshed updates list'});
106 } else {
107 $errormessage = $Lang::tr{'could not open available updates file'};
108 }
109 } else {
110 $errormessage = $Lang::tr{'could not download the available updates list'};
111 }
112}
113elsif ($uploadsettings{'ACTION'} eq "$Lang::tr{'clear cache'} (squid)") {
114 system('/usr/local/bin/restartsquid','-f');
115}
116
117if (!open(AV, "<${General::swroot}/patches/available")) {
118 $errormessage = $Lang::tr{'could not open available updates file'};
119} else {
120 @av = <AV>;
121 close(AV);
122}
123if (!open (PF, "<${General::swroot}/patches/installed")) {
124 $errormessage = $Lang::tr{'could not open installed updates file'};
125} else {
126 @pf = <PF>;
127 close (PF);
128 #substract installed patch from list displayed (AV list may not be updated)
129 foreach my $P (@pf) {
130 $P =~ /^(...)/;
131 my $order=$1;
132 my $idx=0;
133 foreach my $A (@av) {
134 $A =~ /^(...)/;
135 if ($1 eq $order) { # match
136 splice (@av,$idx,1);
137 last;
138 }
139 $idx++;
140 }
141 }
142}
143
144&Header::openpage($Lang::tr{'updates'}, 1, '');
145
146&Header::openbigbox('100%', 'left', 'download.png', $errormessage);
147
148if ($errormessage) {
149 &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
150 print $errormessage;
151 print "&nbsp;";
152 &Header::closebox();
153}
154
155if ($warnmessage) {
156 &Header::openbox('100%', 'LEFT', "$Lang::tr{'warning messages'}:");
157 print "<CLASS NAME='base'>$warnmessage \n";
158 print "&nbsp;</CLASS>\n";
159 &Header::closebox();
160}
161
162
163&Header::openbox('100%', 'left', $Lang::tr{'available updates'});
164
165if ( defined $av[0] ) {
166 print $Lang::tr{'there are updates available'};
167 print qq|<table width='100%' border='0' cellpadding='2' cellspacing='0'>
168<tr>
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%'>&nbsp;</td>
174</tr>
175|;
176 foreach (@av) {
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>";
179 }
180 print "</table>";
181
182
183} else {
184 print $Lang::tr{'all updates installed'};
185}
186
187print qq|<hr /><br>
188$Lang::tr{'to install an update'}
189<br />
190<form method='post' action='/cgi-bin/updates.cgi' enctype='multipart/form-data'>
191<table>
192<tr>
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'}' />
196</td></tr>
197</table>|;
198
199print "<b>$Lang::tr{'disk usage'}</b>";
200open (XX,'df -h / /var/log|');
201my @df=<XX>;
202close (XX);
203print "<table cellpadding='2'>";
204map ( $_ =~ s/ +/<td>/g,@df); # tablify each line!
205print "<tr><td>$df[0]</tr>";
206print "<tr><td>$df[1]</tr>";
207print "<tr><td>$df[2]<td><input type='submit' name='ACTION' value='$Lang::tr{'clear cache'} (squid)' /></tr>";
208print "</table>";
209
210print "\n<hr />";
211print "\n<table width='100%'>\n<tr>";
212print "\n\t<td width='50%'>&nbsp;</td>";
213print "\n\t<td width='50%' align='center'><input type='submit' name='ACTION' value='$Lang::tr{'refresh update list'}' /></td></tr>";
214print "\n</table>\n";
215print "</form>";
216
217&Header::closebox();
218
219&Header::openbox('100%', 'LEFT', $Lang::tr{'installed updates'});
220
221print qq|<table width='100%' border='0' cellpadding='2' cellspacing='0'>
222<tr>
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>
228</tr>
229|;
230
231foreach 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>";
236}
237close(PF);
238
239print "</table>";
240
241&Header::closebox();
242
243&Header::closebigbox();
244
245&Header::closepage();
246
247sub downloadlist {
248 unless (-e "${General::swroot}/red/active") {
249 return 0;
250 }
251
252 my $downloader = LWP::UserAgent->new;
253 $downloader->timeout(5);
254
255 my %proxysettings=();
256 &General::readhash("${General::swroot}/proxy/settings", \%proxysettings);
257
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/");
262 } else {
263 $downloader->proxy("http","http://$peer:$peerport/");
264 }
265 }
266
267 return $downloader->get("http://www.ipcop.org/patches/${General::version}", 'Cache-Control', 'no-cache');
268
269}