]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/updxlrator/checkup
3 # This code is distributed under the terms of the GPL
5 # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
7 # Portions (c) 2008 by dotzball - http://www.blockouttraffic.de
9 # $Id: checkup,v 1.0 2008/07/15 00:00:00 marco.s Exp $
16 require '/var/ipfire/updatexlrator/updxlrator-lib.pl';
18 my $logfile="/var/log/updatexlrator/checkup.log";
19 my $repository='/var/updatecache';
21 my %xlratorsettings=();
30 if (-e
"$UPDXLT::swroot/updatexlrator/settings")
32 &UPDXLT
::readhash
("$UPDXLT::swroot/updatexlrator/settings", \
%xlratorsettings);
33 if ($xlratorsettings{'FULL_AUTOSYNC'} eq 'on') { $download=1; };
34 if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
37 if (-e
"$UPDXLT::swroot/proxy/settings") { &UPDXLT
::readhash
("$UPDXLT::swroot/proxy/settings", \
%proxysettings); }
39 if (-e
"$UPDXLT::swroot/proxy/advanced/settings")
42 &UPDXLT
::readhash
("$UPDXLT::swroot/proxy/advanced/settings", \
%proxysettings);
45 foreach (<$repository/*>)
49 unless (/^$repository\/download
$/) { push(@sources,$_); }
58 if (-e
"$_/source.url")
60 open (FILE
,"$_/source.url");
64 $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl));
70 # dotzball: check for dead downloads
71 system("$UPDXLT::apphome/bin/checkdeaddl");
73 # -------------------------------------------------------------------
80 open (LOGFILE
,">>$logfile");
81 my @now = localtime(time);
82 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];
88 # -------------------------------------------------------------------
93 my $http_result='000 n/a';
102 open (FILE
,"$cdir/source.url");
107 $localfile = $cdir . substr($url,rindex($url,'/'),length($url));
109 if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
111 $login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
112 if ($proxysettings{'UPSTREAM_PASSWORD'})
114 $login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
118 $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
119 @http_header = `$UPDXLT::wget $login --user-agent="$UPDXLT::useragent" --spider -S $url 2>&1`;
120 $ENV{'http_proxy'} = '';
122 foreach (@http_header)
125 if (/^\s*HTTP\/\d
+\
.\d
+\s\d
+\s
+\w
+/) { $http_result = $_; $http_result =~ s/^\s
*HTTP\
/\d+\.\d+\s+//; }
126 if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
127 if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP
::Date
::str2time
($remote_mtime) }
130 &writelog
($localfile);
131 &writelog
("HTTP result: $http_result");
132 &writelog
("Source size: $remote_size");
133 &writelog
("Cached size: " . (-s
$localfile));
134 &writelog
("Source time: $remote_mtime");
135 &writelog
("Cached time: " . &UPDXLT
::getmtime
($localfile));
137 if ($http_result =~ /\d+\s+OK$/)
139 if (($remote_size == -s
$localfile) && ($remote_mtime == &UPDXLT
::getmtime
($localfile)))
141 &writelog
("Status: Ok");
142 &UPDXLT
::setcachestatus
("$cdir/status",$UPDXLT::sfOk
);
144 &writelog
("Status: Outdated");
145 &UPDXLT
::setcachestatus
("$cdir/status",$UPDXLT::sfOutdated
);
148 &writelog
("Retrieving file from source: $remote_size bytes");
149 $_ = system("$UPDXLT::wget $login --user-agent=\"$UPDXLT::useragent\" -q -O $localfile $url");
150 &writelog
("Download finished with code: $_");
151 if ($_ == 0) { &UPDXLT
::setcachestatus
("$cdir/status",$UPDXLT::sfOk
); }
159 &writelog
("Status: No source");
160 &UPDXLT
::setcachestatus
("$cdir/status",$UPDXLT::sfNoSource
);
162 &writelog
("Status: Error");
163 &UPDXLT
::setcachestatus
("$cdir/status",$UPDXLT::sfUnknown
);
167 &UPDXLT
::setcachestatus
("$cdir/checkup.log",time);
170 # -------------------------------------------------------------------