#!/usr/bin/perl #!/usr/bin/perl # # This code is distributed under the terms of the GPL # # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net # # Portions (c) 2008 by dotzball - http://www.blockouttraffic.de # # $Id: updatexlrator.cgi,v 2.1.0 2008/07/16 00:00:00 marco.s Exp $ # ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2009 Michael Tremer & Christian Schmidt # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### use strict; # enable only the following on debugging purpose #use warnings; no warnings 'once';# 'redefine', 'uninitialized'; #use CGI::Carp 'fatalsToBrowser'; use IO::Socket; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; my %color = (); my %checked=(); my %selected=(); my %netsettings=(); my %mainsettings=(); my %proxysettings=(); my %xlratorsettings=(); my %dlinfo=(); my $id=0; my @dfdata=(); my $dfstr=''; my @updatelist=(); my @sources=(); my $sourceurl=''; my $vendorid=''; my $uuid=''; my $status=0; my $updatefile=''; my $shortname=''; my $time=''; my $filesize=0; my $filedate=''; my $lastaccess=''; my $lastcheck=''; my $cachedtraffic=0; my @requests=(); my $data=''; my $counts=0; my $numfiles=0; my $cachehits=0; my $efficiency='0.0'; my @vendors=(); my %vendorstats=(); my $repository = "/var/updatecache/"; my $hintcolour = '#FFFFCC'; my $colourgray = '#808080'; my $sfUnknown='0'; my $sfOk='1'; my $sfOutdated='2'; my $sfNoSource='3'; my $not_accessed_last=''; my $errormessage=''; my @repositorylist=(); my @repositoryfiles=(); my @downloadlist=(); my @downloadfiles=(); my @metadata=(); my $chk_cron_dly = "${General::swroot}/updatexlrator/autocheck/cron.daily"; my $chk_cron_wly = "${General::swroot}/updatexlrator/autocheck/cron.weekly"; my $chk_cron_mly = "${General::swroot}/updatexlrator/autocheck/cron.monthly"; &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); &General::readhash("${General::swroot}/main/settings", \%mainsettings); &General::readhash("${General::swroot}/proxy/settings", \%proxysettings); &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); $xlratorsettings{'ACTION'} = ''; $xlratorsettings{'ENABLE_LOG'} = 'off'; $xlratorsettings{'PASSIVE_MODE'} = 'off'; $xlratorsettings{'MAX_DISK_USAGE'} = '75'; $xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} = 'off'; $xlratorsettings{'MAX_DOWNLOAD_RATE'} = ''; $xlratorsettings{'ENABLE_AUTOCHECK'} = 'off'; $xlratorsettings{'FULL_AUTOSYNC'} = 'off'; $xlratorsettings{'NOT_ACCESSED_LAST'} = 'month1'; $xlratorsettings{'REMOVE_NOSOURCE'} = 'off'; $xlratorsettings{'REMOVE_OUTDATED'} = 'off'; $xlratorsettings{'REMOVE_OBSOLETE'} = 'off'; &Header::getcgihash(\%xlratorsettings); $xlratorsettings{'EXTENDED_GUI'} = ''; if ($xlratorsettings{'ACTION'} eq "$Lang::tr{'updxlrtr statistics'} >>") { $xlratorsettings{'EXTENDED_GUI'} = 'statistics'; } if ($xlratorsettings{'ACTION'} eq "$Lang::tr{'updxlrtr maintenance'} >>") { $xlratorsettings{'EXTENDED_GUI'} = 'maintenance'; } if ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr purge'}) { $xlratorsettings{'EXTENDED_GUI'} = 'maintenance'; if (($xlratorsettings{'REMOVE_OBSOLETE'} eq 'on') || ($xlratorsettings{'REMOVE_NOSOURCE'} eq 'on') || ($xlratorsettings{'REMOVE_OUTDATED'} eq 'on')) { undef (@sources); undef @repositoryfiles; foreach (<$repository/*>) { if (-d $_) { unless (/^$repository\/download$/) { push(@sources,$_); } } } foreach (@sources) { @updatelist=<$_/*>; $vendorid = substr($_,rindex($_,"/")+1); foreach(@updatelist) { $uuid = substr($_,rindex($_,"/")+1); if (-e "$_/source.url") { open (FILE,"$_/source.url"); $sourceurl=; close FILE; chomp($sourceurl); $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); $updatefile = "$vendorid/$uuid/$updatefile"; push(@repositoryfiles,$updatefile); } } } foreach (@repositoryfiles) { ($vendorid,$uuid,$updatefile) = split('/'); if (-e "$repository/$vendorid/$uuid/status") { open (FILE,"$repository/$vendorid/$uuid/status"); @metadata = ; close FILE; chomp(@metadata); $status = $metadata[-1]; } if (-e "$repository/$vendorid/$uuid/access.log") { open (FILE,"$repository/$vendorid/$uuid/access.log"); @metadata = ; close FILE; chomp(@metadata); $lastaccess = $metadata[-1]; } if (($xlratorsettings{'REMOVE_NOSOURCE'} eq 'on') && ($status == $sfNoSource)) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if (($xlratorsettings{'REMOVE_OUTDATED'} eq 'on') && ($status == $sfOutdated)) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if ($xlratorsettings{'REMOVE_OBSOLETE'} eq 'on') { if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'week') && ($lastaccess < (time - 604800))) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month1') && ($lastaccess < (time - 2505600))) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month3') && ($lastaccess < (time - 7516800))) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'month6') && ($lastaccess < (time - 15033600))) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } if (($xlratorsettings{'NOT_ACCESSED_LAST'} eq 'year') && ($lastaccess < (time - 31536000))) { if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } } } } } if ($xlratorsettings{'ACTION'} eq $Lang::tr{'save'}) { if (!($xlratorsettings{'MAX_DISK_USAGE'} =~ /^\d+$/) || ($xlratorsettings{'MAX_DISK_USAGE'} < 1) || ($xlratorsettings{'MAX_DISK_USAGE'} > 100)) { $errormessage = $Lang::tr{'updxlrtr invalid disk usage'}; goto ERROR; } if (($xlratorsettings{'MAX_DOWNLOAD_RATE'} ne '') && ((!($xlratorsettings{'MAX_DOWNLOAD_RATE'} =~ /^\d+$/)) || ($xlratorsettings{'MAX_DOWNLOAD_RATE'} < 1))) { $errormessage = $Lang::tr{'updxlrtr invalid download rate'}; goto ERROR; } &savesettings; } if ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr save and restart'}) { if (!($xlratorsettings{'MAX_DISK_USAGE'} =~ /^\d+$/) || ($xlratorsettings{'MAX_DISK_USAGE'} < 1) || ($xlratorsettings{'MAX_DISK_USAGE'} > 100)) { $errormessage = $Lang::tr{'updxlrtr invalid disk usage'}; goto ERROR; } if (($xlratorsettings{'MAX_DOWNLOAD_RATE'} ne '') && ((!($xlratorsettings{'MAX_DOWNLOAD_RATE'} =~ /^\d+$/)) || ($xlratorsettings{'MAX_DOWNLOAD_RATE'} < 1))) { $errormessage = $Lang::tr{'updxlrtr invalid download rate'}; goto ERROR; } if ((!(-e "${General::swroot}/proxy/enable")) && (!(-e "${General::swroot}/proxy/enable_blue"))) { $errormessage = $Lang::tr{'updxlrtr web proxy service required'}; goto ERROR; } if (!($proxysettings{'ENABLE_UPDXLRATOR'} eq 'on')) { $errormessage = $Lang::tr{'updxlrtr not enabled'}; goto ERROR; } &savesettings; system('/usr/local/bin/squidctrl restart >/dev/null 2>&1'); } if ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr remove file'}) { $xlratorsettings{'EXTENDED_GUI'} = 'maintenance'; $updatefile = $xlratorsettings{'ID'}; unless ($updatefile =~ /^download\//) { ($vendorid,$uuid,$updatefile) = split('/',$updatefile); if (-e "$repository/$vendorid/$uuid/$updatefile") { system("rm -r $repository/$vendorid/$uuid"); } } } if (($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr cancel download'}) || ($xlratorsettings{'ACTION'} eq $Lang::tr{'updxlrtr remove file'})) { $updatefile = $xlratorsettings{'ID'}; if ($updatefile =~ /^download\//) { ($uuid,$vendorid,$updatefile) = split('/',$updatefile); if (-e "$repository/download/$vendorid/$updatefile.info") { &General::readhash("$repository/download/$vendorid/$updatefile.info", \%dlinfo); $id = &getPID("\\s${General::swroot}/updatexlrator/bin/download\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\\s\\d\\s\\d\$"); if ($id) { system("/bin/kill -9 $id"); } $id = &getPID("\\s/usr/bin/wget\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\$"); if ($id) { system("/bin/kill -9 $id"); } system("rm $repository/download/$vendorid/$updatefile.info"); } if (-e "$repository/download/$vendorid/$updatefile") { system("rm $repository/download/$vendorid/$updatefile"); } } } $not_accessed_last = $xlratorsettings{'NOT_ACCESSED_LAST'}; undef($xlratorsettings{'NOT_ACCESSED_LAST'}); if (-e "${General::swroot}/updatexlrator/settings") { &General::readhash("${General::swroot}/updatexlrator/settings", \%xlratorsettings); } if ($xlratorsettings{'NOT_ACCESSED_LAST'} eq '') { $xlratorsettings{'NOT_ACCESSED_LAST'} = $not_accessed_last; } ERROR: $checked{'ENABLE_LOG'}{'off'} = ''; $checked{'ENABLE_LOG'}{'on'} = ''; $checked{'ENABLE_LOG'}{$xlratorsettings{'ENABLE_LOG'}} = "checked='checked'"; $checked{'PASSIVE_MODE'}{'off'} = ''; $checked{'PASSIVE_MODE'}{'on'} = ''; $checked{'PASSIVE_MODE'}{$xlratorsettings{'PASSIVE_MODE'}} = "checked='checked'"; $checked{'LOW_DOWNLOAD_PRIORITY'}{'off'} = ''; $checked{'LOW_DOWNLOAD_PRIORITY'}{'on'} = ''; $checked{'LOW_DOWNLOAD_PRIORITY'}{$xlratorsettings{'LOW_DOWNLOAD_PRIORITY'}} = "checked='checked'"; $checked{'ENABLE_AUTOCHECK'}{'off'} = ''; $checked{'ENABLE_AUTOCHECK'}{'on'} = ''; $checked{'ENABLE_AUTOCHECK'}{$xlratorsettings{'ENABLE_AUTOCHECK'}} = "checked='checked'"; $checked{'FULL_AUTOSYNC'}{'off'} = ''; $checked{'FULL_AUTOSYNC'}{'on'} = ''; $checked{'FULL_AUTOSYNC'}{$xlratorsettings{'FULL_AUTOSYNC'}} = "checked='checked'"; $checked{'REMOVE_NOSOURCE'}{'off'} = ''; $checked{'REMOVE_NOSOURCE'}{'on'} = ''; $checked{'REMOVE_NOSOURCE'}{$xlratorsettings{'REMOVE_NOSOURCE'}} = "checked='checked'"; $checked{'REMOVE_OUTDATED'}{'off'} = ''; $checked{'REMOVE_OUTDATED'}{'on'} = ''; $checked{'REMOVE_OUTDATED'}{$xlratorsettings{'REMOVE_OUTDATED'}} = "checked='checked'"; $checked{'REMOVE_OBSOLETE'}{'off'} = ''; $checked{'REMOVE_OBSOLETE'}{'on'} = ''; $checked{'REMOVE_OBSOLETE'}{$xlratorsettings{'REMOVE_OBSOLETE'}} = "checked='checked'"; $selected{'AUTOCHECK_SCHEDULE'}{'daily'} = ''; $selected{'AUTOCHECK_SCHEDULE'}{'weekly'} = ''; $selected{'AUTOCHECK_SCHEDULE'}{'monthly'} = ''; $selected{'AUTOCHECK_SCHEDULE'}{$xlratorsettings{'AUTOCHECK_SCHEDULE'}} = "selected='selected'"; $selected{'NOT_ACCESSED_LAST'}{'week'} = ''; $selected{'NOT_ACCESSED_LAST'}{'month1'} = ''; $selected{'NOT_ACCESSED_LAST'}{'month3'} = ''; $selected{'NOT_ACCESSED_LAST'}{'month6'} = ''; $selected{'NOT_ACCESSED_LAST'}{'year'} = ''; $selected{'NOT_ACCESSED_LAST'}{$xlratorsettings{'NOT_ACCESSED_LAST'}} = "selected='selected'"; # ---------------------------------------------------- # Settings dialog # ---------------------------------------------------- &Header::showhttpheaders(); &Header::openpage($Lang::tr{'updxlrtr configuration'}, 1, ''); &Header::openbigbox('100%', 'left', '', $errormessage); if ($errormessage) { &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); print "$errormessage \n"; &Header::closebox(); } print "
\n"; &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr update accelerator'}"); print < $Lang::tr{'updxlrtr common settings'} $Lang::tr{'updxlrtr enable log'}: $Lang::tr{'updxlrtr passive mode'}: $Lang::tr{'updxlrtr max disk usage'}: %
$Lang::tr{'updxlrtr performance options'}
$Lang::tr{'updxlrtr low download priority'}: $Lang::tr{'updxlrtr max download rate'}: *

$Lang::tr{'updxlrtr source checkup'}
$Lang::tr{'updxlrtr enable autocheck'}: $Lang::tr{'updxlrtr source checkup schedule'}:
$Lang::tr{'updxlrtr full autosync'}:    

END ; print" \n"; print" \n"; print <
 >' "; } print "/>>' "; } print "/>
END ; &Header::closebox(); print "\n"; # ---------------------------------------------------- # List pending downloads - if any # ---------------------------------------------------- if (($xlratorsettings{'EXTENDED_GUI'} ne 'statistics') && ($xlratorsettings{'EXTENDED_GUI'} ne 'maintenance')) { @downloadlist = <$repository/download/*>; undef(@downloadfiles); foreach (@downloadlist) { if (-d) { my @filelist = <$_/*>; $vendorid = substr($_,rindex($_,"/")+1); foreach(@filelist) { next if(/\.info$/); $updatefile = substr($_,rindex($_,"/")+1); $updatefile .= ":download/$vendorid/$updatefile"; $updatefile = " ".$updatefile; push(@downloadfiles, $updatefile); } } } if (@downloadfiles) { &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr pending downloads'}"); print < $Lang::tr{'updxlrtr current downloads'} END ; $id = 0; foreach $updatefile (@downloadfiles) { $updatefile =~ s/.*://; my $size_updatefile = 0; my $mtime = 0; if(-e "$repository/$updatefile") { $size_updatefile = (-s "$repository/$updatefile"); $mtime = &getmtime("$repository/$updatefile"); } if (-e "$repository/$updatefile.info") { &General::readhash("$repository/$updatefile.info", \%dlinfo); } else { undef(%dlinfo); } $id++; if ($id % 2) { print "\n"; } else { print "\n"; } $filesize = $size_updatefile; 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($mtime); $DAYdt = sprintf ("%.02d",$DAYdt); $MONTHdt = sprintf ("%.02d",$MONTHdt+1); $YEARdt = sprintf ("%.04d",$YEARdt+1900); $filedate = $YEARdt."-".$MONTHdt."-".$DAYdt; ($uuid,$vendorid,$shortname) = split('/',$updatefile); print "\t\t\n"; } else { print "$Lang::tr{ \n"; } print "\t\t\n"; } elsif ($vendorid =~ /^Microsoft$/i) { print "Microsoft \n"; } elsif ($vendorid =~ /^Symantec$/i) { print "Symantec \n"; } elsif ($vendorid =~ /^Linux$/i) { print "Linux \n"; } elsif ($vendorid =~ /^TrendMicro$/i) { print "Trend Micro \n"; } elsif ($vendorid =~ /^Apple$/i) { print "Apple \n"; } elsif ($vendorid =~ /^Avast$/i) { print "Avast \n"; } else { if (-e "/home/httpd/html/images/updxl-src-" . $vendorid . ".gif") { print "" . ucfirst $vendorid . " \n"; } else { print "" . ucfirst $vendorid . " \n"; } } $shortname = substr($updatefile,rindex($updatefile,"/")+1); $shortname =~ s/(.*)_[\da-f]*(\.(exe|cab|psf)$)/$1_*$2/i; $filesize = $dlinfo{'REMOTESIZE'}; 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; $dlinfo{'VENDORID'}=ucfirst $vendorid; print < $dlinfo{'VENDORID'}  END ; } print "
  $Lang::tr{'updxlrtr source'} $Lang::tr{'updxlrtr filename'} $Lang::tr{'updxlrtr filesize'} $Lang::tr{'date'} $Lang::tr{'updxlrtr progress'}  
 "; if (&getPID("\\s/usr/bin/wget\\s.*\\s".quotemeta($dlinfo{'SRCURL'})."\$")) { print "$Lang::tr{  "; if ($vendorid =~ /^Adobe$/i) { print "Adobe $shortname  $filesize   $filedate  END ; my $percent="0%"; if ($dlinfo{'REMOTESIZE'} && $size_updatefile) { $percent=int(100 / ($dlinfo{'REMOTESIZE'} / $size_updatefile))."%"; } print $percent; &percentbar($percent); print <
\n
\n\n"; &printlegenddownload(); print "
\n"; &Header::closebox(); } } # ===================================================================================== # CACHE STATISTICS # ===================================================================================== if ($xlratorsettings{'EXTENDED_GUI'} eq 'statistics') { # ---------------------------------------------------- # Get statistics # ---------------------------------------------------- @sources=(); foreach (<$repository/*>) { if (-d $_) { unless ((/^$repository\/download$/) || (/^$repository\/lost\+found$/)) { push(@sources,$_); } } } @vendors=(); foreach (@sources) { $vendorid=substr($_,rindex($_,'/')+1,length($_)); push(@vendors,$vendorid); $vendorstats{$vendorid."_filesize"} = 0; $vendorstats{$vendorid."_requests"} = 0; $vendorstats{$vendorid."_files"} = 0; $vendorstats{$vendorid."_cachehits"} = 0; $vendorstats{$vendorid."_0"} = 0; $vendorstats{$vendorid."_1"} = 0; $vendorstats{$vendorid."_2"} = 0; $vendorstats{$vendorid."_3"} = 0; @updatelist=<$_/*>; foreach $data (@updatelist) { if (-e "$data/source.url") { open (FILE,"$data/source.url"); $sourceurl=; close FILE; chomp($sourceurl); $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); my $size_updatefile = 0; if(-e "$data/$updatefile") { $size_updatefile = (-s "$data/$updatefile"); } else { # DEBUG #die "file not found: $data/$updatefile\n"; } # # Total file size # $filesize += $size_updatefile; # # File size for this source # $vendorstats{$vendorid."_filesize"} += $size_updatefile; # # Number of requests from cache for this source # open (FILE,"$data/access.log"); @requests=; close FILE; chomp(@requests); $counts = @requests; $counts--; $vendorstats{$vendorid."_requests"} += $counts; $cachehits += $counts; # # Total number of files in cache # $numfiles++; # # Number of files for this source # $vendorstats{$vendorid."_files"}++; # # Count cache status occurences # open (FILE,"$data/status"); $_=; close FILE; chomp; $vendorstats{$vendorid."_".$_}++; # # Calculate cached traffic for this source # $vendorstats{$vendorid."_cachehits"} += $counts * $size_updatefile; # # Calculate total cached traffic # $cachedtraffic += $counts * $size_updatefile; } } } if ($numfiles) { $efficiency = sprintf("%.1f", $cachehits / $numfiles); } 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; 1 while $cachedtraffic =~ s/^(-?\d+)(\d{3})/$1.$2/; # ---------------------------------------------------- # Show statistics # ---------------------------------------------------- &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr cache statistics'}"); unless ($numfiles) { print "$Lang::tr{'updxlrtr empty repository'}\n
\n"; } print < $Lang::tr{'updxlrtr disk usage'} END ; open(DF,"/bin/df -h $repository|"); @dfdata = ; close DF; shift(@dfdata); chomp(@dfdata); $dfstr = join(' ',@dfdata); my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr); print <
$Lang::tr{'updxlrtr cache dir'} $Lang::tr{'size'} $Lang::tr{'used'} $Lang::tr{'free'} $Lang::tr{'percentage'}
[$repository] $size $used $free END ; &percentbar($percent); print < $percent
END ; if ($numfiles) { print <
$Lang::tr{'updxlrtr summary'}
$Lang::tr{'updxlrtr total files'}: $numfiles $Lang::tr{'updxlrtr total cache size'}: $filesize
$Lang::tr{'updxlrtr efficiency index'}: $efficiency $Lang::tr{'updxlrtr total data from cache'}: $cachedtraffic

END ; $id = 0; foreach (@vendors) { $vendorid = $_; unless ($vendorstats{$vendorid . "_files"}) { next; } $id++; if ($id % 2) { print "\n"; } else { print "\n"; } print "\n"; print "\n"; } elsif ($vendorid =~ /^Microsoft$/i) { print "Microsoft \n"; print "\n"; } elsif ($vendorid =~ /^Symantec$/i) { print "Symantec \n"; print "\n"; } elsif ($vendorid =~ /^Linux$/i) { print "Linux \n"; print "\n"; } elsif ($vendorid =~ /^TrendMicro$/i) { print "Trend Micro \n"; print "\n"; } elsif ($vendorid =~ /^Apple$/i) { print "Apple \n"; print "\n"; } elsif ($vendorid =~ /^Avast$/i) { print "Avast \n"; print "\n"; } elsif ($vendorid =~ /^Avira$/i) { print "Avira \n"; print "\n"; } elsif ($vendorid =~ /^AVG$/i) { print "AVG \n"; print "\n"; } elsif ($vendorid =~ /^Ipfire$/i) { print "IPFire \n"; print "\n"; } else { if (-e "/srv/web/ipfire/html/images/updbooster/updxl-src-" . $vendorid . ".gif") { print "" . ucfirst $vendorid . " \n"; } else { print "" . ucfirst $vendorid . " \n"; } print "\n"; } print "\n"; unless ($vendorstats{$vendorid."_filesize"}) { $vendorstats{$vendorid."_filesize"} = '0'; } 1 while $vendorstats{$vendorid."_filesize"} =~ s/^(-?\d+)(\d{3})/$1.$2/; print "\n"; unless ($vendorstats{$vendorid."_cachehits"}) { $vendorstats{$vendorid."_cachehits"} = '0'; } 1 while $vendorstats{$vendorid."_cachehits"} =~ s/^(-?\d+)(\d{3})/$1.$2/; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; } print "
$Lang::tr{'updxlrtr statistics by source'}
$Lang::tr{'updxlrtr source'}   $Lang::tr{'updxlrtr files'}   $Lang::tr{'updxlrtr cache size'}   $Lang::tr{'updxlrtr data from cache'}          
 "; if ($vendorid =~ /^Adobe$/i) { print "Adobe  Adobe  Microsoft  Symantec  Linux  Trend Micro  Apple  Avast  Avira  AVG  IPFire  " . ucfirst $vendorid . " "; printf "%5d", $vendorstats{$vendorid."_files"}; print " "; printf "%15s", $vendorstats{$vendorid."_filesize"}; print " "; printf "%15s", $vendorstats{$vendorid."_cachehits"}; print " "; printf "%5d", $vendorstats{$vendorid."_1"}; print "  "; printf "%5d", $vendorstats{$vendorid."_3"}; print "  "; printf "%5d", $vendorstats{$vendorid."_2"}; print "  "; printf "%5d", $vendorstats{$vendorid."_0"}; print "   
\n"; print <
  $Lang::tr{'legend'}:   $Lang::tr{ $Lang::tr{'updxlrtr condition ok'}     $Lang::tr{ $Lang::tr{'updxlrtr condition nosource'}     $Lang::tr{ $Lang::tr{'updxlrtr condition outdated'}     $Lang::tr{ $Lang::tr{'updxlrtr condition unknown'}    
END ; } &Header::closebox(); } # ===================================================================================== # CACHE MAINTENANCE # ===================================================================================== if ($xlratorsettings{'EXTENDED_GUI'} eq 'maintenance') { # ---------------------------------------------------- # File list dialog # ---------------------------------------------------- &Header::openbox('100%', 'left', "$Lang::tr{'updxlrtr cache maintenance'}"); @sources= <$repository/download/*>; undef @repositoryfiles; foreach (@sources) { if (-d) { @updatelist = <$_/*>; $vendorid = substr($_,rindex($_,"/")+1); foreach(@updatelist) { next if(/\.info$/); $updatefile = substr($_,rindex($_,"/")+1); $updatefile .= ":download/$vendorid/$updatefile"; $updatefile = " ".$updatefile; push(@repositoryfiles,$updatefile); } } } undef (@sources); foreach (<$repository/*>) { if (-d $_) { unless (/^$repository\/download$/) { push(@sources,$_); } } } foreach (@sources) { @updatelist=<$_/*>; $vendorid = substr($_,rindex($_,"/")+1); foreach(@updatelist) { $uuid = substr($_,rindex($_,"/")+1); if (-e "$_/source.url") { open (FILE,"$_/source.url"); $sourceurl=; close FILE; chomp($sourceurl); $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl)); $_ = $updatefile; tr/[A-Z]/[a-z]/; $updatefile = "$_:$vendorid/$uuid/$updatefile"; push(@repositoryfiles,$updatefile); } } } @repositoryfiles = sort(@repositoryfiles); unless (@repositoryfiles) { print "$Lang::tr{'updxlrtr empty repository'}\n
\n"; } print < $Lang::tr{'updxlrtr disk usage'} END ; open(DF,"/bin/df -h $repository|"); @dfdata = ; close DF; shift(@dfdata); chomp(@dfdata); $dfstr = join(' ',@dfdata); my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr); print <
$Lang::tr{'updxlrtr cache dir'} $Lang::tr{'size'} $Lang::tr{'used'} $Lang::tr{'free'} $Lang::tr{'percentage'}
[$repository] $size $used $free END ; &percentbar($percent); print < $percent
END ; if (@repositoryfiles) { print <
 $Lang::tr{'updxlrtr all files'}  $Lang::tr{'updxlrtr not accessed'}
 $Lang::tr{'updxlrtr marked as'} $Lang::tr{ [$Lang::tr{'updxlrtr condition nosource'}]  $Lang::tr{'updxlrtr marked as'} $Lang::tr{ [$Lang::tr{'updxlrtr condition outdated'}]

END ; &printcurrentfiles($Lang::tr{'updxlrtr current files'}, @repositoryfiles); print "
\n\n"; &printlegendicons(); &printlegendspacer(); &printlegendstatus(); &printlegendspacer(); &printlegendsource(); print "
\n"; } &Header::closebox(); } # ===================================================================================== &Header::closebigbox(); &Header::closepage(); # ------------------------------------------------------------------- sub printcurrentfiles { my $title = shift; my @files = @_; print < $Lang::tr{'updxlrtr current files'} END ; $id = 0; foreach $updatefile (@files) { $updatefile =~ s/.*://; my $size_updatefile = 0; my $mtime = 0; if(-e "$repository/$updatefile") { $size_updatefile = (-s "$repository/$updatefile"); $mtime = &getmtime("$repository/$updatefile"); } $id++; if ($id % 2) { print "\n"; } else { print "\n"; } $filesize = $size_updatefile; 1 while $filesize =~ s/^(-?\d+)(\d{3})/$1.$2/; my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($mtime); $DAYdt = sprintf ("%.02d",$DAYdt); $MONTHdt = sprintf ("%.02d",$MONTHdt+1); $YEARdt = sprintf ("%.04d",$YEARdt+1900); $filedate = $YEARdt."-".$MONTHdt."-".$DAYdt; $lastaccess = "n/a"; $lastcheck = "n/a"; $status = $sfUnknown; unless ($updatefile =~ /^download\//) { ($vendorid,$uuid,$shortname) = split('/',$updatefile); if (-e "$repository/$vendorid/$uuid/access.log") { open (FILE,"$repository/$vendorid/$uuid/access.log"); @metadata = ; close(FILE); chomp @metadata; ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($metadata[-1]); $DAYdt = sprintf ("%.02d",$DAYdt); $MONTHdt = sprintf ("%.02d",$MONTHdt+1); $YEARdt = sprintf ("%.04d",$YEARdt+1900); if (($metadata[-1] =~ /^\d+/) && ($metadata[-1] >= 1)) { $lastaccess = $YEARdt."-".$MONTHdt."-".$DAYdt; } } if (-e "$repository/$vendorid/$uuid/checkup.log") { open (FILE,"$repository/$vendorid/$uuid/checkup.log"); @metadata = ; close(FILE); chomp @metadata; ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($metadata[-1]); $DAYdt = sprintf ("%.02d",$DAYdt); $MONTHdt = sprintf ("%.02d",$MONTHdt+1); $YEARdt = sprintf ("%.04d",$YEARdt+1900); if (($metadata[-1] =~ /^\d+/) && ($metadata[-1] >= 1)) { $lastcheck = $YEARdt."-".$MONTHdt."-".$DAYdt; } } if (-e "$repository/$vendorid/$uuid/status") { open (FILE,"$repository/$vendorid/$uuid/status"); @metadata = ; close(FILE); chomp @metadata; $status = $metadata[-1]; } } else { ($uuid,$vendorid,$shortname) = split('/',$updatefile); $status = $sfOutdated; } print "\t\t\n"; } if ($status == $sfOk) { print "$Lang::tr{ \n"; } if ($status == $sfNoSource) { print "$Lang::tr{ \n"; } if (($status == $sfOutdated) && (!($updatefile =~ /^download\//i))) { print "$Lang::tr{ \n"; } if (($status == $sfOutdated) && ($updatefile =~ /^download\//i)) { print "$Lang::tr{ \n"; } print "\t\t\n"; } elsif ($vendorid =~ /^Microsoft$/i) { print "Microsoft \n"; } elsif ($vendorid =~ /^Symantec$/i) { print "Symantec \n"; } elsif ($vendorid =~ /^Linux$/i) { print "Linux \n"; } elsif ($vendorid =~ /^TrendMicro$/i) { print "Trend Micro \n"; } elsif ($vendorid =~ /^Apple$/i) { print "Apple \n"; } elsif ($vendorid =~ /^Avast$/i) { print "Avast \n"; } elsif ($vendorid =~ /^Avira$/i) { print "Avira \n"; } elsif ($vendorid =~ /^AVG$/i) { print "AVG \n"; } elsif ($vendorid =~ /^Ipfire$/i) { print "IPFire \n"; } else { if (-e "/srv/web/ipfire/html/images/updbooster/updxl-src-" . $vendorid . ".gif") { print "" . ucfirst $vendorid . " \n"; } else { print "" . ucfirst $vendorid . " \n"; } } $shortname = substr($updatefile,rindex($updatefile,"/")+1); $shortname =~ s/(.*)_[\da-f]*(\.(exe|cab|psf)$)/$1_*$2/i; print <$shortname END ; } print "
    $Lang::tr{'updxlrtr filename'} $Lang::tr{'updxlrtr filesize'} $Lang::tr{'date'} $Lang::tr{ $Lang::tr{  
 "; if ($status == $sfUnknown) { print "$Lang::tr{  "; if ($vendorid =~ /^Adobe$/i) { print "Adobe  $filesize   $filedate   $lastaccess   $lastcheck 
\n"; } # ------------------------------------------------------------------- sub printlegenddownload { print <   $Lang::tr{'legend'}:   $Lang::tr{ $Lang::tr{'updxlrtr condition download'}     $Lang::tr{ $Lang::tr{'updxlrtr condition suspended'}     $Lang::tr{ $Lang::tr{'updxlrtr cancel download'} END ; } # ------------------------------------------------------------------- sub printlegendicons { print <   $Lang::tr{'legend'}:   $Lang::tr{ $Lang::tr{'updxlrtr last access'}   $Lang::tr{ $Lang::tr{'updxlrtr last checkup'}   $Lang::tr{ $Lang::tr{'updxlrtr remove file'}       END ; } # ------------------------------------------------------------------- sub printlegendstatus { print <   $Lang::tr{'status'}:   $Lang::tr{ $Lang::tr{'updxlrtr condition ok'}   $Lang::tr{ $Lang::tr{'updxlrtr condition nosource'}   $Lang::tr{ $Lang::tr{'updxlrtr condition outdated'}           $Lang::tr{ $Lang::tr{'updxlrtr condition download'}   $Lang::tr{ $Lang::tr{'updxlrtr condition unknown'}             END ; } # ------------------------------------------------------------------- sub printlegendsource { print <   $Lang::tr{'updxlrtr source'}:   Adobe Adobe   Apple Apple   Avast Avast   Linux Linux     Microsoft Microsoft   Symantec Symantec   Trend Micro Trend Micro   IPFire IPFire     Avira Avira   AVG AVG   $Lang::tr{ $Lang::tr{'updxlrtr other'}     END ; } # ------------------------------------------------------------------- sub printlegendspacer { print <  
END ; } # ------------------------------------------------------------------- sub savesettings { if (-e $chk_cron_dly) { unlink($chk_cron_dly); } if (-e $chk_cron_wly) { unlink($chk_cron_wly); } if (-e $chk_cron_mly) { unlink($chk_cron_mly); } if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'daily')) { symlink("../bin/checkup",$chk_cron_dly) } else { symlink("/bin/false",$chk_cron_dly) } if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'weekly')) { symlink("../bin/checkup",$chk_cron_wly) } else { symlink("/bin/false",$chk_cron_wly) } if (($xlratorsettings{'ENABLE_AUTOCHECK'} eq 'on') && ($xlratorsettings{'AUTOCHECK_SCHEDULE'} eq 'monthly')) { symlink("../bin/checkup",$chk_cron_mly) } else { symlink("/bin/false",$chk_cron_mly) } # don't save those variable to the settings file, # but we wan't to have them in the hash again after saving to file my $obsolete = $xlratorsettings{'REMOVE_OBSOLETE'}; my $nosource = $xlratorsettings{'REMOVE_NOSOURCE'}; my $outdated = $xlratorsettings{'REMOVE_OUTDATED'}; my $gui = $xlratorsettings{'EXTENDED_GUI'}; delete($xlratorsettings{'REMOVE_OBSOLETE'}); delete($xlratorsettings{'REMOVE_NOSOURCE'}); delete($xlratorsettings{'REMOVE_OUTDATED'}); delete($xlratorsettings{'EXTENDED_GUI'}); &General::writehash("${General::swroot}/updatexlrator/settings", \%xlratorsettings); # put temp variables back into the hash $xlratorsettings{'REMOVE_OBSOLETE'} = $obsolete; $xlratorsettings{'REMOVE_NOSOURCE'} = $nosource; $xlratorsettings{'REMOVE_OUTDATED'} = $outdated; $xlratorsettings{'EXTENDED_GUI'} = $gui; } # ------------------------------------------------------------------- sub percentbar { my $percent = $_[0]; my $fg = '#a0a0a0'; my $bg = '#e2e2e2'; if ($percent =~ m/^(\d+)%$/ ) { print < END ; if ($percent eq "100%") { print "" } elsif ($percent eq "0%") { print "" } else { print "" } print < END ; } } # ------------------------------------------------------------------- sub getmtime { my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]); return $mtime; } # ------------------------------------------------------------------- sub getPID { my $pid=''; my @psdata=`ps ax --no-heading`; foreach (@psdata) { if (/$_[0]/) { ($pid)=/^\s*(\d+)/; } } return $pid; } # -------------------------------------------------------------------