]>
Commit | Line | Data |
---|---|---|
46c01c09 | 1 | #!/usr/bin/perl |
4f4092e3 CS |
2 | # |
3 | # This code is distributed under the terms of the GPL | |
4 | # | |
5 | # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net | |
6 | # | |
7 | # Portions (c) 2008 by dotzball - http://www.blockouttraffic.de | |
8 | # | |
9 | # $Id: updatexlrator.cgi,v 2.1.0 2008/07/16 00:00:00 marco.s Exp $ | |
10 | # | |
70df8302 MT |
11 | ############################################################################### |
12 | # # | |
13 | # IPFire.org - A linux based firewall # | |
75842d01 | 14 | # Copyright (C) 2005-2010 IPFire Team # |
70df8302 MT |
15 | # # |
16 | # This program is free software: you can redistribute it and/or modify # | |
17 | # it under the terms of the GNU General Public License as published by # | |
18 | # the Free Software Foundation, either version 3 of the License, or # | |
19 | # (at your option) any later version. # | |
20 | # # | |
21 | # This program is distributed in the hope that it will be useful, # | |
22 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
23 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
24 | # GNU General Public License for more details. # | |
25 | # # | |
26 | # You should have received a copy of the GNU General Public License # | |
27 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
28 | # # | |
29 | ############################################################################### | |
cfd33ae0 JIW |
30 | # |
31 | # Changelog: | |
32 | # 2012-10-27: nightshift - Bugfix regarding showing wrong vendor icon while Download of new Updates | |
33 | # 2012-10-27: nightshift - Optimizing logic of check for vendor icons | |
34 | # | |
46c01c09 MT |
35 | |
36 | use strict; | |
37 | ||
38 | # enable only the following on debugging purpose | |
5cf2c339 MT |
39 | use warnings; # no warnings 'once';# 'redefine', 'uninitialized'; |
40 | use CGI::Carp 'fatalsToBrowser'; | |
46c01c09 MT |
41 | |
42 | use IO::Socket; | |
43 | ||
44 | require '/var/ipfire/general-functions.pl'; | |
45 | require "${General::swroot}/lang.pl"; | |
46 | require "${General::swroot}/header.pl"; | |
47 | ||
46c01c09 MT |
48 | my %checked=(); |
49 | my %selected=(); | |
50 | my %netsettings=(); | |
51 | my %mainsettings=(); | |
52 | my %proxysettings=(); | |
53 | my %xlratorsettings=(); | |
4f4092e3 | 54 | my %dlinfo=(); |
46c01c09 | 55 | my $id=0; |
0a638396 CS |
56 | my @dfdata=(); |
57 | my $dfstr=''; | |
5cf2c339 MT |
58 | my $dudata=''; |
59 | my $dustr=''; | |
0a638396 CS |
60 | my @updatelist=(); |
61 | my @sources=(); | |
62 | my $sourceurl=''; | |
63 | my $vendorid=''; | |
64 | my $uuid=''; | |
65 | my $status=0; | |
46c01c09 | 66 | my $updatefile=''; |
5cf2c339 | 67 | my $cachefile=''; |
46c01c09 | 68 | my $shortname=''; |
46c01c09 MT |
69 | my $time=''; |
70 | my $filesize=0; | |
71 | my $filedate=''; | |
72 | my $lastaccess=''; | |
73 | my $lastcheck=''; | |
0a638396 CS |
74 | my $cachedtraffic=0; |
75 | my @requests=(); | |
76 | my $data=''; | |
77 | my $counts=0; | |
78 | my $numfiles=0; | |
79 | my $cachehits=0; | |
80 | my $efficiency='0.0'; | |
81 | my @vendors=(); | |
82 | my %vendorstats=(); | |
5cf2c339 | 83 | my %vendimg = (); |
0a638396 | 84 | |
5cf2c339 MT |
85 | my $repository = '/var/updatecache/'; |
86 | my $webhome = '/srv/web/ipfire/html'; | |
87 | my $webimgdir = '/images/updbooster'; | |
46c01c09 | 88 | |
0a638396 | 89 | my $sfUnknown='0'; |
46c01c09 MT |
90 | my $sfOk='1'; |
91 | my $sfOutdated='2'; | |
0a638396 | 92 | my $sfNoSource='3'; |
46c01c09 MT |
93 | |
94 | my $not_accessed_last=''; | |
95 | ||
5cf2c339 | 96 | my @errormessages=(); |
46c01c09 MT |
97 | |
98 | my @repositorylist=(); | |
99 | my @repositoryfiles=(); | |
4f4092e3 CS |
100 | my @downloadlist=(); |
101 | my @downloadfiles=(); | |
46c01c09 MT |
102 | |
103 | my @metadata=(); | |
104 | ||
46c01c09 MT |
105 | &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); |
106 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
107 | &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); | |
108 | ||
109 | $xlratorsettings{'ACTION'} = ''; | |
110 | $xlratorsettings{'ENABLE_LOG'} = 'off'; | |
46c01c09 | 111 | $xlratorsettings{'PASSIVE_MODE'} = 'off'; |
0a638396 | 112 | $xlratorsettings{'MAX_DISK_USAGE'} = '75'; |
46c01c09 | 113 | $xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} = 'off'; |
0a638396 | 114 | $xlratorsettings{'MAX_DOWNLOAD_RATE'} = ''; |
46c01c09 MT |
115 | $xlratorsettings{'ENABLE_AUTOCHECK'} = 'off'; |
116 | $xlratorsettings{'FULL_AUTOSYNC'} = 'off'; | |
117 | $xlratorsettings{'NOT_ACCESSED_LAST'} = 'month1'; | |
4f4092e3 CS |
118 | $xlratorsettings{'REMOVE_NOSOURCE'} = 'off'; |
119 | $xlratorsettings{'REMOVE_OUTDATED'} = 'off'; | |
5cf2c339 MT |
120 | $xlratorsettings{'REMOVE_UNKNOWN'} = 'off'; |
121 | $xlratorsettings{'REMOVE_TODELETE'} = 'off'; | |
122 | $xlratorsettings{'TODELETE'} = 'off'; | |
123 | $xlratorsettings{'show'} = ''; | |
46c01c09 MT |
124 | |
125 | &Header::getcgihash(\%xlratorsettings); | |
126 | ||
5cf2c339 MT |
127 | # ------------------------------------------------------ |
128 | # Check if some ACTION is required | |
129 | # ------------------------------------------------------ | |
46c01c09 MT |
130 | |
131 | if ($xlratorsettings{'ACTION'} eq $Lang::tr{'save'}) | |
5cf2c339 MT |
132 | { &chksettings('save',\@errormessages); |
133 | $xlratorsettings{'show'} = 'settings'; | |
134 | } | |
135 | elsif ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr save and restart'}) | |
136 | { &chksettings('saverestart',\@errormessages); | |
137 | $xlratorsettings{'show'} = 'settings'; | |
138 | } | |
139 | elsif ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr cancel download'}) | |
140 | { &canceldownload($xlratorsettings{'ID'}); | |
141 | $xlratorsettings{'show'} = 'overview'; | |
142 | } | |
143 | elsif (($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr purge'}) | |
144 | && (($xlratorsettings{'REMOVE_UNKNOWN'} eq 'on') | |
145 | || ($xlratorsettings{'REMOVE_NOSOURCE'} eq 'on') | |
146 | || ($xlratorsettings{'REMOVE_OUTDATED'} eq 'on') | |
147 | || ($xlratorsettings{'REMOVE_TODELETE'} eq 'on'))) | |
148 | { &delolddata(); | |
149 | $xlratorsettings{'show'} = 'maintenance'; | |
150 | } | |
46c01c09 | 151 | |
5cf2c339 MT |
152 | # ------------------------------------------------------ |
153 | # ACTION Check - End | |
154 | # ------------------------------------------------------ | |
46c01c09 | 155 | |
5cf2c339 MT |
156 | $not_accessed_last = $xlratorsettings{'NOT_ACCESSED_LAST'}; |
157 | undef($xlratorsettings{'NOT_ACCESSED_LAST'}); | |
46c01c09 | 158 | |
5cf2c339 MT |
159 | if (-e "${General::swroot}/updatexlrator/settings") { |
160 | &General::readhash("${General::swroot}/updatexlrator/settings", \%xlratorsettings); | |
46c01c09 MT |
161 | } |
162 | ||
5cf2c339 | 163 | if ($xlratorsettings{'NOT_ACCESSED_LAST'} eq '') { $xlratorsettings{'NOT_ACCESSED_LAST'} = $not_accessed_last; } |
0a638396 | 164 | |
5cf2c339 MT |
165 | if ($xlratorsettings{'show'} eq 'overview') { $xlratorsettings{'EXTENDED_GUI'} = 'overview'; } |
166 | elsif ($xlratorsettings{'show'} eq 'statistics') { $xlratorsettings{'EXTENDED_GUI'} = 'statistics'; } | |
167 | elsif ($xlratorsettings{'show'} eq 'settings') { $xlratorsettings{'EXTENDED_GUI'} = 'settings'; } | |
168 | elsif ($xlratorsettings{'show'} eq 'maintenance') { $xlratorsettings{'EXTENDED_GUI'} = 'maintenance'; } | |
169 | else { $xlratorsettings{'EXTENDED_GUI'} = $xlratorsettings{'VIEW_SETTING'}?$xlratorsettings{'VIEW_SETTING'}:'overview'; } | |
46c01c09 | 170 | |
5cf2c339 | 171 | &initvendimg; |
46c01c09 | 172 | |
5cf2c339 MT |
173 | # ---------------------------------------------------- |
174 | # Start Page Output | |
175 | # ---------------------------------------------------- | |
4f4092e3 | 176 | |
5cf2c339 MT |
177 | &Header::showhttpheaders(); |
178 | &Header::openpage($Lang::tr{'updxlrtr configuration'}, 1, '<link rel=\'stylesheet\' type=\'text/css\' href=\'/themes/'.$mainsettings{'THEME'}.'/include/upxlr.css\' />' ); | |
179 | &Header::openbigbox('100%', 'left', '', scalar(@errormessages)); | |
4f4092e3 | 180 | |
5cf2c339 MT |
181 | # ===================================================================================== |
182 | # CACHE OVERVIEW | |
183 | # ===================================================================================== | |
4f4092e3 | 184 | |
5cf2c339 MT |
185 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'overview') { |
186 | &Header::openbox('100%', 'left', $Lang::tr{'updxlrtr cache overview'}); | |
187 | &printfrmview(); | |
188 | &printerrormsgs(\@errormessages); | |
189 | &printtbldiskusage ($Lang::tr{'updxlrtr disk usage'},\$repository); | |
190 | &initdownloaddata(\@downloadfiles); | |
191 | &printtbldownloads(\@downloadfiles); | |
192 | &Header::closebox(); | |
193 | } | |
4f4092e3 | 194 | |
5cf2c339 MT |
195 | # ===================================================================================== |
196 | # CACHE STATISTICS | |
197 | # ===================================================================================== | |
4f4092e3 | 198 | |
5cf2c339 MT |
199 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'statistics') { |
200 | &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr cache statistics'}"); | |
201 | &printfrmview(); | |
202 | &printerrormsgs(\@errormessages); | |
203 | &initcachestats(); | |
204 | &printcachestatistics(); | |
205 | &Header::closebox(); | |
206 | } | |
4f4092e3 | 207 | |
5cf2c339 MT |
208 | # ===================================================================================== |
209 | # CACHE MAINTENANCE | |
210 | # ===================================================================================== | |
46c01c09 | 211 | |
5cf2c339 MT |
212 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'maintenance') { |
213 | &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr cache maintenance'}"); | |
214 | &printfrmview(); | |
215 | &printerrormsgs(\@errormessages); | |
216 | &initfrmmaintenance(); | |
217 | &inittblreposdata(); | |
218 | &printfrmmaintenance('withfiles', \@repositoryfiles); | |
219 | &Header::closebox(); | |
220 | } | |
46c01c09 | 221 | |
5cf2c339 MT |
222 | # ===================================================================================== |
223 | # CACHE SETTINGS | |
224 | # ===================================================================================== | |
46c01c09 | 225 | |
5cf2c339 MT |
226 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'settings') { |
227 | &Header::openbox('100%', 'left', $Lang::tr{'updxlrtr cache settings'}); | |
228 | &printfrmview(); | |
229 | &printerrormsgs(\@errormessages); | |
230 | &initfrmsettings(); | |
231 | &printfrmsettings(); | |
232 | &Header::closebox(); | |
233 | } | |
46c01c09 MT |
234 | |
235 | # ---------------------------------------------------- | |
5cf2c339 | 236 | # End Page Output |
46c01c09 | 237 | # ---------------------------------------------------- |
5cf2c339 MT |
238 | &Header::closebigbox(); |
239 | &Header::closepage(); | |
46c01c09 | 240 | |
5cf2c339 MT |
241 | # ------------------------------------------------------------------- |
242 | # Print Form to switch view | |
243 | # ------------------------------------------------------------------- | |
46c01c09 | 244 | |
5cf2c339 MT |
245 | sub printfrmview { |
246 | print <<END | |
247 | <form class='frmshow' method='get' action='$ENV{'SCRIPT_NAME'}'> | |
248 | <fieldset class='noborder'> | |
249 | <legend><span>$Lang::tr{'updxlrtr current view'}:</span></legend> | |
0a638396 CS |
250 | END |
251 | ; | |
5cf2c339 MT |
252 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'overview') |
253 | { print "<button id='oview' class='symbols' disabled='disabled'>$Lang::tr{'updxlrtr overview'}</button>\n"; } | |
254 | else | |
255 | { print "<button id='oview' class='symbols' type='submit' name='show' value='overview'>$Lang::tr{'updxlrtr overview'}</button>\n"; } | |
256 | ||
257 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'statistics') | |
258 | { print "<button id='stat' class='symbols' disabled='disabled'>$Lang::tr{'updxlrtr statistics'}</button>\n"; } | |
259 | else | |
260 | { print "<button id='stat' class='symbols' type='submit' name='show' value='statistics'>$Lang::tr{'updxlrtr statistics'}</button>\n"; } | |
261 | ||
262 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'maintenance') | |
263 | { print "<button id='wrench' class='symbols' disabled='disabled'>$Lang::tr{'updxlrtr maintenance'}</button>\n"; } | |
264 | else | |
265 | { print "<button id='wrench' class='symbols' type='submit' name='show' value='maintenance'>$Lang::tr{'updxlrtr maintenance'}</button>\n"; } | |
266 | ||
267 | if ($xlratorsettings{'EXTENDED_GUI'} eq 'settings') | |
268 | { print "<button id='set' class='symbols' disabled='disabled'>$Lang::tr{'updxlrtr settings'}</button>\n"; } | |
269 | else | |
270 | { print "<button id='set' class='symbols' type='submit' name='show' value='settings'>$Lang::tr{'updxlrtr settings'}</button>\n"; } | |
271 | print <<END | |
272 | </fieldset> | |
273 | </form> | |
0a638396 CS |
274 | END |
275 | ; | |
5cf2c339 MT |
276 | return; |
277 | } | |
0a638396 | 278 | |
5cf2c339 MT |
279 | # ------------------------------------------------------------------- |
280 | # Print Error Messages - printerrormsgs(\@errormsgs) | |
281 | # ------------------------------------------------------------------- | |
4f4092e3 | 282 | |
5cf2c339 MT |
283 | sub printerrormsgs { |
284 | my $errmsgs_ref = shift; | |
285 | unless (@$errmsgs_ref == 0) { | |
286 | &Header::openbox('100%', 'left', ''); | |
4f4092e3 | 287 | print <<END |
5cf2c339 | 288 | <div id='errors'><strong>$Lang::tr{'error messages'}</strong><br /> |
4f4092e3 CS |
289 | END |
290 | ; | |
5cf2c339 MT |
291 | foreach (@$errmsgs_ref) { print "$_<br />"; } |
292 | undef(@$errmsgs_ref); | |
293 | print "\t\t\t</div>\n"; | |
294 | &Header::closebox(); | |
295 | } | |
296 | } | |
cfd33ae0 | 297 | |
5cf2c339 MT |
298 | # ------------------------------------------------------------------- |
299 | # Initialize Downloaddata | |
300 | # ------------------------------------------------------------------- | |
4f4092e3 | 301 | |
5cf2c339 MT |
302 | sub initdownloaddata { |
303 | @downloadlist = <$repository/download/*>; | |
304 | my $updfile; | |
305 | my $dlfiles_ref = shift; | |
306 | undef(@$dlfiles_ref); | |
307 | foreach (@downloadlist) { | |
308 | if (-d) { | |
309 | my @filelist = <$_/*>; | |
310 | $vendorid = substr($_,rindex($_,"/")+1); | |
311 | foreach(@filelist) { | |
312 | next if(/\.info$/); | |
313 | $updfile = substr($_,rindex($_,"/")+1); | |
314 | $updfile .= ":download/$vendorid/$updfile"; | |
315 | $updfile = " ".$updfile; | |
316 | push(@$dlfiles_ref, $updfile); | |
317 | } | |
318 | } | |
319 | } | |
320 | } | |
4f4092e3 | 321 | |
5cf2c339 MT |
322 | # ------------------------------------------------------------------- |
323 | # Print pending Downloadlist | |
324 | # ------------------------------------------------------------------- | |
4f4092e3 | 325 | |
5cf2c339 MT |
326 | sub printtbldownloads { |
327 | my $dllist_ref = shift; | |
328 | print <<END | |
329 | <table id='listuploads'> | |
330 | <caption>$Lang::tr{'updxlrtr current downloads'}</caption> | |
331 | <thead> | |
332 | <tr> | |
333 | <th>$Lang::tr{'status'}</th> | |
334 | <th>$Lang::tr{'updxlrtr source'}</th> | |
335 | <th>$Lang::tr{'updxlrtr filename'}</th> | |
336 | <th>$Lang::tr{'updxlrtr filesize'}</th> | |
337 | <th>$Lang::tr{'date'}</th> | |
338 | <th>$Lang::tr{'updxlrtr progress'}</th> | |
339 | <th> </th> | |
340 | </tr> | |
341 | </thead> | |
342 | <tfoot> | |
343 | <tr> | |
344 | <td colspan='7' id='legenddownload'> | |
4f4092e3 CS |
345 | END |
346 | ; | |
5cf2c339 MT |
347 | &printlegenddownload(); |
348 | print <<END | |
4f4092e3 CS |
349 | </td> |
350 | </tr> | |
5cf2c339 MT |
351 | </tfoot> |
352 | <tbody> | |
353 | END | |
354 | ; | |
355 | &printtbldldata($dllist_ref); | |
356 | print <<END | |
357 | </tbody> | |
358 | </table> | |
4f4092e3 CS |
359 | END |
360 | ; | |
4f4092e3 | 361 | } |
0a638396 | 362 | |
5cf2c339 MT |
363 | # ------------------------------------------------------------------- |
364 | # Print Download Files - printdlfiles(\@dlfiles) | |
365 | # ------------------------------------------------------------------- | |
0a638396 | 366 | |
5cf2c339 MT |
367 | sub printtbldldata { |
368 | my $dlfiles_ref = shift; | |
369 | unless (@$dlfiles_ref) | |
370 | { print "<tr>\n<th colspan=\"7\">".$Lang::tr{'updxlrtr no pending downloads attime'}."</th>\n</tr>\n"; } | |
371 | else { | |
372 | $id = 0; | |
373 | foreach $updatefile (@$dlfiles_ref) { | |
374 | print "<tr>\n"; | |
375 | $updatefile =~ s/.*://; | |
376 | my $size_updatefile = 0; | |
377 | my $mtime = 0; | |
378 | ||
379 | if(-e "$repository/$updatefile") { | |
380 | $size_updatefile = (-s "$repository/$updatefile"); | |
381 | $mtime = &getmtime("$repository/$updatefile"); | |
382 | } | |
383 | ||
384 | if (-e "$repository/$updatefile.info") { &General::readhash("$repository/$updatefile.info", \%dlinfo); } | |
385 | else { undef(%dlinfo); } | |
386 | ||
387 | $filesize = $size_updatefile; | |
388 | 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; | |
389 | my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($mtime); | |
390 | my $percent = '0'; | |
391 | $DAYdt = sprintf ("%.02d",$DAYdt); | |
392 | $MONTHdt = sprintf ("%.02d",$MONTHdt+1); | |
393 | $YEARdt = sprintf ("%.04d",$YEARdt+1900); | |
394 | $filedate = $DAYdt.".".$MONTHdt.".".$YEARdt; | |
395 | ($uuid,$vendorid,$shortname) = split('/',$updatefile); | |
396 | $shortname = substr($updatefile,rindex($updatefile,"/")+1); | |
397 | $shortname =~ s/(.*)_([\da-f]{8})*(\.(exe|cab|psf|msu)$)/$1_$2*$3/i; | |
398 | unless (length($shortname) <= 50) { | |
399 | my $fext = substr($shortname,rindex("$shortname",'.')); | |
400 | $shortname = substr($shortname,0,44-length($fext)); | |
401 | $shortname .= "[...] $fext"; | |
402 | } | |
403 | $filesize = $dlinfo{'REMOTESIZE'}; | |
404 | 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; | |
405 | $dlinfo{'VENDORID'} = ucfirst $vendorid; | |
406 | if ($dlinfo{'REMOTESIZE'} && $size_updatefile) { $percent = int(100 / ($dlinfo{'REMOTESIZE'} / $size_updatefile)); } | |
407 | ||
408 | if (&getPID("\\s/usr/bin/wget\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\$")) | |
409 | { print '<th><span id="ledbl" class="symbols" title="'.$Lang::tr{'updxlrtr condition download'}."\"></span></th>\n"; } | |
410 | else { print '<th><span id="ledgy" class="symbols" title="'.$Lang::tr{'updxlrtr condition suspended'}."\"></span></th>\n"; } | |
411 | ||
412 | if ($vendimg{$vendorid}) | |
413 | { print '<th><span id="vd$id" class="vendimg" style="background-image: url('.$vendimg{$vendorid}.');" title="'.ucfirst $vendorid.'">'.ucfirst $dlinfo{'VENDORID'}."</span></th>\n"; } | |
414 | else { print '<th><span id="vd$id" class="vendimg" style="background-image: url('.$vendimg{'unknown'}.');" title="'.ucfirst $vendorid.'">'.ucfirst $dlinfo{'VENDORID'}."</span></th>\n"; } | |
415 | print <<END | |
416 | <td title="cache:/$updatefile">$shortname</td> | |
417 | <td>$filesize</td> | |
418 | <td>$filedate</td> | |
419 | <td> | |
420 | END | |
421 | ; | |
422 | &percentbar($percent); | |
423 | print <<END | |
424 | </td> | |
425 | <th> | |
426 | <form method='post' id='del$id' action='$ENV{'SCRIPT_NAME'}'> | |
427 | <div> | |
428 | <button id='del$id' class='symbols' type='submit' title='$Lang::tr{'updxlrtr cancel download'}'></button> | |
429 | <input type='hidden' name='ID' value='$updatefile' /> | |
430 | <input type='hidden' name='ACTION' value='$Lang::tr{'updxlrtr cancel download'}' /> | |
431 | </div> | |
432 | </form> | |
433 | </th> | |
434 | </tr> | |
435 | END | |
436 | ; | |
437 | $id += 1; | |
438 | } | |
439 | } | |
0a638396 CS |
440 | } |
441 | ||
5cf2c339 MT |
442 | # ------------------------------------------------------------------- |
443 | # Initialize Cachestats | |
444 | # ------------------------------------------------------------------- | |
0a638396 | 445 | |
5cf2c339 MT |
446 | sub initcachestats { |
447 | @sources=(); | |
448 | foreach (<$repository/*>) { | |
449 | if (-d $_) { | |
450 | unless ((/^$repository\/download$/) || (/^$repository\/lost\+found$/)) { push(@sources,$_); } | |
451 | } | |
452 | } | |
453 | @vendors=(); | |
454 | foreach (@sources) | |
455 | { | |
456 | $vendorid=substr($_,rindex($_,'/')+1,length($_)); | |
457 | push(@vendors,$vendorid); | |
458 | $vendorstats{$vendorid."_filesize"} = 0; | |
459 | $vendorstats{$vendorid."_requests"} = 0; | |
460 | $vendorstats{$vendorid."_files"} = 0; | |
461 | $vendorstats{$vendorid."_cachehits"} = 0; | |
462 | $vendorstats{$vendorid."_0"} = 0; | |
463 | $vendorstats{$vendorid."_1"} = 0; | |
464 | $vendorstats{$vendorid."_2"} = 0; | |
465 | $vendorstats{$vendorid."_3"} = 0; | |
466 | @updatelist=<$_/*>; | |
467 | foreach $data (@updatelist) { | |
468 | if (-e "$data/source.url") { | |
469 | open (FILE,"$data/source.url"); | |
470 | $sourceurl=<FILE>; | |
471 | close FILE; | |
472 | chomp($sourceurl); | |
473 | $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); | |
474 | my $size_updatefile = 0; | |
475 | if(-e "$data/$updatefile") { | |
476 | $size_updatefile = (-s "$data/$updatefile"); | |
477 | } | |
478 | else { | |
479 | # DEBUG | |
480 | #die "file not found: $data/$updatefile\n"; | |
481 | } | |
482 | # | |
483 | # Total file size | |
484 | # | |
485 | $filesize += $size_updatefile; | |
486 | # | |
487 | # File size for this source | |
488 | # | |
489 | $vendorstats{$vendorid."_filesize"} += $size_updatefile; | |
490 | # | |
491 | # Number of requests from cache for this source | |
492 | # | |
493 | open (FILE,"$data/access.log"); | |
494 | @requests=<FILE>; | |
495 | close FILE; | |
496 | chomp(@requests); | |
497 | $counts = @requests; | |
498 | $counts--; | |
499 | $vendorstats{$vendorid."_requests"} += $counts; | |
500 | $cachehits += $counts; | |
501 | # | |
502 | # Total number of files in cache | |
503 | # | |
504 | $numfiles++; | |
505 | # | |
506 | # Number of files for this source | |
507 | # | |
508 | $vendorstats{$vendorid."_files"}++; | |
509 | # | |
510 | # Count cache status occurences | |
511 | # | |
512 | open (FILE,"$data/status"); | |
513 | $_=<FILE>; | |
514 | close FILE; | |
515 | chomp; | |
516 | $vendorstats{$vendorid."_".$_}++; | |
517 | # | |
518 | # Calculate cached traffic for this source | |
519 | # | |
520 | $vendorstats{$vendorid."_cachehits"} += $counts * $size_updatefile; | |
521 | # | |
522 | # Calculate total cached traffic | |
523 | # | |
524 | $cachedtraffic += $counts * $size_updatefile; | |
525 | } | |
526 | } | |
527 | } | |
528 | if ($numfiles) { $efficiency = sprintf("%.1f", $cachehits / $numfiles); } | |
0a638396 CS |
529 | } |
530 | ||
0a638396 | 531 | # ---------------------------------------------------- |
5cf2c339 | 532 | # Print statistics |
0a638396 CS |
533 | # ---------------------------------------------------- |
534 | ||
5cf2c339 MT |
535 | sub printcachestatistics { |
536 | if ($numfiles) { | |
537 | $filesize = &format_size($filesize); | |
538 | $cachedtraffic = &format_size($cachedtraffic); | |
539 | print <<END | |
540 | <table id='summary'> | |
541 | <caption>$Lang::tr{'updxlrtr summary'}</caption> | |
542 | <tbody> | |
543 | <tr> | |
544 | <th>$Lang::tr{'updxlrtr total files'}:</th> | |
545 | <td>$numfiles</td> | |
546 | <th>$Lang::tr{'updxlrtr total cache size'}:</th> | |
547 | <td align='right'>$filesize</td> | |
548 | </tr> | |
549 | <tr> | |
550 | <th>$Lang::tr{'updxlrtr efficiency index'}:</th> | |
551 | <td>$efficiency</td> | |
552 | <th>$Lang::tr{'updxlrtr total data from cache'}:</th> | |
553 | <td>$cachedtraffic</td> | |
554 | </tr> | |
555 | </tbody> | |
0a638396 | 556 | </table> |
5cf2c339 MT |
557 | <hr /> |
558 | <table id='liststatbysrc'> | |
559 | <caption>$Lang::tr{'updxlrtr statistics by source'}</caption> | |
560 | <colgroup> | |
561 | <col></col> | |
562 | <col></col> | |
563 | <col></col> | |
564 | <col></col> | |
565 | <col span='4' style='width: 40px'></col> | |
566 | </colgroup> | |
567 | <thead> | |
568 | <tr> | |
569 | <th>$Lang::tr{'updxlrtr source'}</th> | |
570 | <th>$Lang::tr{'updxlrtr files'}</th> | |
571 | <th>$Lang::tr{'updxlrtr cache size'}</th> | |
572 | <th>$Lang::tr{'updxlrtr data from cache'}</th> | |
573 | <th><span id='ledgr' class='symbols' title='$Lang::tr{'updxlrtr condition ok'}'></span></th> | |
574 | <th><span id='ledye' class='symbols' title='$Lang::tr{'updxlrtr condition nosource'}'></span></th> | |
575 | <th><span id='ledrd' class='symbols' title='$Lang::tr{'updxlrtr condition outdated'}'></span></th> | |
576 | <th><span id='ledgy' class='symbols' title='$Lang::tr{'updxlrtr condition unknown'}'></span></th> | |
577 | </tr> | |
578 | </thead> | |
579 | <tfoot> | |
580 | <tr> | |
581 | <td colspan='8' id='legendstatus'> | |
0a638396 CS |
582 | END |
583 | ; | |
5cf2c339 MT |
584 | &printlegendstatus(); |
585 | print <<END | |
586 | </td> | |
587 | </tr> | |
588 | </tfoot> | |
589 | <tbody> | |
0a638396 CS |
590 | END |
591 | ; | |
5cf2c339 | 592 | &printtblstatdata(\@vendors); |
0a638396 | 593 | print <<END |
5cf2c339 | 594 | </tbody> |
46c01c09 | 595 | </table> |
0a638396 CS |
596 | END |
597 | ; | |
5cf2c339 | 598 | } |
0a638396 | 599 | |
5cf2c339 MT |
600 | sub printtblstatdata { |
601 | my $vendlst_ref = shift; | |
602 | my $vendorid; | |
603 | $id = 0; | |
604 | unless (@$vendlst_ref) { print "<tr>\n<th colspan='8'>$Lang::tr{'updxlrtr empty repository'}.</th>\n</tr>\n"; } | |
0a638396 | 605 | else { |
5cf2c339 MT |
606 | foreach (@$vendlst_ref) { |
607 | $vendorid = $_; | |
608 | unless ($vendorstats{$vendorid . "_files"}) { next; } | |
609 | print "\t<tr>\n"; | |
610 | if ($vendimg{$vendorid}) | |
611 | { print "\t\t<th><span id='vd$id' class='vendimg' style='background-image: url($vendimg{$vendorid});' title='".ucfirst $vendorid."'>". ucfirst $vendorid ."</span></th>\n"; } | |
612 | else { print "\t\t<th><span id='vd$id' class='vendimg' style='background-image: url($vendimg{'unknown'});' title='".ucfirst $vendorid."'>". ucfirst $vendorid ."</span></th>\n"; } | |
613 | print "\t\t<td>"; | |
614 | printf "%5d", $vendorstats{$vendorid."_files"}; | |
615 | print "</td>\n"; | |
616 | unless ($vendorstats{$vendorid."_filesize"}) { $vendorstats{$vendorid."_filesize"} = '0'; } | |
617 | print "\t\t<td>"; | |
618 | print &format_size($vendorstats{$vendorid."_filesize"}); | |
619 | print "</td>\n"; | |
620 | unless ($vendorstats{$vendorid."_cachehits"}) { $vendorstats{$vendorid."_cachehits"} = '0'; } | |
621 | print "\t\t<td>"; | |
622 | print &format_size($vendorstats{$vendorid."_cachehits"}); | |
623 | print "</td>\n"; | |
624 | print "\t\t<td>"; | |
625 | printf "%5d", $vendorstats{$vendorid."_1"}; | |
626 | print "</td>\n"; | |
627 | print "\t\t<td>"; | |
628 | printf "%5d", $vendorstats{$vendorid."_3"}; | |
629 | print "</td>\n"; | |
630 | print "\t\t<td>"; | |
631 | printf "%5d", $vendorstats{$vendorid."_2"}; | |
632 | print "</td>\n"; | |
633 | print "\t\t<td>"; | |
634 | printf "%5d", $vendorstats{$vendorid."_0"}; | |
635 | print "</td>\n"; | |
636 | print "\t</tr>\n"; | |
637 | $id += 1; | |
0a638396 | 638 | } |
0a638396 | 639 | } |
5cf2c339 | 640 | } |
0a638396 | 641 | } |
5cf2c339 MT |
642 | # ------------------------------------------------------------------- |
643 | # Initialize Repositorydata | |
644 | # ------------------------------------------------------------------- | |
0a638396 | 645 | |
5cf2c339 MT |
646 | sub inittblreposdata { |
647 | @sources = <$repository/download/*>; | |
648 | undef @repositoryfiles; | |
649 | foreach (@sources) { | |
650 | if (-d) { | |
651 | @updatelist = <$_/*>; | |
652 | $vendorid = substr($_,rindex($_,"/")+1); | |
653 | foreach(@updatelist) { | |
654 | next if(/\.info$/); | |
655 | $updatefile = substr($_,rindex($_,"/")+1); | |
656 | $updatefile .= ":download/$vendorid/$updatefile"; | |
657 | $updatefile = " ".$updatefile; | |
658 | push(@repositoryfiles,$updatefile); | |
659 | } | |
660 | } | |
661 | } | |
0a638396 | 662 | |
5cf2c339 MT |
663 | undef (@sources); |
664 | foreach (<$repository/*>) { | |
665 | if (-d $_) { | |
666 | unless (/^$repository\/download$/) { push(@sources,$_); } | |
667 | } | |
668 | } | |
46c01c09 | 669 | |
5cf2c339 MT |
670 | foreach (@sources) { |
671 | @updatelist=<$_/*>; | |
672 | $vendorid = substr($_,rindex($_,"/")+1); | |
673 | foreach(@updatelist) { | |
674 | $uuid = substr($_,rindex($_,"/")+1); | |
675 | if (-e "$_/source.url") { | |
676 | open (FILE,"$_/source.url"); | |
677 | $sourceurl=<FILE>; | |
678 | close FILE; | |
679 | chomp($sourceurl); | |
680 | $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); | |
681 | $_ = $updatefile; tr/[A-Z]/[a-z]/; | |
682 | $updatefile = "$_:$vendorid/$uuid/$updatefile"; | |
683 | push(@repositoryfiles,$updatefile); | |
684 | } | |
685 | } | |
686 | } | |
687 | @repositoryfiles = sort { ($a =~ /.*?:(.*\/).*?/)[0] cmp ($b =~ /.*?:(.*\/).*?/)[0] } @repositoryfiles; | |
0a638396 CS |
688 | } |
689 | ||
5cf2c339 MT |
690 | # ------------------------------------------------------------------- |
691 | # Initialize Cache-Maintenance Form | |
692 | # ------------------------------------------------------------------- | |
46c01c09 | 693 | |
5cf2c339 MT |
694 | sub initfrmmaintenance { |
695 | $selected{'NOT_ACCESSED_LAST'}{'week'} = ''; | |
696 | $selected{'NOT_ACCESSED_LAST'}{'month1'} = ''; | |
697 | $selected{'NOT_ACCESSED_LAST'}{'month3'} = ''; | |
698 | $selected{'NOT_ACCESSED_LAST'}{'month6'} = ''; | |
699 | $selected{'NOT_ACCESSED_LAST'}{'year'} = ''; | |
700 | $selected{'NOT_ACCESSED_LAST'}{$xlratorsettings{'NOT_ACCESSED_LAST'}} = "selected='selected'"; | |
701 | $checked{'REMOVE_NOSOURCE'}{'off'} = ''; | |
702 | $checked{'REMOVE_NOSOURCE'}{'on'} = ''; | |
703 | $checked{'REMOVE_NOSOURCE'}{$xlratorsettings{'REMOVE_NOSOURCE'}} = "checked='checked'"; | |
704 | $checked{'REMOVE_OUTDATED'}{'off'} = ''; | |
705 | $checked{'REMOVE_OUTDATED'}{'on'} = ''; | |
706 | $checked{'REMOVE_OUTDATED'}{$xlratorsettings{'REMOVE_OUTDATED'}} = "checked='checked'"; | |
707 | $checked{'REMOVE_UNKNOWN'}{'off'} = ''; | |
708 | $checked{'REMOVE_UNKNOWN'}{'on'} = ''; | |
709 | $checked{'REMOVE_UNKNOWN'}{$xlratorsettings{'REMOVE_UNKNOWN'}} = "checked='checked'"; | |
710 | $checked{'REMOVE_TODELETE'}{'off'} = ''; | |
711 | $checked{'REMOVE_TODELETE'}{'on'} = ''; | |
712 | $checked{'REMOVE_TODELETE'}{$xlratorsettings{'REMOVE_TODELETE'}} = "checked='checked'"; | |
713 | $checked{'TODELETE'}{'off'} = ''; | |
714 | $checked{'TODELETE'}{'on'} = ''; | |
715 | $checked{'TODELETE'}{$xlratorsettings{'TODELETE'}} = "checked='checked'"; | |
46c01c09 MT |
716 | } |
717 | ||
5cf2c339 MT |
718 | # ------------------------------------------------------------------- |
719 | # Print Cache-Maintenance Form - printfrmmaintenance('withfiles', \@repositoryfiles) | |
720 | # ------------------------------------------------------------------- | |
46c01c09 | 721 | |
5cf2c339 MT |
722 | sub printfrmmaintenance { |
723 | my $param = shift; | |
724 | my $repos_ref = shift; | |
725 | my $disabled = ''; | |
726 | unless (@$repos_ref) { $disabled = "disabled='disabled'"; } | |
727 | print <<END | |
728 | <form method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'> | |
729 | <fieldset> | |
730 | <legend>$Lang::tr{'updxlrtr all files'}</legend> | |
731 | <input id='check08' type='checkbox' name='REMOVE_UNKNOWN' $checked{'REMOVE_UNKNOWN'}{'on'} $disabled/> | |
732 | <label for='check08'>$Lang::tr{'updxlrtr not accessed'}:</label> | |
733 | <select id='select02' name='NOT_ACCESSED_LAST' $disabled> | |
734 | <option value='week' $selected{'NOT_ACCESSED_LAST'}{'week'}>$Lang::tr{'updxlrtr week'}</option> | |
735 | <option value='month1' $selected{'NOT_ACCESSED_LAST'}{'month1'}>$Lang::tr{'updxlrtr month'}</option> | |
736 | <option value='month3' $selected{'NOT_ACCESSED_LAST'}{'month3'}>$Lang::tr{'updxlrtr 3 months'}</option> | |
737 | <option value='month6' $selected{'NOT_ACCESSED_LAST'}{'month6'}>$Lang::tr{'updxlrtr 6 months'}</option> | |
738 | <option value='year' $selected{'NOT_ACCESSED_LAST'}{'year'}>$Lang::tr{'updxlrtr year'}</option> | |
739 | </select> | |
740 | </fieldset> | |
741 | <fieldset> | |
742 | <legend>$Lang::tr{'updxlrtr marked as'} ...</legend> | |
743 | <input id='check09' type='checkbox' name='REMOVE_NOSOURCE' $disabled/> | |
744 | <label id='lbledye' class='symbols' for='check09'>$Lang::tr{'updxlrtr condition nosource'}</label> | |
745 | <input id='check10' type='checkbox' name='REMOVE_OUTDATED' $disabled/> | |
746 | <label id='lbledrd' class='symbols' for='check10'>$Lang::tr{'updxlrtr condition outdated'}</label> | |
747 | <input id='check11' type='checkbox' name='REMOVE_UNKNOWN' $disabled/> | |
748 | <label id='lbledgy' class='symbols' for='check11'>$Lang::tr{'updxlrtr condition unknown'}</label> | |
749 | <input id='check12' type='checkbox' name='REMOVE_TODELETE' $disabled/> | |
750 | <label id='lbdel' class='symbols' for='check12'>$Lang::tr{'updxlrtr remove file'}</label> | |
751 | </fieldset> | |
752 | <fieldset class='noborder'> | |
753 | <input type='submit' name='ACTION' value='$Lang::tr{'updxlrtr purge'}' $disabled/> | |
754 | </fieldset> | |
755 | END | |
756 | ; | |
757 | if ($param =~ /withfiles/i) | |
758 | { &printtblrepository($Lang::tr{'updxlrtr current files'}, $repos_ref); } | |
759 | print "</form>\n"; | |
46c01c09 MT |
760 | } |
761 | ||
5cf2c339 MT |
762 | # ------------------------------------------------------------------- |
763 | # Print current files in repository - printreposfiles($title, \@files) | |
764 | # ------------------------------------------------------------------- | |
0a638396 | 765 | |
5cf2c339 MT |
766 | sub printtblrepository { |
767 | my $title = shift; | |
768 | my $files = shift; | |
769 | ||
770 | print <<END | |
771 | <hr /> | |
772 | <table id='listcurrfiles'> | |
773 | <caption>$title</caption> | |
774 | <colgroup> | |
775 | <col></col> | |
776 | <col></col> | |
777 | <col style='width: 0*'></col> | |
778 | <col span='5' style='min-width: 20px'></col> | |
779 | </colgroup> | |
780 | <thead> | |
781 | <tr> | |
782 | <th>$Lang::tr{'status'}</th> | |
783 | <th>$Lang::tr{'updxlrtr source'}</th> | |
784 | <th>$Lang::tr{'updxlrtr filename'}</th> | |
785 | <th>$Lang::tr{'updxlrtr filesize'}</th> | |
786 | <th>$Lang::tr{'date'}</th> | |
787 | <th><span id='rel' class='symbols' title='$Lang::tr{'updxlrtr last access'}'></span></th> | |
788 | <th><span id='glo' class='symbols' title='$Lang::tr{'updxlrtr last checkup'}'></span></th> | |
789 | <th><span id='del' class='symbols' title='$Lang::tr{'updxlrtr remove file'}'></span></th> | |
790 | </tr> | |
791 | </thead> | |
792 | <tfoot> | |
793 | <tr> | |
794 | <td colspan='9' id='legend'> | |
0a638396 CS |
795 | END |
796 | ; | |
5cf2c339 MT |
797 | &printlegendicons(); |
798 | &printlegendstatus(); | |
799 | &printlegendsource(); | |
0a638396 | 800 | print <<END |
5cf2c339 MT |
801 | </td> |
802 | </tr> | |
803 | </tfoot> | |
804 | <tbody> | |
0a638396 CS |
805 | END |
806 | ; | |
5cf2c339 MT |
807 | unless (@$files) { print "\t<tr>\n\t\t<th colspan='8'>$Lang::tr{'updxlrtr empty repository'}.</th>\n\t</tr>\n"; } |
808 | else { | |
809 | $id = 0; | |
810 | foreach $updatefile (@$files) { | |
811 | $updatefile =~ s/.*://; | |
812 | my $size_updatefile = 0; | |
813 | my $mtime = 0; | |
814 | if(-e "$repository/$updatefile") { | |
815 | $size_updatefile = (-s "$repository/$updatefile"); | |
816 | $mtime = &getmtime("$repository/$updatefile"); | |
817 | } | |
818 | print "\t<tr>\n"; | |
819 | $filesize = &format_size($size_updatefile); | |
820 | my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($mtime); | |
821 | $DAYdt = sprintf ("%.02d",$DAYdt); | |
822 | $MONTHdt = sprintf ("%.02d",$MONTHdt+1); | |
823 | $YEARdt = sprintf ("%.04d",$YEARdt+1900); | |
824 | $filedate = $DAYdt.".".$MONTHdt.".".$YEARdt; | |
825 | $lastaccess = "n/a"; | |
826 | $lastcheck = "n/a"; | |
827 | $status = $sfUnknown; | |
828 | unless ($updatefile =~ /^download\//) { | |
829 | ($vendorid,$uuid,$shortname) = split('/',$updatefile); | |
830 | if (-e "$repository/$vendorid/$uuid/access.log") { | |
831 | open (FILE,"$repository/$vendorid/$uuid/access.log"); | |
832 | @metadata = <FILE>; | |
833 | close(FILE); | |
834 | chomp @metadata; | |
835 | ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($metadata[-1]); | |
836 | $DAYdt = sprintf ("%.02d",$DAYdt); | |
837 | $MONTHdt = sprintf ("%.02d",$MONTHdt+1); | |
838 | $YEARdt = sprintf ("%.04d",$YEARdt+1900); | |
839 | if (($metadata[-1] =~ /^\d+/) && ($metadata[-1] >= 1)) | |
840 | { $lastaccess = $DAYdt.".".$MONTHdt.".".$YEARdt; } | |
841 | } | |
842 | if (-e "$repository/$vendorid/$uuid/checkup.log") { | |
843 | open (FILE,"$repository/$vendorid/$uuid/checkup.log"); | |
844 | @metadata = <FILE>; | |
845 | close(FILE); | |
846 | chomp @metadata; | |
847 | ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($metadata[-1]); | |
848 | $DAYdt = sprintf ("%.02d",$DAYdt); | |
849 | $MONTHdt = sprintf ("%.02d",$MONTHdt+1); | |
850 | $YEARdt = sprintf ("%.04d",$YEARdt+1900); | |
851 | if (($metadata[-1] =~ /^\d+/) && ($metadata[-1] >= 1)) | |
852 | { $lastcheck = $DAYdt.".".$MONTHdt.".".$YEARdt; } | |
853 | } | |
854 | if (-e "$repository/$vendorid/$uuid/status") { | |
855 | open (FILE,"$repository/$vendorid/$uuid/status"); | |
856 | @metadata = <FILE>; | |
857 | close(FILE); | |
858 | chomp @metadata; | |
859 | $status = $metadata[-1]; | |
860 | } | |
861 | } | |
862 | else { | |
863 | ($uuid,$vendorid,$shortname) = split('/',$updatefile); | |
864 | $status = $sfOutdated; | |
865 | } | |
866 | ||
867 | if ($status == $sfUnknown) | |
868 | { print "\t\t<th><span id='ledgy$id' class='symbols' title='$Lang::tr{'updxlrtr condition unknown'}'> </span></th>\n"; } | |
869 | elsif ($status == $sfOk) | |
870 | { print "\t\t<th><span id='ledgr$id' class='symbols' title='$Lang::tr{'updxlrtr condition ok'}'></span> </th>\n"; } | |
871 | elsif ($status == $sfNoSource) | |
872 | { print "\t\t<th><span id='ledye$id' class='symbols' title='$Lang::tr{'updxlrtr condition nosource'}'> </span></th>\n"; } | |
873 | elsif (($status == $sfOutdated) && (!($updatefile =~ /^download\//i))) | |
874 | { print "\t\t<th><span id='ledrd$id' class='symbols' title='$Lang::tr{'updxlrtr condition outdated'}'> </span></th>\n"; } | |
875 | elsif (($status == $sfOutdated) && ($updatefile =~ /^download\//i)) | |
876 | { print "\t\t<th><span id='ledbl$id' class='symbols' title='$Lang::tr{'updxlrtr condition download'}'> </span></th>\n"; } | |
877 | if ($vendimg{$vendorid}) { | |
878 | print "\t\t<th><span class='vendimg' style='background-image: url($vendimg{$vendorid});' title='".ucfirst $vendorid."'> </span></th>\n"; } | |
879 | else { | |
880 | print "\t\t<th><span class='vendimg' style='background-image: url($vendimg{unknown});' title='".ucfirst $vendorid."'> </span></th>\n"; | |
881 | } | |
882 | $shortname = substr($updatefile,rindex($updatefile,"/")+1); | |
883 | unless ($vendorid ne 'microsoft') { $shortname =~ s/(.*)_[\da-f]*(\.(exe|cab|psf)$)/$1\[...\] $2/i; } | |
884 | unless (length($shortname) <= 50) { | |
885 | my $fext = substr($shortname,rindex("$shortname",'.')); | |
886 | $shortname = substr($shortname,0,44-length($fext)); | |
887 | $shortname .= "[...] $fext"; | |
888 | } | |
889 | print <<END | |
890 | <td title='cache:/$updatefile'><a href="/updatecache/$updatefile">$shortname</a></td> | |
891 | <td>$filesize</td> | |
892 | <td>$filedate</td> | |
893 | <td>$lastaccess</td> | |
894 | <td>$lastcheck</td> | |
895 | <th><input id='frm$id' type='checkbox' name='TODELETE' value='$updatefile' title='$Lang::tr{'updxlrtr remove file'}' /></th> | |
896 | </tr> | |
0a638396 CS |
897 | END |
898 | ; | |
5cf2c339 MT |
899 | $id += 1; |
900 | } | |
901 | } | |
902 | print <<END | |
903 | </tbody> | |
0a638396 CS |
904 | </table> |
905 | </form> | |
4f4092e3 CS |
906 | END |
907 | ; | |
4f4092e3 CS |
908 | } |
909 | ||
5cf2c339 MT |
910 | # ------------------------------------------------------------------- |
911 | # cancels pending download - need updatefile(-ID) | |
912 | # ------------------------------------------------------------------- | |
4f4092e3 | 913 | |
5cf2c339 MT |
914 | sub canceldownload { |
915 | $updatefile = shift; | |
916 | if ($updatefile =~ /^download\//) { | |
917 | ($uuid,$vendorid,$updatefile) = split('/',$updatefile); | |
918 | if (-e "$repository/download/$vendorid/$updatefile.info") { | |
919 | &General::readhash("$repository/download/$vendorid/$updatefile.info", \%dlinfo); | |
920 | $id = &getPID("\\s${General::swroot}/updatexlrator/bin/download\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\\s\\d\\s\\d\$"); | |
921 | if ($id) { system("/bin/kill -9 $id"); } | |
922 | $id = &getPID("\\s/usr/bin/wget\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\$"); | |
923 | if ($id) { system("/bin/kill -9 $id"); } | |
924 | system("rm \"$repository/download/$vendorid/$updatefile.info\""); | |
925 | } | |
926 | ||
927 | if (-e "$repository/download/$vendorid/$updatefile") { | |
928 | system("rm \"$repository/download/$vendorid/$updatefile\""); | |
929 | } | |
930 | } | |
4f4092e3 CS |
931 | } |
932 | ||
5cf2c339 MT |
933 | # ------------------------------------------------------------------- |
934 | # Delete old and selected cached files | |
4f4092e3 CS |
935 | # ------------------------------------------------------------------- |
936 | ||
5cf2c339 MT |
937 | sub delolddata { |
938 | undef (@sources); | |
939 | undef @repositoryfiles; | |
940 | foreach (<$repository/*>) { | |
941 | if (-d $_) { | |
942 | unless (/^$repository\/download$/) { push(@sources,$_); } | |
943 | } | |
944 | } | |
945 | ||
946 | foreach (@sources) { | |
947 | @updatelist=<$_/*>; | |
948 | $vendorid = substr($_,rindex($_,"/")+1); | |
949 | foreach(@updatelist) { | |
950 | $uuid = substr($_,rindex($_,"/")+1); | |
951 | if (-e "$_/source.url") { | |
952 | open (FILE,"$_/source.url"); | |
953 | $sourceurl=<FILE>; | |
954 | close FILE; | |
955 | chomp($sourceurl); | |
956 | $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); | |
957 | $updatefile = "$vendorid/$uuid/$updatefile"; | |
958 | push(@repositoryfiles,$updatefile); | |
959 | } | |
960 | } | |
961 | } | |
962 | ||
963 | foreach (@repositoryfiles) { | |
964 | ($vendorid,$uuid,$updatefile) = split('/'); | |
965 | if (-e "$repository/$vendorid/$uuid/status") { | |
966 | open (FILE,"$repository/$vendorid/$uuid/status"); | |
967 | @metadata = <FILE>; | |
968 | close FILE; | |
969 | chomp(@metadata); | |
970 | $status = $metadata[-1]; | |
971 | } | |
972 | ||
973 | if (-e "$repository/$vendorid/$uuid/access.log") { | |
974 | open (FILE,"$repository/$vendorid/$uuid/access.log"); | |
975 | @metadata = <FILE>; | |
976 | close FILE; | |
977 | chomp(@metadata); | |
978 | $lastaccess = $metadata[-1]; | |
979 | } | |
980 | ||
981 | if (($xlratorsettings{'REMOVE_NOSOURCE'} eq 'on') && ($status == $sfNoSource)) { | |
982 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
983 | } | |
984 | ||
985 | if (($xlratorsettings{'REMOVE_OUTDATED'} eq 'on') && ($status == $sfOutdated)) { | |
986 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
987 | } | |
988 | ||
989 | if (($xlratorsettings{'REMOVE_UNKNOWN'} eq 'on') && ($status == $sfUnknown)) { | |
990 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
991 | } | |
0a638396 | 992 | |
5cf2c339 MT |
993 | if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'week') && ($lastaccess < (time - 604800))) { |
994 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
995 | } | |
996 | elsif (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month1') && ($lastaccess < (time - 2505600))) { | |
997 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
998 | } | |
999 | elsif (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month3') && ($lastaccess < (time - 7516800))) { | |
1000 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
1001 | } | |
1002 | elsif (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month6') && ($lastaccess < (time - 15033600))) { | |
1003 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
1004 | } | |
1005 | elsif (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'year') && ($lastaccess < (time - 31536000))) { | |
1006 | if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
1007 | } | |
0a638396 | 1008 | |
5cf2c339 MT |
1009 | |
1010 | if (($xlratorsettings{'REMOVE_TODELETE'} eq 'on') && ($xlratorsettings{'TODELETE'} ne 'off')) { | |
1011 | my @todelete = split(/\|/, $xlratorsettings{'TODELETE'}); | |
1012 | foreach (@todelete) { | |
1013 | unless ($_ =~ /^download\//) { | |
1014 | ($vendorid,$uuid,$cachefile) = split(/\//, $_); | |
1015 | if (-e "$repository/$vendorid/$uuid/$cachefile") { system("rm -r \"$repository/$vendorid/$uuid\""); } | |
1016 | } | |
1017 | } | |
1018 | } | |
1019 | } | |
1020 | } | |
46c01c09 | 1021 | |
46c01c09 | 1022 | |
5cf2c339 | 1023 | # ------------------------------------------------------------------- |
46c01c09 | 1024 | |
5cf2c339 MT |
1025 | sub printlegenddownload { |
1026 | print <<END | |
1027 | <h5>$Lang::tr{'legend'}:</h5> | |
1028 | <ul> | |
1029 | <li id='liledbl' class='symbols' title='$Lang::tr{'updxlrtr condition download'}'>$Lang::tr{'updxlrtr condition download'}</li> | |
1030 | <li id='liledgy' class='symbols' title='$Lang::tr{'updxlrtr condition suspended'}'>$Lang::tr{'updxlrtr condition suspended'}</li> | |
1031 | <li id='lidel' class='symbols' title='$Lang::tr{'updxlrtr cancel download'}'>$Lang::tr{'updxlrtr cancel download'}</li> | |
1032 | </ul> | |
46c01c09 MT |
1033 | END |
1034 | ; | |
4f4092e3 CS |
1035 | } |
1036 | ||
1037 | # ------------------------------------------------------------------- | |
1038 | ||
5cf2c339 MT |
1039 | sub printlegendicons { |
1040 | print <<END | |
1041 | <h5>$Lang::tr{'legend'}:</h5> | |
1042 | <ul> | |
1043 | <li id='lirel' class='symbols' title='$Lang::tr{'updxlrtr last access'}'>$Lang::tr{'updxlrtr last access'}</li> | |
1044 | <li id='liglo' class='symbols' title='$Lang::tr{'updxlrtr last checkup'}'>$Lang::tr{'updxlrtr last checkup'}</li> | |
1045 | <li id='lidel' class='symbols' title='$Lang::tr{'updxlrtr remove file'}'>$Lang::tr{'updxlrtr remove file'}</li> | |
1046 | </ul> | |
4f4092e3 CS |
1047 | END |
1048 | ; | |
1049 | } | |
1050 | ||
1051 | # ------------------------------------------------------------------- | |
1052 | ||
5cf2c339 MT |
1053 | sub printlegendstatus { |
1054 | print <<END | |
1055 | <h5>$Lang::tr{'status'}:</h5> | |
1056 | <ul> | |
1057 | <li id='liledgr' class='symbols' title='$Lang::tr{'updxlrtr condition ok'}'>$Lang::tr{'updxlrtr condition ok'}</li> | |
1058 | <li id='liledye' class='symbols' title='$Lang::tr{'updxlrtr condition nosource'}'>$Lang::tr{'updxlrtr condition nosource'}</li> | |
1059 | <li id='liledrd' class='symbols' title='$Lang::tr{'updxlrtr condition outdated'}'>$Lang::tr{'updxlrtr condition outdated'}</li> | |
1060 | <li id='liledbl' class='symbols' title='$Lang::tr{'updxlrtr condition download'}'>$Lang::tr{'updxlrtr condition download'}</li> | |
1061 | <li id='liledgy' class='symbols' title='$Lang::tr{'updxlrtr condition unknown'}'>$Lang::tr{'updxlrtr condition unknown'}</li> | |
1062 | </ul> | |
4f4092e3 CS |
1063 | END |
1064 | ; | |
1065 | } | |
1066 | ||
1067 | # ------------------------------------------------------------------- | |
1068 | ||
5cf2c339 MT |
1069 | sub printlegendsource { |
1070 | print <<END | |
1071 | <h5>$Lang::tr{'updxlrtr sources'}:</h5> | |
1072 | <ul> | |
4f4092e3 CS |
1073 | END |
1074 | ; | |
5cf2c339 MT |
1075 | foreach my $name (sort keys %vendimg) { |
1076 | if ($name =~ /^unknown$/i) { | |
1077 | print "\t<li class='vendimg' style='background-image: url($vendimg{$name})' title='". ucfirst $Lang::tr{$name} ."'>". ucfirst $Lang::tr{$name} ."</li>\n"; | |
1078 | } else { | |
1079 | print "\t<li class='vendimg' style='background-image: url($vendimg{$name})' title='". ucfirst $name ."'>". ucfirst $name ."</li>\n"; | |
1080 | } | |
1081 | } | |
1082 | print "</ul>\n"; | |
4f4092e3 CS |
1083 | } |
1084 | ||
5cf2c339 MT |
1085 | # ------------------------------------------------------------------- |
1086 | # 2012-12-18: | |
1087 | # Seaching updbooster-image dir for all available images of format "updxl-src-<vendor>.gif" | |
1088 | # Build a hash in format '<vendor(name)>' -> '/images/updbooster/updxl-src-<vendor>.gif' | |
1089 | ||
1090 | sub initvendimg { | |
1091 | if (opendir(DIR, "$webhome$webimgdir")) { | |
1092 | my @files = grep { /updxl-src-/ } readdir(DIR); | |
1093 | my @vendor = (); | |
1094 | closedir(DIR); | |
1095 | foreach (@files) { | |
1096 | @vendor = split (/[.-]/, $_); | |
1097 | $vendimg{$vendor[2]} = "$webimgdir/$_"; | |
1098 | } | |
1099 | } | |
1100 | else { | |
1101 | die "updxlrtr: Can't access \"$webhome$webimgdir\". Error was: $!\n"; | |
1102 | } | |
1103 | } | |
4f4092e3 CS |
1104 | # ------------------------------------------------------------------- |
1105 | ||
5cf2c339 MT |
1106 | sub printtbldiskusage { |
1107 | my $tabletitle = shift; | |
1108 | my $repos_ref=shift; | |
1109 | print <<END | |
1110 | <table id='diskusage'> | |
1111 | <caption>$tabletitle</caption> | |
1112 | <thead> | |
0a638396 | 1113 | <tr> |
5cf2c339 MT |
1114 | <th>$Lang::tr{'updxlrtr cache dir'}</th> |
1115 | <th>$Lang::tr{'size'}</th> | |
1116 | <th>$Lang::tr{'updxlrtr total used'}</th> | |
1117 | <th>$Lang::tr{'updxlrtr used by'}<br />[$repository]</th> | |
1118 | <th>$Lang::tr{'free'}</th> | |
1119 | <th>$Lang::tr{'percentage'}</th> | |
0a638396 | 1120 | </tr> |
5cf2c339 MT |
1121 | </thead> |
1122 | END | |
1123 | ; | |
1124 | open(DF,"/bin/df -h $repository|"); | |
1125 | @dfdata = <DF>; | |
1126 | $dudata = `/usr/bin/du -hs $repository`; | |
1127 | close DF; | |
1128 | shift(@dfdata); | |
1129 | chomp(@dfdata); | |
1130 | chomp($dudata); | |
1131 | $dfstr = join(' ',@dfdata); | |
1132 | my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr); | |
1133 | my ($duused,$tmp) = split(' ',$dudata); | |
1134 | print <<END | |
1135 | <tbody> | |
0a638396 | 1136 | <tr> |
5cf2c339 MT |
1137 | <td>[$repository]</td> |
1138 | <td>$size</td> | |
1139 | <td><span id="used">$used</span></td> | |
1140 | <td><span id="duused">$duused</span></td> | |
1141 | <td><span id="free">$free</span></td> | |
1142 | <td> | |
1143 | END | |
1144 | ; | |
1145 | &percentbar(&cpof($duused,$size),&cpof($used,$size)); | |
1146 | print <<END | |
1147 | </td> | |
5b2a12ff | 1148 | </tr> |
5cf2c339 MT |
1149 | </tbody> |
1150 | </table> | |
46c01c09 MT |
1151 | END |
1152 | ; | |
5cf2c339 | 1153 | } |
46c01c09 | 1154 | |
5cf2c339 MT |
1155 | # ------------------------------------------------------------------- |
1156 | # Initialize Cache-Settings Form | |
1157 | # ------------------------------------------------------------------- | |
1158 | ||
1159 | sub initfrmsettings { | |
1160 | $checked{'ENABLE_LOG'}{'off'} = ''; | |
1161 | $checked{'ENABLE_LOG'}{'on'} = ''; | |
1162 | $checked{'ENABLE_LOG'}{$xlratorsettings{'ENABLE_LOG'}} = "checked='checked'"; | |
1163 | $checked{'PASSIVE_MODE'}{'off'} = ''; | |
1164 | $checked{'PASSIVE_MODE'}{'on'} = ''; | |
1165 | $checked{'PASSIVE_MODE'}{$xlratorsettings{'PASSIVE_MODE'}} = "checked='checked'"; | |
1166 | $checked{'LOW_DOWNLOAD_PRIORITY'}{'off'} = ''; | |
1167 | $checked{'LOW_DOWNLOAD_PRIORITY'}{'on'} = ''; | |
1168 | $checked{'LOW_DOWNLOAD_PRIORITY'}{$xlratorsettings{'LOW_DOWNLOAD_PRIORITY'}} = "checked='checked'"; | |
1169 | $checked{'ENABLE_AUTOCHECK'}{'off'} = ''; | |
1170 | $checked{'ENABLE_AUTOCHECK'}{'on'} = ''; | |
1171 | $checked{'ENABLE_AUTOCHECK'}{$xlratorsettings{'ENABLE_AUTOCHECK'}} = "checked='checked'"; | |
1172 | $checked{'FULL_AUTOSYNC'}{'off'} = ''; | |
1173 | $checked{'FULL_AUTOSYNC'}{'on'} = ''; | |
1174 | $checked{'FULL_AUTOSYNC'}{$xlratorsettings{'FULL_AUTOSYNC'}} = "checked='checked'"; | |
1175 | $selected{'VIEW_SETTING'}{'overview'} = ''; | |
1176 | $selected{'VIEW_SETTING'}{'statistics'} = ''; | |
1177 | $selected{'VIEW_SETTING'}{'maintenance'} = ''; | |
1178 | $selected{'VIEW_SETTING'}{'settings'} = ''; | |
1179 | $selected{'VIEW_SETTING'}{$xlratorsettings{'VIEW_SETTING'}} = "checked='checked'"; | |
1180 | $selected{'AUTOCHECK_SCHEDULE'}{'daily'} = ''; | |
1181 | $selected{'AUTOCHECK_SCHEDULE'}{'weekly'} = ''; | |
1182 | $selected{'AUTOCHECK_SCHEDULE'}{'monthly'} = ''; | |
1183 | $selected{'AUTOCHECK_SCHEDULE'}{$xlratorsettings{'AUTOCHECK_SCHEDULE'}} = "selected='selected'"; | |
46c01c09 MT |
1184 | } |
1185 | ||
5cf2c339 MT |
1186 | # ------------------------------------------------------------------- |
1187 | # Print Cache-Settings Form | |
4f4092e3 | 1188 | # ------------------------------------------------------------------- |
46c01c09 | 1189 | |
5cf2c339 MT |
1190 | sub printfrmsettings { |
1191 | print <<END | |
1192 | <form id='frmsettings' method='post' action='$ENV{'SCRIPT_NAME'}' enctype='multipart/form-data'> | |
1193 | <fieldset> | |
1194 | <legend>$Lang::tr{'updxlrtr standard view'}</legend> | |
1195 | <input id='radio01' type='radio' name='VIEW_SETTING' value='overview' $selected{'VIEW_SETTING'}{'overview'} /> | |
1196 | <label for='radio01'>$Lang::tr{'updxlrtr overview'}</label> | |
1197 | <input id='radio02' type='radio' name='VIEW_SETTING' value='statistics' $selected{'VIEW_SETTING'}{'statistics'} /> | |
1198 | <label for='radio02'>$Lang::tr{'updxlrtr statistics'}</label> | |
1199 | <input id='radio03' type='radio' name='VIEW_SETTING' value='maintenance' $selected{'VIEW_SETTING'}{'maintenance'} /> | |
1200 | <label for='radio03'>$Lang::tr{'updxlrtr maintenance'}</label> | |
1201 | <input id='radio04' type='radio' name='VIEW_SETTING' value='settings' $selected{'VIEW_SETTING'}{'settings'} /> | |
1202 | <label for='radio04'>$Lang::tr{'updxlrtr settings'}</label> | |
1203 | </fieldset> | |
1204 | <fieldset> | |
1205 | <legend>$Lang::tr{'updxlrtr common settings'}</legend> | |
1206 | <input id='check01' type='checkbox' name='ENABLE_LOG' $checked{'ENABLE_LOG'}{'on'} /> | |
1207 | <label for='check01'>$Lang::tr{'updxlrtr enable log'}</label> | |
1208 | <input id='check02' type='checkbox' name='PASSIVE_MODE' $checked{'PASSIVE_MODE'}{'on'} /> | |
1209 | <label for='check02'>$Lang::tr{'updxlrtr passive mode'}</label> | |
1210 | <label for='text01'>$Lang::tr{'updxlrtr max disk usage'} (<output id='duval'>$xlratorsettings{'MAX_DISK_USAGE'}</output>%):</label> | |
1211 | <input id='text01' type='range' name='MAX_DISK_USAGE' min='0' max='100' step='1' onchange='duval.value=value' value='$xlratorsettings{'MAX_DISK_USAGE'}' size='3' maxlength='4'/> | |
1212 | </fieldset> | |
1213 | <fieldset> | |
1214 | <legend>$Lang::tr{'updxlrtr performance options'}</legend> | |
1215 | <input id='check04' type='checkbox' name='LOW_DOWNLOAD_PRIORITY' $checked{'LOW_DOWNLOAD_PRIORITY'}{'on'} /> | |
1216 | <label for='check04'>$Lang::tr{'updxlrtr low download priority'}</label> | |
1217 | <label for='text02' >$Lang::tr{'updxlrtr max download rate'}:</label> | |
1218 | <input id='text02' type='number' name='MAX_DOWNLOAD_RATE' title='$Lang::tr{'updxlrtr notice dlrate'}' min='0' max='1000000' step='16' value='$xlratorsettings{'MAX_DOWNLOAD_RATE'}' size='5' /> | |
1219 | </fieldset> | |
1220 | <fieldset> | |
1221 | <legend>$Lang::tr{'updxlrtr source checkup'}</legend> | |
1222 | <input id='check06' type='checkbox' name='ENABLE_AUTOCHECK' $checked{'ENABLE_AUTOCHECK'}{'on'} /> | |
1223 | <label for='check06'>$Lang::tr{'updxlrtr enable autocheck'}</label> | |
1224 | <label for='select01'>$Lang::tr{'updxlrtr source checkup schedule'}:</label> | |
1225 | <select id='select01' name='AUTOCHECK_SCHEDULE'> | |
1226 | <option value='daily' $selected{'AUTOCHECK_SCHEDULE'}{'daily'}>$Lang::tr{'updxlrtr daily'}</option> | |
1227 | <option value='weekly' $selected{'AUTOCHECK_SCHEDULE'}{'weekly'}>$Lang::tr{'updxlrtr weekly'}</option> | |
1228 | <option value='monthly' $selected{'AUTOCHECK_SCHEDULE'}{'monthly'}>$Lang::tr{'updxlrtr monthly'}</option> | |
1229 | </select> | |
1230 | <br /> | |
1231 | <input id='check07' type='checkbox' name='FULL_AUTOSYNC' $checked{'FULL_AUTOSYNC'}{'on'} /> | |
1232 | <label for='check07'>$Lang::tr{'updxlrtr full autosync'}</label> | |
1233 | </fieldset> | |
1234 | <fieldset style='border:0'> | |
1235 | <input type='submit' name='ACTION' value='$Lang::tr{'save'}' /> | |
1236 | <input type='submit' name='ACTION' value='$Lang::tr{'updxlrtr save and restart'}' /> | |
1237 | </fieldset> | |
1238 | </form> | |
4f4092e3 CS |
1239 | END |
1240 | ; | |
46c01c09 | 1241 | } |
46c01c09 | 1242 | |
5cf2c339 MT |
1243 | # ------------------------------------------------------------------- |
1244 | # chksettings([save|restart]) - Check settings and/or restart proxy | |
46c01c09 MT |
1245 | # ------------------------------------------------------------------- |
1246 | ||
5cf2c339 MT |
1247 | sub chksettings { |
1248 | my $param = shift; | |
1249 | my $error_ref = shift; | |
1250 | if ( $param =~ /save/i ) { | |
1251 | if (!($xlratorsettings{'MAX_DISK_USAGE'} =~ /^\d+$/) | |
1252 | || ($xlratorsettings{'MAX_DISK_USAGE'} < 1) | |
1253 | || ($xlratorsettings{'MAX_DISK_USAGE'} > 100)) { | |
1254 | push(@$error_ref, $Lang::tr{'updxlrtr invalid disk usage'}); | |
1255 | } | |
1256 | if (($xlratorsettings{'MAX_DOWNLOAD_RATE'} ne '') && ((!($xlratorsettings{'MAX_DOWNLOAD_RATE'} =~ /^\d+$/)) | |
1257 | || ($xlratorsettings{'MAX_DOWNLOAD_RATE'} < 1))) { | |
1258 | push(@$error_ref, $Lang::tr{'updxlrtr invalid download rate'}); | |
1259 | } | |
1260 | unless (@$error_ref >= 1) { &savesettings; } | |
1261 | } | |
1262 | if ($param =~ /restart/i ) { | |
1263 | if ((!(-e "${General::swroot}/proxy/enable")) && (!(-e "${General::swroot}/proxy/enable_blue"))) { | |
1264 | push(@$error_ref, $Lang::tr{'updxlrtr web proxy service required'}); | |
1265 | } | |
1266 | if ($proxysettings{'ENABLE_UPDXLRATOR'} ne 'on') { | |
1267 | push(@$error_ref, $Lang::tr{'updxlrtr not enabled'}); | |
1268 | } | |
1269 | unless (@$error_ref >= 1) { system('/usr/local/bin/squidctrl restart > /dev/null 2>&1'); } | |
1270 | } | |
1271 | unless (@$error_ref == 0) { &initfrmsettings; } | |
1272 | } | |
46c01c09 | 1273 | |
5cf2c339 | 1274 | # ------------------------------------------------------------------- |
4f4092e3 | 1275 | |
5cf2c339 MT |
1276 | sub savesettings { |
1277 | if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'daily')) | |
1278 | { system('/usr/local/bin/updxlratorctrl cron daily >/dev/null 2>&1'); } | |
1279 | if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'weekly')) | |
1280 | { system('/usr/local/bin/updxlratorctrl cron weekly >/dev/null 2>&1'); } | |
1281 | if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'monthly')) | |
1282 | { system('/usr/local/bin/updxlratorctrl cron monthly >/dev/null 2>&1'); } | |
1283 | ||
1284 | # don't save those variable to the settings file, | |
1285 | # but we wan't to have them in the hash again after saving to file | |
1286 | my $obsolete = $xlratorsettings{'REMOVE_UNKNOWN'}; | |
1287 | my $nosource = $xlratorsettings{'REMOVE_NOSOURCE'}; | |
1288 | my $outdated = $xlratorsettings{'REMOVE_OUTDATED'}; | |
1289 | my $todelete = $xlratorsettings{'REMOVE_TODELETE'}; | |
1290 | my $gui = $xlratorsettings{'EXTENDED_GUI'}; | |
1291 | my $show = $xlratorsettings{'show'}; | |
1292 | ||
1293 | delete($xlratorsettings{'REMOVE_UNKNOWN'}); | |
1294 | delete($xlratorsettings{'REMOVE_NOSOURCE'}); | |
1295 | delete($xlratorsettings{'REMOVE_OUTDATED'}); | |
1296 | delete($xlratorsettings{'REMOVE_TODELETE'}); | |
1297 | delete($xlratorsettings{'TODELETE'}); | |
1298 | delete($xlratorsettings{'EXTENDED_GUI'}); | |
1299 | delete($xlratorsettings{'show'}); | |
1300 | ||
1301 | &General::writehash("${General::swroot}/updatexlrator/settings", \%xlratorsettings); | |
1302 | ||
1303 | # put temp variables back into the hash | |
1304 | $xlratorsettings{'REMOVE_UNKNOWN'} = $obsolete; | |
1305 | $xlratorsettings{'REMOVE_NOSOURCE'} = $nosource; | |
1306 | $xlratorsettings{'REMOVE_OUTDATED'} = $outdated; | |
1307 | $xlratorsettings{'REMOVE_TODELETE'} = $todelete; | |
1308 | $xlratorsettings{'EXTENDED_GUI'} = $gui; | |
1309 | $xlratorsettings{'show'} = $show; | |
1310 | } | |
46c01c09 | 1311 | |
0a638396 | 1312 | |
5cf2c339 MT |
1313 | # ------------------------------------------------------------------- |
1314 | # percentbar(number[, number2, number(n)) - need absolute values | |
1315 | # - print relative bars ([##1][##2(number2-number1)][#n-#2-#1]...) | |
1316 | # ------------------------------------------------------------------- | |
4f4092e3 | 1317 | |
5cf2c339 MT |
1318 | sub percentbar { |
1319 | $counts = '0'; | |
1320 | my $width = '-0'; # width of value bar | |
1321 | my $widthmax = '-0'; # overall width | |
1322 | my $tmp = ''; | |
1323 | my @tmplst; | |
1324 | my $sf = 1; # scale-factor | |
1325 | print "<div id='pbar'>"; | |
1326 | @_ = sort{ $a <=> $b } @_; | |
1327 | for (@_) { | |
1328 | unless ($widthmax <= 100.0) { next; }; | |
1329 | $width = $_-($widthmax); | |
1330 | $widthmax = $_; | |
1331 | if (($width > 0) && ($width < 1)) { $width=1; } | |
1332 | $tmp .= "<div id='bar$counts' style='width:".(sprintf("%0.2f",$width))*$sf."%'></div>\n"; | |
1333 | $counts = $counts + 1; | |
1334 | } | |
1335 | $widthmax = sprintf("%0d",$widthmax); | |
1336 | if ( $widthmax < 79) { $tmp .= "<span id='percent'>$widthmax%</span>\n"; } | |
1337 | else { $tmp .= "<span id='max'>$widthmax%</span>\n"; } | |
1338 | ||
1339 | print "\t\t$tmp</div>\n"; | |
1340 | return; | |
46c01c09 MT |
1341 | } |
1342 | ||
5cf2c339 MT |
1343 | # ------------------------------------------------------------------- |
1344 | # Format given filesize in Bits | |
1345 | # into values of more human readable format like kB, MB, GB, etc | |
1346 | # take filesize in Bit, returns formatted string in example "xx.xx kB" | |
1347 | # No roundings are happened, | |
1348 | # so counting with the output may result in wrong values | |
46c01c09 MT |
1349 | # ------------------------------------------------------------------- |
1350 | ||
5cf2c339 MT |
1351 | sub format_size{ |
1352 | my $fsize = shift; | |
1353 | ||
1354 | if ($fsize > 2**60) # EB: 1024 PB | |
1355 | { return sprintf("%.2f EB", $fsize / 2**40); } | |
1356 | elsif ($fsize > 2**50) # PB: 1024 TB | |
1357 | { return sprintf("%.2f PB", $fsize / 2**40); } | |
1358 | elsif ($fsize > 2**40) # TB: 1024 GB | |
1359 | { return sprintf("%.2f TB", $fsize / 2**40); } | |
1360 | elsif ($fsize > 2**30) # GB: 1024 MB | |
1361 | { return sprintf("%.2f GB", $fsize / 2**30); } | |
1362 | elsif ($fsize > 2**20) # MB: 1024 kB | |
1363 | { return sprintf("%.2f MB", $fsize / 2**20); } | |
1364 | elsif ($fsize > 2**10) # kB: 1024 B | |
1365 | { return sprintf("%.2f KB", $fsize / 2**10); } | |
1366 | else # Bytes | |
1367 | { return "$fsize B"; } | |
46c01c09 MT |
1368 | } |
1369 | ||
1370 | # ------------------------------------------------------------------- | |
1371 | ||
1372 | sub getmtime | |
1373 | { | |
5cf2c339 MT |
1374 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]); |
1375 | return $mtime; | |
46c01c09 MT |
1376 | } |
1377 | ||
1378 | # ------------------------------------------------------------------- | |
4f4092e3 CS |
1379 | |
1380 | sub getPID | |
1381 | { | |
5cf2c339 MT |
1382 | my $pid=''; |
1383 | my @psdata=`ps ax --no-heading`; | |
4f4092e3 | 1384 | |
5cf2c339 MT |
1385 | foreach (@psdata) |
1386 | { if (/$_[0]/) { ($pid)=/^\s*(\d+)/; } } | |
1387 | return $pid; | |
4f4092e3 CS |
1388 | } |
1389 | ||
1390 | # ------------------------------------------------------------------- | |
5cf2c339 MT |
1391 | # Calculating Percentage of 2 Values (for percentbar) |
1392 | # ------------------------------------------------------------------- | |
1393 | ||
1394 | sub cpof { | |
1395 | my $Value; | |
1396 | my $MValue; | |
1397 | my $result; | |
1398 | my $Vsize; | |
1399 | my $MVsize; | |
1400 | my $corf; | |
1401 | my $callme = "cpof\(value[B|K|M|G|T|P|E], maxvalue[B|K|M|G|T|P|E]\)"; | |
1402 | $Value = shift; | |
1403 | $MValue = shift; | |
1404 | my %cf = ('B'=>0,'K'=>1,'M'=>2,'G'=>3,'T'=>4,'P'=>5,'E'=>6); | |
1405 | unless ('$Value' ne '') { die "updxlrtr sub cpof: value not given: $!\n$callme"; } | |
1406 | unless ('$MValue' ne '') { die "updxlrtr sub cpof: maxvalue not given: $!\n$callme"; } | |
1407 | ||
1408 | unless ($Value =~ /\d+(B|K|M|G|T|P|E)/) { die "updxlrtr: cpof() - value has no size!\nPossible Values: 'number[B|K|M|G|T|P|E]'\n"; } | |
1409 | else { $Vsize = chop $Value; } | |
1410 | unless ($MValue =~ /\d+(B|K|M|G|T|P|E)/) { die "updxlrtr: cpof(): maxvalue has no size!\nPossible Values: 'number[B|K|M|G|T|P|E]'\n"; } | |
1411 | else { $MVsize = chop $MValue; } | |
1412 | ||
1413 | if ('$Vsize' eq '$MVsize') { $result = (100/$MValue)*$Value; } | |
1414 | else { | |
1415 | if ($Value =~ /^0\.d+/) { $corf = 1; } | |
1416 | else { $corf = '0'; } | |
1417 | } | |
1418 | my $tmp = (100/($MValue*(2**(10*$cf{$MVsize}))))*($Value*(2**(10*($cf{$Vsize}-$corf)))); | |
1419 | $tmp = sprintf ("%.2f", $tmp); | |
1420 | return $tmp; | |
1421 | } |