]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - config/updxlrator/checkup
3 # This code is distributed under the terms of the GPL
7 # $Id: checkup,v 1.0 2006/08/30 00:00:00 marco.s Exp $
15 my $swroot='/var/ipfire';
16 my $scriptpath=substr($0,0,rindex($0,"/"));
17 my $apphome="/var/ipfire/updatexlrator";
18 my $logfile="/var/log/updatexlrator/checkup.log";
19 my $debug=(-e
"$apphome/debug");
20 my $repository='/srv/web/ipfire/html/updatecache';
21 my %xlratorsettings=();
32 @updatelist = <$repository/*>;
38 if (-e
"$swroot/updatexlrator/settings")
40 &readhash
("$swroot/updatexlrator/settings", \
%xlratorsettings);
41 if ($xlratorsettings{'FULL_AUTOSYNC'} eq 'on') { $download=1; };
48 $updatefile = substr($_,rindex($_,"/")+1);
49 if (-e
"$repository/metadata/$updatefile")
51 open (FILE
,"$repository/metadata/$updatefile");
55 $sourceurl = $metadata[0];
57 $remote_size = &getdownloadsize
($sourceurl);
58 $local_size = (-s
"$repository/$updatefile");
60 $remote_mtime = &getlastmod
($sourceurl);
61 $local_mtime = &getmtime
("$repository/$updatefile");
63 if ($remote_mtime eq 0)
65 $metadata[2] = $sfUnknown;
66 if ($debug) { &writelog
("$updatefile - WARNING: Source not found"); }
67 print "$updatefile - WARNING: Source not found\n";
69 elsif (($local_mtime eq $remote_mtime) && ($local_size == $remote_size))
73 if ($debug) { &writelog
("$updatefile"); }
74 print "$updatefile\n";
78 $metadata[2] = $sfOutdated;
80 if ($debug) { &writelog
("$updatefile - WARNING: Out of date"); }
81 print "$updatefile - WARNING: Out of date\n";
86 1 while $remote_size =~ s/^(-?\d+)(\d{3})/$1.$2/;
87 print "Please wait, retrieving file ($remote_size Byte) from source ...";
88 `$scriptpath/../bin/wget -nd -nv -O $repository/$updatefile $sourceurl >>$logfile 2>&1`;
92 `$scriptpath/../bin/wget -nd -nv -O $repository/$updatefile $sourceurl 2>&1`;
94 $local_mtime = &getmtime
("$repository/$updatefile");
95 if ($local_mtime eq $remote_mtime) { $metadata[2] = $sfOk; }
98 open (FILE
,">$repository/metadata/$updatefile");
99 foreach (@metadata) { print FILE
"$_\n"; }
105 # -------------------------------------------------------------------
109 my $filename = $_[0];
115 open(FILE
, $filename) or die "Unable to read file $filename";
119 ($var, $val) = split /=/, $_, 2;
125 # Untaint variables read from hash
126 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
127 $val =~ /([\w\W]*)/; $val = $1;
128 $hash->{$var} = $val;
135 # -------------------------------------------------------------------
139 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
144 # -------------------------------------------------------------------
154 $url =~ s@
^(.*)://([^/]*)@@
;
159 if ((-e
"$swroot/red/active") && ($proto eq 'http'))
161 $remote = IO
::Socket
::INET
->new(
163 PeerPort
=> 'http(80)',
170 print $remote "HEAD $url HTTP/1.0\n";
171 print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
172 print $remote "Host: $fqhn\n";
173 print $remote "Accept: */*\n\n";
174 while (<$remote>) { push(@response,$_); }
176 if ($response[0] =~ /^HTTP\/\d
+\
.\d
+\s\d
+\sOK\s
*$/)
180 if (/^Last-Modified: /i)
182 s/^Last-Modified: //i;
183 $lastmoddate=HTTP
::Date
::str2time
($_);
191 # -------------------------------------------------------------------
201 $url =~ s@
^(.*)://([^/]*)@@
;
206 if ((-e
"$swroot/red/active") && ($proto eq 'http'))
208 $remote = IO
::Socket
::INET
->new(
210 PeerPort
=> 'http(80)',
217 print $remote "HEAD $url HTTP/1.0\n";
218 print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
219 print $remote "Host: $fqhn\n";
220 print $remote "Accept: */*\n\n";
221 while (<$remote>) { push(@response,$_); }
223 if ($response[0] =~ /^HTTP\/\d
+\
.\d
+\s\d
+\sOK\s
*$/)
227 if (/^Content-Length: /i)
229 s/^Content-Length: //i;
230 $contentlength=int($_);
235 return $contentlength;
238 # -------------------------------------------------------------------
242 open (LOGFILE
,">>$logfile");
243 my @now = localtime(time);
244 printf LOGFILE
"%02d:%02d:%02d %s\n",$now[2],$now[1],$now[0],$_[0];
248 # -------------------------------------------------------------------