]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/updxlrator/updxlrator
3 # This code is distributed under the terms of the GPL
7 # $Id: updxlrator,v 1.0 2006/10/03 00:00:00 marco.s Exp $
16 my $swroot="/var/ipfire";
17 my $updcachedir="/srv/web/ipfire/html/updatecache";
19 my %xlratorsettings=();
21 my $logfile="/var/log/updatexlrator/cache.log";
29 my $from_local_cache=0;
40 unless (-d
"$updcachedir/metadata")
42 unless (-d
"$updcachedir") { mkdir "$updcachedir"; }
43 mkdir "$updcachedir/metadata";
44 system("chown nobody.squid $updcachedir");
45 system("chmod 775 $updcachedir");
46 system("chown nobody.squid $updcachedir/metadata");
47 system("chmod 775 $updcachedir/metadata");
50 readhash
("${swroot}/ethernet/settings", \
%netsettings);
52 if (-e
"$swroot/updatexlrator/settings")
54 &readhash
("$swroot/updatexlrator/settings", \
%xlratorsettings);
55 if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
56 if ($xlratorsettings{'PASSIVE_MODE'} eq 'on') { $passive_mode=1; };
57 $maxusage=$xlratorsettings{'MAX_DISK_USAGE'};
58 if ($xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} eq 'on') { $nice='/bin/nice --adjustment=15 '; };
60 if (!$maxusage) { $maxusage=75; };
68 @tmp=split(/ /,$request);
72 $hostaddr=$tmp[1]; while ($hostaddr =~ /.*\/$/) { chop $hostaddr; }
73 $username=$tmp[2]; if ($username eq '') { $username='-'; };
76 if (($method eq 'GET') || ($method eq 'HEAD'))
79 # -----------------------------------------------------------
80 # Section: Windows Update / Windows Downloads
81 # -----------------------------------------------------------
84 (($dsturl =~ m@
^http
://[^/]*\.microsoft\.com/.*\
.(exe
|psf
|msi
)$@i) ||
85 ($dsturl =~ m@
^http
://[^/]*\.windowsupdate\.com/.*\
.(exe
|psf
|cab
)$@i))
86 && ($dsturl !~ m@
^http
://[^/]*\.microsoft\.com/.*(/autoupd|selfupdate/).*\
.cab
@i)
90 $from_local_cache = &cache_access
($dsturl,$hostaddr,$username,"Microsoft");
93 # -----------------------------------------------------------
94 # Section: Adobe Downloads
95 # -----------------------------------------------------------
97 if ($dsturl =~ m@
^http
://(ar
)?download\
.adobe\
.com
/.*\
.(exe
|bin
|dmg
|idx
|gz
)$@i)
99 $from_local_cache = &cache_access
($dsturl,$hostaddr,$username,"Adobe");
102 # -----------------------------------------------------------
103 # Section: Symantec Downloads
104 # -----------------------------------------------------------
106 if ($dsturl =~ m@
^[f
|h
]t?tp
://[^/]*\.symantec(liveupdate)?\.com/.*\
.(exe
|zip
|xdb
)$@i)
108 $from_local_cache = &cache_access
($dsturl,$hostaddr,$username,"Symantec");
111 # -----------------------------------------------------------
112 # Section: Avira Downloads
113 # -----------------------------------------------------------
115 if ($dsturl =~ m@
^http
://dl[0-9]\
.avgate\
.net
/.*\
.(htm
|html
|gz
)$@i)
117 $from_local_cache = &cache_access
($dsturl,$hostaddr,$username,"Avira");
120 # -----------------------------------------------------------
121 # Section: Avast Downloads
122 # -----------------------------------------------------------
124 if ($dsturl =~ m@
^http
://download
[0-99]\
.avast\
.com
/.*\
.(exe
|zip
|vps
|stamp
|vpu
)$@i)
126 $from_local_cache = &cache_access
($dsturl,$hostaddr,$username,"Avast");
129 # -----------------------------------------------------------
133 if ($from_local_cache) { $request="http://$netsettings{'GREEN_ADDRESS'}:$http_port/updatecache/".substr($dsturl,rindex($dsturl,"/")+1)." $hostaddr $username $method\n"; }
138 # -------------------------------------------------------------------
142 my $filename = $_[0];
148 open(FILE
, $filename) or die "Unable to read file $filename";
152 ($var, $val) = split /=/, $_, 2;
158 # Untaint variables read from hash
159 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
160 $val =~ /([\w\W]*)/; $val = $1;
161 $hash->{$var} = $val;
168 # -------------------------------------------------------------------
172 open(LOGFILE
,">>$logfile");
173 print LOGFILE
time." $_[0] $_[1] $_[2] $_[3] $_[4]\n";
177 # -------------------------------------------------------------------
181 open(DF
,"/bin/df --block-size=1 $_[0]|");
184 unless ($_ =~ m/^Filesystem/ )
186 my ($device,$size,$used,$free,$percent,$mount) = split;
187 if ($free =~ m/^(\d+)$/)
197 # -------------------------------------------------------------------
201 open(DF
,"/bin/df $_[0]|");
204 unless ($_ =~ m/^Filesystem/ )
206 my ($device,$size,$used,$free,$percent,$mount) = split;
207 if ($percent =~ m/^(\d+)%$/)
218 # -------------------------------------------------------------------
228 $url =~ s@
^(.*)://([^/]*)@@
;
233 if ((-e
"$swroot/red/active") && ($proto eq 'http'))
235 $remote = IO
::Socket
::INET
->new(
237 PeerPort
=> 'http(80)',
244 print $remote "HEAD $url HTTP/1.0\n";
245 print $remote "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\n";
246 print $remote "Host: $fqhn\n";
247 print $remote "Accept: */*\n\n";
248 while (<$remote>) { push(@response,$_); }
250 if ($response[0] =~ /^HTTP\/\d
+\
.\d
+\s\d
+\sOK\s
*$/)
254 if (/^Content-Length: /i)
256 s/^Content-Length: //i;
262 return $contentlength;
265 # -------------------------------------------------------------------
269 my $updsource="UPDCACHE";
273 $_[0] =~ s@\
%2f@
/@ig;
274 $updfile = substr($_[0],rindex($_[0],"/")+1);
276 if (!-e
"$updcachedir/metadata/$updfile")
278 open(FILE
,">$updcachedir/metadata/$updfile");
279 print FILE
"$_[0]\n$_[3]\n$sfOutdated\n0\n";
283 if (-e
"$updcachedir/$updfile")
285 open(FILE
,">>$updcachedir/metadata/$updfile");
286 print FILE
time."\n";
292 $updsource="DLSOURCE";
293 if ((!$passive_mode) && (&diskusage
($updcachedir) <= $maxusage) && (&getdownloadsize
<= &diskfree
($updcachedir)) && (!-e
"$updcachedir/download/$updfile"))
295 system("$nice/var/ipfire/updatexlrator/bin/download $_[0] &");
299 if ($logging) { &writelog
($_[1],$_[2],$_[3],$updsource,$_[0]); }
304 # -------------------------------------------------------------------