#
# (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;
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/*>)
}
}
-# -------------------------------------------------------------------
-
-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 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");
# -------------------------------------------------------------------
}
}
-# -------------------------------------------------------------------
-
-sub setcachestatus
-{
- open (FILE,">$_[0]");
- print FILE "$_[1]\n";
- close FILE;
-}
# -------------------------------------------------------------------
}
$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)
{
&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 {
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);
}
# -------------------------------------------------------------------