Upgrade updbooster to xlrator 2.0 added to core

This commit is contained in:
Maniacikarus
2008-09-03 20:17:23 +02:00
parent cfd3bd5599
commit 0a63839688
32 changed files with 1689 additions and 674 deletions

View File

@@ -1615,17 +1615,26 @@ srv/web/ipfire/html
#srv/web/ipfire/html/images/stock_up-16.png
#srv/web/ipfire/html/images/table-header.gif
#srv/web/ipfire/html/images/up.gif
#srv/web/ipfire/html/images/updxl-gr.gif
#srv/web/ipfire/html/images/updxl-led-blue.gif
#srv/web/ipfire/html/images/updxl-led-green.gif
#srv/web/ipfire/html/images/updxl-led-red.gif
#srv/web/ipfire/html/images/updxl-led-yellow.gif
#srv/web/ipfire/html/images/updxl-rd.gif
#srv/web/ipfire/html/images/updxl-src-adobe.gif
#srv/web/ipfire/html/images/updxl-src-symantec.gif
#srv/web/ipfire/html/images/updxl-src-unknown.gif
#srv/web/ipfire/html/images/updxl-src-windows.gif
#srv/web/ipfire/html/images/updxl-yl.gif
#srv/web/ipfire/html/images/updbooster
#srv/web/ipfire/html/images/updbooster/updxl-globe.gif
#srv/web/ipfire/html/images/updbooster/updxl-led-gray.gif
#srv/web/ipfire/html/images/updbooster/updxl-led-yellow.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-apple.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-avira.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-trendmicro.gif
#srv/web/ipfire/html/images/updbooster/updxl-yl.gif
#srv/web/ipfire/html/images/updbooster/updxl-gr.gif
#srv/web/ipfire/html/images/updbooster/updxl-led-green.gif
#srv/web/ipfire/html/images/updbooster/updxl-rd.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-avast.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-linux.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-unknown.gif
#srv/web/ipfire/html/images/updbooster/updxl-led-blue.gif
#srv/web/ipfire/html/images/updbooster/updxl-led-red.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-adobe.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-avg.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-symantec.gif
#srv/web/ipfire/html/images/updbooster/updxl-src-windows.gif
#srv/web/ipfire/html/images/urlfilter
#srv/web/ipfire/html/images/urlfilter/1x1.gif
#srv/web/ipfire/html/images/urlfilter/bg_cool_tux.jpg

View File

@@ -1,9 +1,12 @@
etc/squid
etc/init.d/connectd
usr/lib/squid
usr/lib/squid/
usr/sbin/squid
srv/web/ipfire/cgi-bin/updatexlrator.cgi
bin/ntfs-3g
lib/libntfs-3g.so
lib/libntfs-3g.so.36
lib/libntfs-3g.so.36.0.0
srv/web/ipfire/html/images/updbooster
srv/web/ipfire/cgi-bin/updatexlrator.cgi
var/ipfire/updatexlrator/bin/
usr/sbin/updxlrator

View File

@@ -2,102 +2,70 @@
#
# This code is distributed under the terms of the GPL
#
# (c) 2006 marco.s
# (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
#
# $Id: checkup,v 1.0 2006/08/30 00:00:00 marco.s Exp $
# $Id: checkup,v 2.0 2007/06/17 00:00:00 marco.s Exp $
#
use strict;
use IO::Socket;
use HTTP::Date;
my $swroot='/var/ipfire';
my $scriptpath=substr($0,0,rindex($0,"/"));
my $apphome="/var/ipfire/updatexlrator";
my $logfile="/var/log/updatexlrator/checkup.log";
my $debug=(-e "$apphome/debug");
my $repository='/srv/web/ipfire/html/updatecache';
my $repository='/var/updatecache';
my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
my %proxysettings=();
my %xlratorsettings=();
my $download=0;
my $updatefile='';
my $sourceurl='';
my $remote_size=0;
my $local_size=0;
my $remote_mtime=0;
my $local_mtime=0;
my @sources=();
my @updatelist=();
my @metadata=();
@updatelist = <$repository/*>;
my $logging=0;
my $sfUnknown = "0";
my $sfOk = "1";
my $sfOutdated = "2";
my $sfNoSource = "3";
if (-e "$swroot/updatexlrator/settings")
{
&readhash("$swroot/updatexlrator/settings", \%xlratorsettings);
if ($xlratorsettings{'FULL_AUTOSYNC'} eq 'on') { $download=1; };
if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
}
foreach (@updatelist)
if (-e "$swroot/proxy/settings") { &readhash("$swroot/proxy/settings", \%proxysettings); }
if (-e "$swroot/proxy/advanced/settings")
{
if (!-d $_)
%proxysettings=();
&readhash("$swroot/proxy/advanced/settings", \%proxysettings);
}
foreach (<$repository/*>)
{
if (-d $_)
{
$updatefile = substr($_,rindex($_,"/")+1);
if (-e "$repository/metadata/$updatefile")
unless (/^$repository\/download$/) { push(@sources,$_); }
}
}
foreach (@sources)
{
@updatelist=<$_/*>;
foreach(@updatelist)
{
if (-e "$_/source.url")
{
open (FILE,"$repository/metadata/$updatefile");
@metadata = <FILE>;
close FILE;
chomp(@metadata);
$sourceurl = $metadata[0];
$remote_size = &getdownloadsize($sourceurl);
$local_size = (-s "$repository/$updatefile");
$remote_mtime = &getlastmod($sourceurl);
$local_mtime = &getmtime("$repository/$updatefile");
if ($remote_mtime eq 0)
{
$metadata[2] = $sfUnknown;
if ($debug) { &writelog("$updatefile - WARNING: Source not found"); }
print "$updatefile - WARNING: Source not found\n";
}
elsif (($local_mtime eq $remote_mtime) && ($local_size == $remote_size))
{
$metadata[2] = $sfOk;
$metadata[3] = time;
if ($debug) { &writelog("$updatefile"); }
print "$updatefile\n";
}
else
{
$metadata[2] = $sfOutdated;
$metadata[3] = time;
if ($debug) { &writelog("$updatefile - WARNING: Out of date"); }
print "$updatefile - WARNING: Out of date\n";
if ($download)
{
if ($debug)
{
1 while $remote_size =~ s/^(-?\d+)(\d{3})/$1.$2/;
print "Please wait, retrieving file ($remote_size Byte) from source ...";
`$scriptpath/../bin/wget -nd -nv -O $repository/$updatefile $sourceurl >>$logfile 2>&1`;
print "\n";
} else
{
`$scriptpath/../bin/wget -nd -nv -O $repository/$updatefile $sourceurl 2>&1`;
}
$local_mtime = &getmtime("$repository/$updatefile");
if ($local_mtime eq $remote_mtime) { $metadata[2] = $sfOk; }
}
}
open (FILE,">$repository/metadata/$updatefile");
foreach (@metadata) { print FILE "$_\n"; }
open (FILE,"$_/source.url");
$sourceurl=<FILE>;
close FILE;
chomp($sourceurl);
$updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl));
&checksource($_);
}
}
}
@@ -143,106 +111,108 @@ sub getmtime
# -------------------------------------------------------------------
sub getlastmod
{
my $remote=0;
my @response=();
my $lastmoddate=0;
my $url = $_[0];
$url =~ s@^(.*)://([^/]*)@@;
my $proto = $1;
my $fqhn = $2;
if ((-e "$swroot/red/active") && ($proto eq 'http'))
{
$remote = IO::Socket::INET->new(
PeerHost => $fqhn,
PeerPort => 'http(80)',
Timeout => 1
);
}
if ($remote)
{
print $remote "HEAD $url HTTP/1.0\n";
print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
print $remote "Host: $fqhn\n";
print $remote "Accept: */*\n\n";
while (<$remote>) { push(@response,$_); }
close $remote;
if ($response[0] =~ /^HTTP\/\d+\.\d+\s\d+\sOK\s*$/)
{
foreach (@response)
{
if (/^Last-Modified: /i)
{
s/^Last-Modified: //i;
$lastmoddate=HTTP::Date::str2time($_);
}
}
}
}
return $lastmoddate;
}
# -------------------------------------------------------------------
sub getdownloadsize
{
my $remote=0;
my @response=();
my $contentlength=0;
my $url = $_[0];
$url =~ s@^(.*)://([^/]*)@@;
my $proto = $1;
my $fqhn = $2;
if ((-e "$swroot/red/active") && ($proto eq 'http'))
{
$remote = IO::Socket::INET->new(
PeerHost => $fqhn,
PeerPort => 'http(80)',
Timeout => 1
);
}
if ($remote)
{
print $remote "HEAD $url HTTP/1.0\n";
print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
print $remote "Host: $fqhn\n";
print $remote "Accept: */*\n\n";
while (<$remote>) { push(@response,$_); }
close $remote;
if ($response[0] =~ /^HTTP\/\d+\.\d+\s\d+\sOK\s*$/)
{
foreach (@response)
{
if (/^Content-Length: /i)
{
s/^Content-Length: //i;
$contentlength=int($_);
}
}
}
}
return $contentlength;
}
# -------------------------------------------------------------------
sub writelog
{
open (LOGFILE,">>$logfile");
my @now = localtime(time);
printf LOGFILE "%02d:%02d:%02d %s\n",$now[2],$now[1],$now[0],$_[0];
close LOGFILE;
print "$_[0]\n";
if ($logging)
{
open (LOGFILE,">>$logfile");
my @now = localtime(time);
printf LOGFILE "%04d-%02d-%02d %02d:%02d:%02d %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$_[0];
close LOGFILE;
}
}
# -------------------------------------------------------------------
sub setcachestatus
{
open (FILE,">$_[0]");
print FILE "$_[1]\n";
close FILE;
}
# -------------------------------------------------------------------
sub checksource
{
my @http_header=();
my $http_result='000 n/a';
my $returncode=0;
my $localfile='';
my $remote_size=0;
my $remote_mtime=0;
my $login='';
my $url='';
my $cdir=$_[0];
open (FILE,"$cdir/source.url");
$url=<FILE>;
close FILE;
chomp($url);
$localfile = $cdir . substr($url,rindex($url,'/'),length($url));
if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
{
$login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
if ($proxysettings{'UPSTREAM_PASSWORD'})
{
$login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
}
}
$ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
@http_header = `wget $login --user-agent="$useragent" --spider -S $url 2>&1`;
$ENV{'http_proxy'} = '';
&writelog(@http_header);
foreach (@http_header)
{
chomp;
if (/^\s*HTTP\/\d+\.\d+\s\d+\s+\w+/) { $http_result = $_; $http_result =~ s/^\s*HTTP\/\d+\.\d+\s+//; }
if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP::Date::str2time($remote_mtime) }
}
&writelog($localfile);
&writelog("HTTP result: $http_result");
&writelog("Source size: $remote_size");
&writelog("Cached size: " . (-s $localfile));
&writelog("Source time: $remote_mtime");
&writelog("Cached time: " . getmtime($localfile));
if ($http_result =~ /\d+\s+OK$/)
{
if (($remote_size == -s $localfile) && ($remote_mtime == getmtime($localfile)))
{
&writelog("Status: Ok");
&setcachestatus("$cdir/status",$sfOk);
} else {
&writelog("Status: Outdated");
&setcachestatus("$cdir/status",$sfOutdated);
if ($download)
{
&writelog("Retrieving file from source: $remote_size bytes");
$_ = system("wget $login --user-agent=\"$useragent\" -q -O $localfile $url");
&writelog("Download finished with code: $_");
if ($_ == 0) { &setcachestatus("$cdir/status",$sfOk); }
}
}
} else {
$_ = $http_result;
s/\D+//;
if ($_ eq '404')
{
&writelog("Status: No source");
&setcachestatus("$cdir/status",$sfNoSource);
} else {
&writelog("Status: Error");
&setcachestatus("$cdir/status",$sfUnknown);
}
}
&setcachestatus("$cdir/checkup.log",time);
}
# -------------------------------------------------------------------

110
config/updxlrator/convert Normal file
View File

@@ -0,0 +1,110 @@
#!/usr/bin/perl
#
# This code is distributed under the terms of the GPL
#
# (c) 2007-2008 marco.s - http://update-accelerator.advproxy.net
#
# $Id: convert,v 1.0 2007/09/12 00:00:00 marco.s Exp $
#
use strict;
my $updcache='/var/updatecache/';
my @metadata=();
my $filename='';
my $uuid='';
my $vendorid='';
my @cachedirs=qw(download);
my $i=0;
my $n=0;
my $verbose=1;
my $logging=1;
my $logfile="/var/log/updatexlrator/convert.log";
if (@ARGV[0] eq '-nv') { $verbose = 0; }
if (!-d "/var/log/updatexlrator") { $logging = 0; }
&writelog("Converting cached objects from Update Accelerator 1.0 to 2.x");
&writelog("------------------------------------------------------------");
(-d "$updcache/metadata") || die "No version 1.0 cache found.\n";
if (`ps --no-heading -C wget`)
{
&writelog("WARNING: Download in progress");
print "\n";
system("killall -9 -i wget");
print "\n";
}
foreach (<$updcache/metadata/*>)
{
$filename = substr($_,rindex($_,'/')+1,length($_));
if ((-f "$updcache/$filename") && (-f "$updcache/metadata/$filename"))
{
&writelog("$filename");
open (FILE,$_);
@metadata = <FILE>;
close FILE;
chomp(@metadata);
if (@metadata >= 5)
{
$uuid = `echo $metadata[0] | md5sum`;
$uuid =~ s/[^0-9a-f]//g;
$uuid =~ s/([a-f\d]{8})([a-f\d]{4})([a-f\d]{4})([a-f\d]{4})([a-f\d]{12})/$1-$2-$3-$4-$5/;
$vendorid = $metadata[1];
$vendorid =~ tr/A-Z/a-z/;
unless (-d "$updcache/$vendorid")
{
system("mkdir $updcache/$vendorid");
push(@cachedirs,$vendorid);
}
system("chmod 775 $updcache/$vendorid");
unless (-d "$updcache/$vendorid/$uuid") { system("mkdir $updcache/$vendorid/$uuid"); }
system("chmod 775 $updcache/$vendorid/$uuid");
open (FILE,">$updcache/$vendorid/$uuid/source.url");
print FILE "$metadata[0]\n";
close FILE;
open (FILE,">$updcache/$vendorid/$uuid/status");
print FILE "$metadata[2]\n";
close FILE;
open (FILE,">$updcache/$vendorid/$uuid/checkup.log");
print FILE "$metadata[3]\n";
close FILE;
open (FILE,">$updcache/$vendorid/$uuid/access.log");
for($i=4;$i<@metadata;$i++)
{
print FILE "$metadata[$i]\n";
}
close FILE;
system("mv $updcache/$filename $updcache/$vendorid/$uuid");
system("chmod 664 $updcache/$vendorid/$uuid/*");
$n++;
} else { &writelog("WARNING: Insufficient metadata for $filename"); }
}
}
if (($n) && (-d "$updcache/metadata")) { system("rm -r $updcache/metadata"); }
foreach (@cachedirs) { system("chown -R nobody:squid $updcache/$_"); }
if ($n) { &writelog("------------------------------------------------------------"); }
$verbose=1;
&writelog("$n objects converted.");
# -------------------------------------------------------------------
sub writelog
{
if ($verbose) { print "$_[0]\n"; }
if ($logging)
{
open (LOGFILE,">>$logfile");
my @now = localtime(time);
printf LOGFILE "%04d-%02d-%02d %02d:%02d:%02d %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$_[0];
close LOGFILE;
}
}
# -------------------------------------------------------------------

View File

@@ -2,67 +2,199 @@
#
# This code is distributed under the terms of the GPL
#
# (c) 2006 marco.s
# (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
#
# $Id: download,v 1.0 2006/08/30 00:00:00 marco.s Exp $
# $Id: download,v 2.0 2008/04/06 00:00:00 marco.s Exp $
#
use strict;
use HTTP::Date;
my $swroot='/var/ipfire';
my $apphome="$swroot/updatexlrator";
my $logfile="/var/log/updatexlrator/download.log";
my $debug = 1;
my $updcachedir="/var/updatecache";
my $updfile='';
my @metadata=();
my $logging=0;
my $repository='/var/updatecache';
my $login='';
my $dlrate='';
my $uuid='';
my $wget="$apphome/bin/wget";
my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
my %xlratorsettings=();
my %proxysettings=();
my @http_header=();
my $remote_mtime=0;
my $updatefile='';
my $unique=0;
my $mirror=1;
my $sfOk="1";
my $dsturl=@ARGV[0]; if ($dsturl eq '') { exit; }
my $vendorid = @ARGV[0]; if ($vendorid eq '') { exit; }
my $sourceurl = @ARGV[1]; if ($sourceurl eq '') { exit; }
my $cfmirror = @ARGV[2]; if ($cfmirror eq '') { exit; }
$dsturl =~ s@\%2f@/@ig;
$updfile = substr($dsturl,rindex($dsturl,"/")+1);
umask(0002);
# ---------------------------------------------------------------
# Retrieve file
# ---------------------------------------------------------------
$sourceurl =~ s@\%2f@/@ig;
$sourceurl =~ s@\%7e@~@ig;
$updatefile = substr($sourceurl,rindex($sourceurl,"/")+1);
$updatefile =~ s@\%20@ @ig;
$vendorid =~ tr/A-Z/a-z/;
if ($debug)
unless (-d "$repository/download/$vendorid")
{
&writelog("Retrieving file for local cache: $updfile");
`/usr/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl >>$logfile 2>&1`;
} else
{
`/usr/bin/wget -nc -nd -nv -P $updcachedir/download $dsturl 2>&1`;
system("mkdir $repository/download/$vendorid");
system("$apphome/bin/setperms download/$vendorid");
}
if ($debug) { &writelog("Moving file into the cache directory -> \"$updcachedir/$updfile\""); }
system("mv $updcachedir/download/$updfile $updcachedir");
exit if (-e "$repository/download/$vendorid/$updatefile");
# ---------------------------------------------------------------
# Write metadata
# ---------------------------------------------------------------
system("touch $repository/download/$vendorid/$updatefile");
if ($debug) { &writelog("Writing metadata \"$updcachedir/metadata/$updfile\""); }
if ($cfmirror)
{
$uuid = `echo $updatefile | md5sum`;
} else {
$uuid = `echo $sourceurl | md5sum`;
}
open(FILE,"$updcachedir/metadata/$updfile");
@metadata = <FILE>;
close(FILE);
chomp @metadata;
$metadata[2]="$sfOk";
$metadata[3]=time;
open(FILE,">$updcachedir/metadata/$updfile");
foreach (@metadata) { print FILE "$_\n"; }
print FILE time."\n";
close(FILE);
$uuid =~ s/[^0-9a-f]//g;
$uuid =~ s/([a-f\d]{8})([a-f\d]{4})([a-f\d]{4})([a-f\d]{4})([a-f\d]{12})/$1-$2-$3-$4-$5/;
# ===============================================================
if (-e "$swroot/updatexlrator/settings")
{
&readhash("$swroot/updatexlrator/settings", \%xlratorsettings);
if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
if ($xlratorsettings{'MAX_DOWNLOAD_RATE'} ne '') { $dlrate = "--limit-rate=" . int($xlratorsettings{'MAX_DOWNLOAD_RATE'} / 8) . "k" };
}
if (-e "$swroot/proxy/settings") { &readhash("$swroot/proxy/settings", \%proxysettings); }
if (-e "$swroot/proxy/advanced/settings")
{
%proxysettings=();
&readhash("$swroot/proxy/advanced/settings", \%proxysettings);
}
if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
{
$login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
if ($proxysettings{'UPSTREAM_PASSWORD'})
{
$login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
}
}
if ($xlratorsettings{'MAX_DOWNLOAD_RATE'} eq '')
{
&writelog("Retrieving file for local cache: $updatefile");
} else {
&writelog("Retrieving file for local cache at max. " . $xlratorsettings{'MAX_DOWNLOAD_RATE'} . " kBit/s: $updatefile");
}
$ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
@http_header = `$wget $login --user-agent="$useragent" --spider -S $sourceurl 2>&1`;
$ENV{'http_proxy'} = '';
foreach (@http_header)
{
chomp;
if (/^\s*Content-Length:\s/) { s/[^0-9]//g; &writelog("Remote file size: $_ bytes"); }
if (/^\s*Last-Modified:\s/) { s/^\s*Last-Modified:\s//; $remote_mtime = HTTP::Date::str2time($_); &writelog("Remote file date: $_"); }
}
$ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
unlink "$repository/download/$vendorid/$updatefile";
$_ = system("$wget $login $dlrate --user-agent=\"$useragent\" -q -nc -P $repository/download/$vendorid $sourceurl");
$ENV{'http_proxy'} = '';
if ($_ == 0)
{
&writelog("Download finished with result code: OK");
unless (-d "$repository/$vendorid")
{
system("mkdir $repository/$vendorid");
system("$apphome/bin/setperms $vendorid");
}
unless (-d "$repository/$vendorid/$uuid")
{
system("mkdir $repository/$vendorid/$uuid");
system("$apphome/bin/setperms $vendorid/$uuid");
}
&writelog("Moving file to the cache directory: $vendorid/$uuid");
$updatefile =~ s@ @\\ @ig;
system("mv $repository/download/$vendorid/$updatefile $repository/$vendorid/$uuid");
# Workaround for IPCop's mv bug:
utime time,$remote_mtime,"$repository/$vendorid/$uuid/$updatefile";
$updatefile =~ s@\\ @ @ig;
&setcachestatus("$repository/$vendorid/$uuid/source.url",$sourceurl);
&setcachestatus("$repository/$vendorid/$uuid/status",$sfOk);
&setcachestatus("$repository/$vendorid/$uuid/checkup.log",time);
&setcachestatus("$repository/$vendorid/$uuid/access.log",time);
system("$apphome/bin/setperms $vendorid/$uuid/*");
} else {
&writelog("Download finished with result code: ERROR");
if (-e "$repository/download/$vendorid/$updatefile") { unlink ("$repository/download/$vendorid/$updatefile"); }
}
# -------------------------------------------------------------------
sub readhash
{
my $filename = $_[0];
my $hash = $_[1];
my ($var, $val);
if (-e $filename)
{
open(FILE, $filename) or die "Unable to read file $filename";
while (<FILE>)
{
chop;
($var, $val) = split /=/, $_, 2;
if ($var)
{
$val =~ s/^\'//g;
$val =~ s/\'$//g;
# Untaint variables read from hash
$var =~ /([A-Za-z0-9_-]*)/; $var = $1;
$val =~ /([\w\W]*)/; $val = $1;
$hash->{$var} = $val;
}
}
close FILE;
}
}
# -------------------------------------------------------------------
sub writelog
{
open (LOGFILE,">>$logfile");
my @now = localtime(time);
printf LOGFILE "%02d:%02d:%02d %s\n",$now[2],$now[1],$now[0],$_[0];
close LOGFILE;
if ($logging)
{
open (LOGFILE,">>$logfile");
my @now = localtime(time);
printf LOGFILE "%04d-%02d-%02d %02d:%02d:%02d [%d] %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$$,$_[0];
close LOGFILE;
}
}
# ===============================================================
# -------------------------------------------------------------------
sub setcachestatus
{
open (FILE,">$_[0]");
print FILE "$_[1]\n";
close FILE;
}
# -------------------------------------------------------------------

246
config/updxlrator/lscache Normal file
View File

@@ -0,0 +1,246 @@
#!/usr/bin/perl
#
# This code is distributed under the terms of the GPL
#
# (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
#
# $Id: lscache,v 1.0 2007/09/11 00:00:00 marco.s Exp $
#
use strict;
use Getopt::Std;
my $swroot='/var/ipfire';
my $apphome="$swroot/updatexlrator";
my $repository='/var/updatecache';
my $updatefile='';
my $sourceurl='';
my $filesize=0;
my $totalfilesize=0;
my $cachedtraffic=0;
my @updatelist=();
my @sources=();
my @requests=();
my @filelist=();
my $objectdir='';
my @tmp;
my $counts=0;
my $filedate;
my $lastaccess;
my $vendorid;
my @vendors=();
my $numfiles=0;
my $cachehits=0;
my $efficiency='0.0';
my %vendorstats=();
my $maxlength_filesize=0;
my $maxlength_request=0;
my $maxlength_vendorid=0;
getopts('adfs');
foreach (<$repository/*>)
{
if (-d $_)
{
unless ((/^$repository\/download$/) || (/^$repository\/lost\+found$/)) { push(@sources,$_); }
}
}
foreach (@sources)
{
$vendorid=substr($_,rindex($_,'/')+1,length($_));
push(@vendors,$vendorid);
@updatelist=<$_/*>;
foreach $objectdir (@updatelist)
{
if (-e "$objectdir/source.url")
{
open (FILE,"$objectdir/source.url");
$sourceurl=<FILE>;
close FILE;
chomp($sourceurl);
$updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl));
#
# Get filesize and calculate max length for output
#
$filesize = (-s "$objectdir/$updatefile");
if (length($filesize) > $maxlength_filesize) { $maxlength_filesize = length($filesize); }
#
# Total file size
#
$totalfilesize += $filesize;
#
# File size for this source
#
$vendorstats{$vendorid . "_filesize"} += $filesize;
#
# Number of requests from cache for this source
#
open (FILE,"$objectdir/access.log");
@requests=<FILE>;
close FILE;
chomp(@requests);
$counts = @requests;
$counts--;
$vendorstats{$vendorid . "_requests"} += $counts;
$cachehits += $counts;
#
# Calculate cache hits max length for output
#
if (length($cachehits) > $maxlength_request) { $maxlength_request = length($cachehits); }
#
# Get last cache access date
#
my ($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime($requests[-1]);
$DAYdt = sprintf ("%.02d",$DAYdt);
$MONTHdt = sprintf ("%.02d",$MONTHdt+1);
$YEARdt = sprintf ("%.04d",$YEARdt+1900);
if (($counts) && ($requests[-1] =~ /^\d+/) && ($requests[-1] >= 1))
{
$lastaccess = $YEARdt."-".$MONTHdt."-".$DAYdt;
} else {
$lastaccess = ' ';
}
#
# Get file modification time
#
($SECdt,$MINdt,$HOURdt,$DAYdt,$MONTHdt,$YEARdt) = localtime(&getmtime("$objectdir/$updatefile"));
$DAYdt = sprintf ("%.02d",$DAYdt);
$MONTHdt = sprintf ("%.02d",$MONTHdt+1);
$YEARdt = sprintf ("%.04d",$YEARdt+1900);
$filedate = $YEARdt."-".$MONTHdt."-".$DAYdt;
#
# Total number of files in cache
#
$numfiles++;
#
# Number of files for this source
#
$vendorstats{$vendorid . "_files"}++;
#
# Count cache status occurences
#
open (FILE,"$objectdir/status");
$_=<FILE>;
close FILE;
chomp;
$vendorstats{$vendorid . "_" . $_}++;
#
# Calculate cached traffic for this source
#
$vendorstats{$vendorid . "_cachehits"} += $counts * $filesize;
#
# Calculate total cached traffic
#
$cachedtraffic += $counts * $filesize;
#
# Calculate vendor ID max length for output
#
if (length($vendorid) > $maxlength_vendorid) { $maxlength_vendorid = length($vendorid); }
#
# Add record to filelist
#
push (@filelist,"$filesize;$filedate;$counts;$lastaccess;$vendorid;$objectdir;$updatefile");
}
}
}
@filelist || die "No matching files found in cache\n";
#
# Process statistics for output
#
if ($Getopt::Std::opt_s)
{
foreach (@vendors)
{
print "$_\n";
printf "%5d %s", $vendorstats{$_ . "_files"}, "files in cache\n";
printf "%5d %s", $vendorstats{$_ . "_requests"}, "files from cache\n";
printf "%5d %s", $vendorstats{$_ . "_1"}, "files 'Ok'\n";
printf "%5d %s", $vendorstats{$_ . "_3"}, "files 'No source'\n";
printf "%5d %s", $vendorstats{$_ . "_2"}, "files 'Outdated'\n";
printf "%5d %s", $vendorstats{$_ . "_0"}, "files 'Unknown'\n";
unless ($vendorstats{$_ . "_filesize"}) { $vendorstats{$_ . "_filesize"} = '0'; }
1 while $vendorstats{$_ . "_filesize"} =~ s/^(-?\d+)(\d{3})/$1.$2/;
printf "%15s %s", $vendorstats{$_ . "_filesize"}, "bytes in cache\n";
unless ($vendorstats{$_ . "_cachehits"}) { $vendorstats{$_ . "_cachehits"} = '0'; }
1 while $vendorstats{$_ . "_cachehits"} =~ s/^(-?\d+)(\d{3})/$1.$2/;
printf "%15s %s", $vendorstats{$_ . "_cachehits"}, "bytes from cache\n\n";
}
if ($numfiles) { $efficiency = sprintf("%.1f", $cachehits / $numfiles); }
1 while $totalfilesize =~ s/^(-?\d+)(\d{3})/$1.$2/;
1 while $cachedtraffic =~ s/^(-?\d+)(\d{3})/$1.$2/;
print "\nTotal files in cache: $numfiles\n";
print "Total cache size: $totalfilesize bytes\n";
print "Delivered from cache: $cachedtraffic bytes\n";
print "Cache efficiency index: $efficiency\n";
exit;
}
#
# Process filelist for output
#
foreach (@filelist)
{
@tmp = split(';');
printf "%$maxlength_filesize\d %s ",$tmp[0],$tmp[1];
if ($Getopt::Std::opt_a) { printf "%$maxlength_request\d %s ",$tmp[2],$tmp[3]; }
if ($Getopt::Std::opt_d) { printf "%-$maxlength_vendorid\s ",$tmp[4]; }
if ($Getopt::Std::opt_f) { print "$tmp[5]/"; }
print "$tmp[6]\n";
}
# -------------------------------------------------------------------
sub getmtime
{
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
return $mtime;
}
# -------------------------------------------------------------------
sub VERSION_MESSAGE
{
$Getopt::Std::STANDARD_HELP_VERSION=1;
print <<EOM
lscache (Update Accelerator coreutils) 1.00
Copyright (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
EOM
;
}
# -------------------------------------------------------------------
sub HELP_MESSAGE
{
print <<EOM
Usage: lscache [-adf | -s]
Shows details about the Update Accelerator cache content
File listing:
-a list number of cache hits and last access date
-d list download source
-f list full cache path
Statistics:
-s show statistics by source
--help display this help
--version output version information
EOM
;
}
# -------------------------------------------------------------------

BIN
config/updxlrator/setperms Normal file

Binary file not shown.

View File

@@ -2,50 +2,39 @@
#
# This code is distributed under the terms of the GPL
#
# (c) 2006 marco.s
# (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
#
# $Id: updxlrator,v 1.0 2006/10/03 00:00:00 marco.s Exp $
# $Id: updxlrator,v 2.0 2008/04/06 00:00:00 marco.s Exp $
#
use strict;
use IO::Socket;
use HTTP::Date;
$|=1;
my $swroot="/var/ipfire";
my $updcachedir="/var/updatecache";
my %netsettings=();
my %xlratorsettings=();
my $http_port="81";
my $apphome="/var/ipfire/updatexlrator";
my $logfile="/var/log/updatexlrator/cache.log";
my $wget="$apphome/bin/wget";
my $debug=(-e "$apphome/debug");
my $http_port='81';
my %netsettings=();
my %proxysettings=();
my %xlratorsettings=();
my $logging=0;
my $passive_mode=0;
my $maxusage=0;
my $nice='';
my @tmp=();
my $now='';
my $request='';
my $from_local_cache=0;
my $dsturl='';
my $xlrator_url=0;
my $source_url='';
my $hostaddr='';
my $username='';
my $method='';
my @metadata=();
my $sfNoSource = "0";
my $sfOk = "1";
my $sfOutdated = "2";
unless (-d "$updcachedir/metadata")
{
unless (-d "$updcachedir") { mkdir "$updcachedir"; }
mkdir "$updcachedir/metadata";
system("chown nobody.squid $updcachedir");
system("chmod 775 $updcachedir");
system("chown nobody.squid $updcachedir/metadata");
system("chmod 775 $updcachedir/metadata");
}
my $unique = 0;
my $mirror = 1;
readhash("${swroot}/ethernet/settings", \%netsettings);
@@ -55,7 +44,7 @@ if (-e "$swroot/updatexlrator/settings")
if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
if ($xlratorsettings{'PASSIVE_MODE'} eq 'on') { $passive_mode=1; };
$maxusage=$xlratorsettings{'MAX_DISK_USAGE'};
if ($xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} eq 'on') { $nice='/bin/nice --adjustment=15 '; };
if ($xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} eq 'on') { $nice='/usr/bin/nice --adjustment=15 '; };
}
if (!$maxusage) { $maxusage=75; };
@@ -63,15 +52,16 @@ if (!$maxusage) { $maxusage=75; };
while (<>) {
$request=$_;
$from_local_cache=0;
@tmp=split(/ /,$request);
chomp(@tmp);
$dsturl =$tmp[0];
$hostaddr=$tmp[1]; while ($hostaddr =~ /.*\/$/) { chop $hostaddr; }
$username=$tmp[2]; if ($username eq '') { $username='-'; };
$method =$tmp[3];
$source_url = $tmp[0];
$hostaddr = $tmp[1]; while ($hostaddr =~ /.*\/$/) { chop $hostaddr; }
$username = $tmp[2]; if ($username eq '') { $username='-'; };
$method = $tmp[3];
$xlrator_url = $source_url;
if (($method eq 'GET') || ($method eq 'HEAD'))
{
@@ -81,105 +71,114 @@ while (<>) {
# -----------------------------------------------------------
if (
(($dsturl =~ m@^http://[^/]*\.microsoft\.com/.*\.(exe|psf|msi)$@i) ||
($dsturl =~ m@^http://[^/]*\.windowsupdate\.com/.*\.(exe|psf|cab)$@i))
&& ($dsturl !~ m@^http://[^/]*\.microsoft\.com/.*(/autoupd|selfupdate/).*\.cab@i)
&& ($dsturl !~ m@\&@)
(($source_url =~ m@^http://[^/]*\.microsoft\.com/.*\.(exe|psf|msi|msp|cab)$@i) ||
($source_url =~ m@^http://[^/]*\.windowsupdate\.com/.*\.(exe|psf|msi|msp|cab)$@i))
&& ($source_url !~ m@^http://[^/]*\.microsoft\.com/.*(/autoupd|selfupdate/).*\.cab@i)
&& ($source_url !~ m@\&@)
)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Microsoft");
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Microsoft",$unique);
}
# -----------------------------------------------------------
# Section: Adobe Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^http://(ar)?download\.adobe\.com/.*\.(exe|bin|dmg|idx|gz)$@i)
if (
($source_url =~ m@^http://(ar)?download\.adobe\.com/.*\.(exe|msi|bin|dmg|idx|gz)$@i) ||
($source_url =~ m@^http://swupdl\.adobe\.com/updates/.*\.(exe|msi|bin|dmg|idx|gz|[a-z][a-z]_[A-Z][A-Z])$@i) ||
($source_url =~ m@^http://swupmf\.adobe\.com/manifest/.*\.upd$@i)
)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Adobe");
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Adobe",$unique);
}
# -----------------------------------------------------------
# Section: Linux Downloads
# -----------------------------------------------------------
if ($source_url =~ m@^[h|f]t?tp://[^?]+\.(deb|rpm)$@i)
{
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Linux",$mirror);
}
# -----------------------------------------------------------
# Section: Trend Micro Downloads
# -----------------------------------------------------------
if (
($source_url =~ m@^http://[^/]*\.trendmicro\.com/activeupdate/.*@i) &&
($source_url !~ m@.*/tmnotify\.dat$@i) &&
($source_url !~ m@.*/ini_xml\.zip$@i) &&
($source_url !~ m@.*/server\.ini$@i)
)
{
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"TrendMicro",$mirror);
}
# -----------------------------------------------------------
# Section: Symantec Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^[f|h]t?tp://[^/]*\.symantec(liveupdate)?\.com/.*\.(exe|zip|xdb)$@i)
if ($source_url =~ m@^[h|f]tt?p://[^/]*\.symantec(liveupdate)?\.com/.*\.(exe|zip|vdb|xdb)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Symantec");
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Symantec",$unique);
}
# -----------------------------------------------------------
# Section: Apple Downloads
# -----------------------------------------------------------
if (
(($source_url =~ m@^http://swcdn\.apple\.com/content/downloads/.*\.(tar)$@i) ||
($source_url =~ m@^http://appldnld\.apple\.com\.edgesuite\.net/.*\.(exe|dmg)$@i) ||
($source_url =~ m@^http://.*\.g.akamai.net/.*/3093/1/.*\.(tar|pkg|dmg|exe)$@i))
)
{
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Apple",$unique);
}
# -----------------------------------------------------------
# Section: Avast Downloads
# -----------------------------------------------------------
if ($source_url =~ m@^http://download[\d]+\.avast\.com/.*\.(exe|vpu)$@i)
{
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Avast",$mirror);
}
# -----------------------------------------------------------
# -----------------------------------------------------------
# Section: Avira Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^http://dl[0-9]\.avgate\.net/.*\.(htm|html|gz)$@i)
if ($source_url =~ m@^http://dl[0-9]\.avgate\.net/.*\.(htm|html|gz)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Avira");
}
# -----------------------------------------------------------
# Section: Avast Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^http://download[0-99]\.avast\.com/.*\.(exe|zip|vps|stamp|vpu)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Avast");
}
# -----------------------------------------------------------
# Section: IPFire Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^[f|h]t?tp://.*\.(ipfire)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"IPFire");
}
# -----------------------------------------------------------
# Section: Linux Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^[f|h]t?tp://.*\.(deb|rpm)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Linux");
}
# -----------------------------------------------------------
# -----------------------------------------------------------
# Section: Apple Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^[f|h]t?tp://swcdn\.apple.*\.(pkm|tar)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Apple");
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"Avira",$mirror);
}
# -----------------------------------------------------------
# Section: IPFire Downloads
# -----------------------------------------------------------
if ($source_url =~ m@^[f|h]t?tp://.*\.(ipfire)$@i)
{
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"IPFire",$mirror);
}
}
# -----------------------------------------------------------
# Section: AVG Downloads
# -----------------------------------------------------------
if ($dsturl =~ m@^http://[^/]*\.(grisoft|avg)\.com/.*\.(bin)$@i)
if ($source_url =~ m@^http://[^/]*\.(grisoft|avg)\.com/.*\.(bin)$@i)
{
$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"AVG");
$xlrator_url = &check_cache($source_url,$hostaddr,$username,"AVG",$mirror);
}
# -----------------------------------------------------------
# Section: Kaspersky Downloads
# not working properly
# -----------------------------------------------------------
#if ($dsturl =~ m@^http://dnl-.*\.kaspersky-labs\.com\/(diffs|bases|AutoPatches).*$@i)
#{
#$from_local_cache = &cache_access($dsturl,$hostaddr,$username,"Kaspersky");
#}
# -----------------------------------------------------------
}
if ($from_local_cache) { $request="http://$netsettings{'GREEN_ADDRESS'}:$http_port/updatecache/".substr($dsturl,rindex($dsturl,"/")+1)." $hostaddr $username $method\n"; }
$request="$xlrator_url $hostaddr $username $method\n";
print $request;
}
@@ -218,29 +217,51 @@ sub readhash
sub writelog
{
open(LOGFILE,">>$logfile");
print LOGFILE time." $_[0] $_[1] $_[2] $_[3] $_[4]\n";
close(LOGFILE);
if ($logging)
{
open(LOGFILE,">>$logfile");
print LOGFILE time." $_[0] $_[1] $_[2] $_[3] $_[4]\n";
close(LOGFILE);
}
}
# -------------------------------------------------------------------
sub diskfree
sub debuglog
{
open(DF,"/bin/df --block-size=1 $_[0]|");
while(<DF>)
if ($debug)
{
unless ($_ =~ m/^Filesystem/ )
{
my ($device,$size,$used,$free,$percent,$mount) = split;
if ($free =~ m/^(\d+)$/)
{
close DF;
return $free;
}
}
open(LOGFILE,">>/var/log/updatexlrator/debug.log");
my @now = localtime(time);
printf LOGFILE "%04d-%02d-%02d %02d:%02d:%02d [%d] [%s] %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$$,"updxlrator",$_[0];
close(LOGFILE);
}
}
# -------------------------------------------------------------------
sub setcachestatus
{
open (FILE,">>$_[0]");
print FILE "$_[1]\n";
close FILE;
}
# -------------------------------------------------------------------
sub diskfree
{
open(DF,"/bin/df --block-size=1 $_[0]|");
my @dfdata = <DF>;
close DF;
shift(@dfdata);
chomp(@dfdata);
my $dfstr = join(' ',@dfdata);
my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
if ($free =~ m/^(\d+)$/)
{
return $free;
}
}
# -------------------------------------------------------------------
@@ -248,106 +269,126 @@ sub diskfree
sub diskusage
{
open(DF,"/bin/df $_[0]|");
while(<DF>)
{
unless ($_ =~ m/^Filesystem/ )
{
my ($device,$size,$used,$free,$percent,$mount) = split;
if ($percent =~ m/^(\d+)%$/)
{
close DF;
$percent =~ s/%$//;
return $percent;
}
}
}
my @dfdata = <DF>;
close DF;
shift(@dfdata);
chomp(@dfdata);
my $dfstr = join(' ',@dfdata);
my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
if ($percent =~ m/^(\d+)%$/)
{
$percent =~ s/%$//;
return $percent;
}
}
# -------------------------------------------------------------------
sub getdownloadsize
sub getmtime
{
my $remote=0;
my @response=();
my $contentlength=0;
my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
my $url = $_[0];
$url =~ s@^(.*)://([^/]*)@@;
my $proto = $1;
my $fqhn = $2;
if ((-e "$swroot/red/active") && ($proto eq 'http'))
{
$remote = IO::Socket::INET->new(
PeerHost => $fqhn,
PeerPort => 'http(80)',
Timeout => 1
);
}
if ($remote)
{
print $remote "HEAD $url HTTP/1.0\n";
print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
print $remote "Host: $fqhn\n";
print $remote "Accept: */*\n\n";
while (<$remote>) { push(@response,$_); }
close $remote;
if ($response[0] =~ /^HTTP\/\d+\.\d+\s\d+\sOK\s*$/)
{
foreach (@response)
{
if (/^Content-Length: /i)
{
s/^Content-Length: //i;
$contentlength=$_;
}
}
}
}
return $contentlength;
return $mtime;
}
# -------------------------------------------------------------------
sub cache_access
sub check_cache
{
my $updsource="UPDCACHE";
my $updfile='';
my $do_redirect=0;
my $cacheurl='';
my $vendorid='';
my $uuid='';
my @http_header=();
my $remote_size=0;
my $remote_mtime=0;
my $login='';
my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$_[0] =~ s@\%2f@/@ig;
$updfile = substr($_[0],rindex($_[0],"/")+1);
my $sourceurl=$_[0];
my $cfmirror=$_[4];
if (!-e "$updcachedir/metadata/$updfile")
$sourceurl =~ s@\%2f@/@ig;
$updfile = substr($sourceurl,rindex($sourceurl,"/")+1);
$updfile =~ s@\%20@ @ig;
if ($cfmirror)
{
open(FILE,">$updcachedir/metadata/$updfile");
print FILE "$_[0]\n$_[3]\n$sfOutdated\n0\n";
close(FILE);
$uuid = `echo $updfile | md5sum`;
} else {
$uuid = `echo $sourceurl | md5sum`;
}
if (-e "$updcachedir/$updfile")
$uuid =~ s/[^0-9a-f]//g;
$uuid =~ s/([a-f\d]{8})([a-f\d]{4})([a-f\d]{4})([a-f\d]{4})([a-f\d]{12})/$1-$2-$3-$4-$5/;
$vendorid = $_[3];
$vendorid =~ tr/A-Z/a-z/;
&debuglog("Processing URL $sourceurl");
&debuglog("Vendor ID is $vendorid");
&debuglog("UUID is $uuid");
if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
{
open(FILE,">>$updcachedir/metadata/$updfile");
print FILE time."\n";
close(FILE);
$do_redirect=1;
}
else
{
$updsource="DLSOURCE";
if ((!$passive_mode) && (&diskusage($updcachedir) <= $maxusage) && (&getdownloadsize <= &diskfree($updcachedir)) && (!-e "$updcachedir/download/$updfile"))
$login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
if ($proxysettings{'UPSTREAM_PASSWORD'})
{
system("$nice/var/ipfire/updatexlrator/bin/download $_[0] &");
$login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
}
}
if ($logging) { &writelog($_[1],$_[2],$_[3],$updsource,$_[0]); }
if ($proxysettings{'UPSTREAM_PROXY'}) { &debuglog("Using upstream proxy $proxysettings{'UPSTREAM_PROXY'}"); }
return $do_redirect;
$ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
@http_header = `$wget $login --user-agent="$useragent" --spider -S $sourceurl 2>&1`;
$ENV{'http_proxy'} = '';
foreach (@http_header)
{
chomp;
if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP::Date::str2time($remote_mtime) }
}
if (
(-e "$updcachedir/$vendorid/$uuid/$updfile") &&
($remote_size == (-s "$updcachedir/$vendorid/$uuid/$updfile")) &&
($remote_mtime == &getmtime("$updcachedir/$vendorid/$uuid/$updfile"))
)
{
&debuglog("File exists in cache and is up to date");
&debuglog("Retrieving file from cache ($updsource)");
&setcachestatus("$updcachedir/$vendorid/$uuid/access.log",time);
system("$apphome/bin/setperms $vendorid/$uuid/access.log");
$cacheurl="http://$netsettings{'GREEN_ADDRESS'}:$http_port/updatecache/$vendorid/$uuid/$updfile";
}
else
{
if (-e "$updcachedir/$vendorid/$uuid/$updfile")
{
&debuglog("Local filesize: " . (-s "$updcachedir/$vendorid/$uuid/$updfile"));
&debuglog("Local timestamp: " . &getmtime("$updcachedir/$vendorid/$uuid/$updfile"));
} else { &debuglog("File not found in cache"); }
$updsource="DLSOURCE";
&debuglog("Remote filesize: $remote_size");
&debuglog("Remote timestamp: $remote_mtime");
&debuglog("Free disk space: " . &diskfree($updcachedir));
&debuglog("Disk usage: " . &diskusage($updcachedir) . "% (max. $maxusage%)");
if (-e "$updcachedir/download/$vendorid/$updfile") { &debuglog("File download/$vendorid/$updfile exists"); }
&debuglog("Retrieving file from source ($updsource)");
if ((!$passive_mode) && (&diskusage($updcachedir) <= $maxusage) && ($remote_size <= &diskfree($updcachedir)) && (!-e "$updcachedir/download/$vendorid/$updfile"))
{
&debuglog("Running command $nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
system("$nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
}
$cacheurl=$sourceurl;
}
&writelog($_[1],$_[2],$_[3],$updsource,$sourceurl);
return $cacheurl;
}
# -------------------------------------------------------------------

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 898 B

View File

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 B

View File

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 898 B

View File

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 898 B

View File

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

View File

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 898 B

View File

Before

Width:  |  Height:  |  Size: 1000 B

After

Width:  |  Height:  |  Size: 1000 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 996 B

After

Width:  |  Height:  |  Size: 996 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 1017 B

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 898 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

Before

Width:  |  Height:  |  Size: 158 B

After

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1010 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB