X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=config%2Fupdxlrator%2Fcheckup;h=b105d8d2de32da3232b2896aa2e947de64619485;hb=a8ae890ecd389c8c5f54c30a171acaa1f6666e61;hp=35c4953edc8a83a46f1dada8fd67f409a990d585;hpb=52948e87b185cc7f8ad47fb7c8680a4d66a51bef;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/config/updxlrator/checkup b/config/updxlrator/checkup index 35c4953edc..b105d8d2de 100644 --- a/config/updxlrator/checkup +++ b/config/updxlrator/checkup @@ -4,18 +4,19 @@ # # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net # -# $Id: checkup,v 2.0 2007/06/17 00:00:00 marco.s Exp $ +# Portions (c) 2008 by dotzball - http://www.blockouttraffic.de +# +# $Id: checkup,v 1.0 2008/07/15 00:00:00 marco.s Exp $ # use strict; use HTTP::Date; -my $swroot='/var/ipfire'; -my $apphome="/var/ipfire/updatexlrator"; +require '/var/ipfire/updatexlrator/updxlrator-lib.pl'; + my $logfile="/var/log/updatexlrator/checkup.log"; my $repository='/var/updatecache'; -my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; my %proxysettings=(); my %xlratorsettings=(); my $download=0; @@ -25,24 +26,20 @@ my @sources=(); my @updatelist=(); my $logging=0; -my $sfUnknown = "0"; -my $sfOk = "1"; -my $sfOutdated = "2"; -my $sfNoSource = "3"; -if (-e "$swroot/updatexlrator/settings") +if (-e "$UPDXLT::swroot/updatexlrator/settings") { - &readhash("$swroot/updatexlrator/settings", \%xlratorsettings); + &UPDXLT::readhash("$UPDXLT::swroot/updatexlrator/settings", \%xlratorsettings); if ($xlratorsettings{'FULL_AUTOSYNC'} eq 'on') { $download=1; }; if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; }; } -if (-e "$swroot/proxy/settings") { &readhash("$swroot/proxy/settings", \%proxysettings); } +if (-e "$UPDXLT::swroot/proxy/settings") { &UPDXLT::readhash("$UPDXLT::swroot/proxy/settings", \%proxysettings); } -if (-e "$swroot/proxy/advanced/settings") +if (-e "$UPDXLT::swroot/proxy/advanced/settings") { %proxysettings=(); - &readhash("$swroot/proxy/advanced/settings", \%proxysettings); + &UPDXLT::readhash("$UPDXLT::swroot/proxy/advanced/settings", \%proxysettings); } foreach (<$repository/*>) @@ -70,44 +67,8 @@ foreach (@sources) } } -# ------------------------------------------------------------------- - -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 () - { - 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 getmtime -{ - my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]); - - return $mtime; -} +# dotzball: check for dead downloads +system("$UPDXLT::apphome/bin/checkdeaddl"); # ------------------------------------------------------------------- @@ -123,14 +84,6 @@ sub writelog } } -# ------------------------------------------------------------------- - -sub setcachestatus -{ - open (FILE,">$_[0]"); - print FILE "$_[1]\n"; - close FILE; -} # ------------------------------------------------------------------- @@ -163,9 +116,8 @@ sub checksource } $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'}; - @http_header = `wget $login --user-agent="$useragent" --spider -S $url 2>&1`; + @http_header = `$UPDXLT::wget $login --user-agent="$UPDXLT::useragent" --spider -S $url 2>&1`; $ENV{'http_proxy'} = ''; - &writelog(@http_header); foreach (@http_header) { @@ -180,23 +132,23 @@ sub checksource &writelog("Source size: $remote_size"); &writelog("Cached size: " . (-s $localfile)); &writelog("Source time: $remote_mtime"); - &writelog("Cached time: " . getmtime($localfile)); + &writelog("Cached time: " . &UPDXLT::getmtime($localfile)); if ($http_result =~ /\d+\s+OK$/) { - if (($remote_size == -s $localfile) && ($remote_mtime == getmtime($localfile))) + if (($remote_size == -s $localfile) && ($remote_mtime == &UPDXLT::getmtime($localfile))) { &writelog("Status: Ok"); - &setcachestatus("$cdir/status",$sfOk); + &UPDXLT::setcachestatus("$cdir/status",$UPDXLT::sfOk); } else { &writelog("Status: Outdated"); - &setcachestatus("$cdir/status",$sfOutdated); + &UPDXLT::setcachestatus("$cdir/status",$UPDXLT::sfOutdated); if ($download) { &writelog("Retrieving file from source: $remote_size bytes"); - $_ = system("wget $login --user-agent=\"$useragent\" -q -O $localfile $url"); + $_ = system("$UPDXLT::wget $login --user-agent=\"$UPDXLT::useragent\" -q -O $localfile $url"); &writelog("Download finished with code: $_"); - if ($_ == 0) { &setcachestatus("$cdir/status",$sfOk); } + if ($_ == 0) { &UPDXLT::setcachestatus("$cdir/status",$UPDXLT::sfOk); } } } } else { @@ -205,14 +157,14 @@ sub checksource if ($_ eq '404') { &writelog("Status: No source"); - &setcachestatus("$cdir/status",$sfNoSource); + &UPDXLT::setcachestatus("$cdir/status",$UPDXLT::sfNoSource); } else { &writelog("Status: Error"); - &setcachestatus("$cdir/status",$sfUnknown); + &UPDXLT::setcachestatus("$cdir/status",$UPDXLT::sfUnknown); } } - - &setcachestatus("$cdir/checkup.log",time); + + &UPDXLT::setcachestatus("$cdir/checkup.log",time); } # -------------------------------------------------------------------