]>
git.ipfire.org Git - 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 # $Id: checkup,v 2.0 2007/06/17 00:00:00 marco.s Exp $
14 my $swroot='/var/ipfire';
15 my $apphome="/var/ipfire/updatexlrator";
16 my $logfile="/var/log/updatexlrator/checkup.log";
17 my $repository='/var/updatecache';
18 my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
20 my %xlratorsettings=();
33 if (-e
"$swroot/updatexlrator/settings")
35 &readhash
("$swroot/updatexlrator/settings", \
%xlratorsettings);
36 if ($xlratorsettings{'FULL_AUTOSYNC'} eq 'on') { $download=1; };
37 if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
40 if (-e
"$swroot/proxy/settings") { &readhash
("$swroot/proxy/settings", \
%proxysettings); }
42 if (-e
"$swroot/proxy/advanced/settings")
45 &readhash
("$swroot/proxy/advanced/settings", \
%proxysettings);
48 foreach (<$repository/*>)
52 unless (/^$repository\/download
$/) { push(@sources,$_); }
61 if (-e
"$_/source.url")
63 open (FILE
,"$_/source.url");
67 $updatefile = substr($sourceurl,rindex($sourceurl,'/')+1,length($sourceurl));
73 # -------------------------------------------------------------------
83 open(FILE
, $filename) or die "Unable to read file $filename";
87 ($var, $val) = split /=/, $_, 2;
93 # Untaint variables read from hash
94 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
95 $val =~ /([\w\W]*)/; $val = $1;
103 # -------------------------------------------------------------------
107 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
112 # -------------------------------------------------------------------
119 open (LOGFILE
,">>$logfile");
120 my @now = localtime(time);
121 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];
126 # -------------------------------------------------------------------
130 open (FILE
,">$_[0]");
131 print FILE
"$_[1]\n";
135 # -------------------------------------------------------------------
140 my $http_result='000 n/a';
149 open (FILE
,"$cdir/source.url");
154 $localfile = $cdir . substr($url,rindex($url,'/'),length($url));
156 if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
158 $login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
159 if ($proxysettings{'UPSTREAM_PASSWORD'})
161 $login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
165 $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
166 @http_header = `wget $login --user-agent="$useragent" --spider -S $url 2>&1`;
167 $ENV{'http_proxy'} = '';
168 &writelog
(@http_header);
170 foreach (@http_header)
173 if (/^\s*HTTP\/\d
+\
.\d
+\s\d
+\s
+\w
+/) { $http_result = $_; $http_result =~ s/^\s
*HTTP\
/\d+\.\d+\s+//; }
174 if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
175 if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP
::Date
::str2time
($remote_mtime) }
178 &writelog
($localfile);
179 &writelog
("HTTP result: $http_result");
180 &writelog
("Source size: $remote_size");
181 &writelog
("Cached size: " . (-s
$localfile));
182 &writelog
("Source time: $remote_mtime");
183 &writelog
("Cached time: " . getmtime
($localfile));
185 if ($http_result =~ /\d+\s+OK$/)
187 if (($remote_size == -s
$localfile) && ($remote_mtime == getmtime
($localfile)))
189 &writelog
("Status: Ok");
190 &setcachestatus
("$cdir/status",$sfOk);
192 &writelog
("Status: Outdated");
193 &setcachestatus
("$cdir/status",$sfOutdated);
196 &writelog
("Retrieving file from source: $remote_size bytes");
197 $_ = system("wget $login --user-agent=\"$useragent\" -q -O $localfile $url");
198 &writelog
("Download finished with code: $_");
199 if ($_ == 0) { &setcachestatus
("$cdir/status",$sfOk); }
207 &writelog
("Status: No source");
208 &setcachestatus
("$cdir/status",$sfNoSource);
210 &writelog
("Status: Error");
211 &setcachestatus
("$cdir/status",$sfUnknown);
215 &setcachestatus
("$cdir/checkup.log",time);
218 # -------------------------------------------------------------------