]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - config/updxlrator/updxlrator
ffbc9c7ab617a3d5612d493da7363f1fccec8702
3 # This code is distributed under the terms of the GPL
5 # (c) 2006-2008 marco.s - http://update-accelerator.advproxy.net
7 # $Id: updxlrator,v 2.0 2008/04/06 00:00:00 marco.s Exp $
15 my $swroot="/var/ipfire";
16 my $updcachedir="/var/updatecache";
17 my $apphome="/var/ipfire/updatexlrator";
18 my $logfile="/var/log/updatexlrator/cache.log";
19 my $wget="$apphome/bin/wget";
20 my $debug=(-e
"$apphome/debug");
24 my %xlratorsettings=();
39 readhash
("${swroot}/ethernet/settings", \
%netsettings);
41 if (-e
"$swroot/updatexlrator/settings")
43 &readhash
("$swroot/updatexlrator/settings", \
%xlratorsettings);
44 if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
45 if ($xlratorsettings{'PASSIVE_MODE'} eq 'on') { $passive_mode=1; };
46 $maxusage=$xlratorsettings{'MAX_DISK_USAGE'};
47 if ($xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} eq 'on') { $nice='/usr/bin/nice --adjustment=15 '; };
49 if (!$maxusage) { $maxusage=75; };
56 @tmp=split(/ /,$request);
59 $source_url = $tmp[0];
60 $hostaddr = $tmp[1]; while ($hostaddr =~ /.*\/$/) { chop $hostaddr; }
61 $username = $tmp[2]; if ($username eq '') { $username='-'; };
64 $xlrator_url = $source_url;
66 if (($method eq 'GET') || ($method eq 'HEAD'))
69 # -----------------------------------------------------------
70 # Section: Windows Update / Windows Downloads
71 # -----------------------------------------------------------
74 (($source_url =~ m@
^http
://[^/]*\.microsoft\.com/.*\
.(exe
|psf
|msi
|msp
|cab
)$@i) ||
75 ($source_url =~ m@
^http
://[^/]*\.windowsupdate\.com/.*\
.(exe
|psf
|msi
|msp
|cab
)$@i))
76 && ($source_url !~ m@
^http
://[^/]*\.microsoft\.com/.*(/autoupd|selfupdate/).*\
.cab
@i)
77 && ($source_url !~ m@\
&@
)
80 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Microsoft",$unique);
83 # -----------------------------------------------------------
84 # Section: Adobe Downloads
85 # -----------------------------------------------------------
88 ($source_url =~ m@
^http
://(ar
)?download\
.adobe\
.com
/.*\
.(exe
|msi
|bin
|dmg
|idx
|gz
)$@i) ||
89 ($source_url =~ m@
^http
://swupdl\
.adobe\
.com
/updates
/.*\
.(exe
|msi
|bin
|dmg
|idx
|gz
|[a
-z
][a
-z
]_
[A
-Z
][A
-Z
])$@i) ||
90 ($source_url =~ m@
^http
://swupmf\
.adobe\
.com
/manifest
/.*\
.upd
$@i)
93 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Adobe",$unique);
96 # -----------------------------------------------------------
97 # Section: Linux Downloads
98 # -----------------------------------------------------------
100 if ($source_url =~ m@
^[h
|f
]t?tp
://[^?
]+\
.(deb
|rpm
)$@i)
102 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Linux",$mirror);
105 # -----------------------------------------------------------
106 # Section: Trend Micro Downloads
107 # -----------------------------------------------------------
110 ($source_url =~ m@
^http
://[^/]*\.trendmicro\.com/activeupdate
/.*@i) &&
111 ($source_url !~ m@
.*/tmnotify\
.dat
$@i) &&
112 ($source_url !~ m@
.*/ini_xml\
.zip
$@i) &&
113 ($source_url !~ m@
.*/server\
.ini
$@i)
116 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"TrendMicro",$mirror);
119 # -----------------------------------------------------------
120 # Section: Symantec Downloads
121 # -----------------------------------------------------------
123 if ($source_url =~ m@
^[h
|f
]tt?p
://[^/]*\.symantec(liveupdate)?\.com/.*\
.(exe
|zip
|vdb
|xdb
)$@i)
125 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Symantec",$unique);
128 # -----------------------------------------------------------
129 # Section: Apple Downloads
130 # -----------------------------------------------------------
133 (($source_url =~ m@
^http
://swcdn\
.apple\
.com
/content
/downloads
/.*\
.(tar
)$@i) ||
134 ($source_url =~ m@
^http
://appldnld\
.apple\
.com\
.edgesuite\
.net
/.*\
.(exe
|dmg
)$@i) ||
135 ($source_url =~ m@
^http
://.*\
.g
.akamai
.net
/.*/3093/1/.*\
.(tar
|pkg
|dmg
|exe
)$@i))
138 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Apple",$unique);
141 # -----------------------------------------------------------
142 # Section: Avast Downloads
143 # -----------------------------------------------------------
145 if ($source_url =~ m@
^http
://download
[\d
]+\
.avast\
.com
/.*\
.(exe
|vpu
)$@i)
147 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Avast",$mirror);
150 # -----------------------------------------------------------
152 # -----------------------------------------------------------
153 # Section: Avira Downloads
154 # -----------------------------------------------------------
156 if ($source_url =~ m@
^http
://dl[0-9]\
.avgate\
.net
/.*\
.(htm
|html
|gz
)$@i)
158 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Avira",$mirror);
161 # -----------------------------------------------------------
162 # Section: IPFire Downloads
163 # -----------------------------------------------------------
165 if ($source_url =~ m@
^[f
|h
]t?tp
://.*\
.(ipfire
)$@i)
167 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"IPFire",$mirror);
172 # -----------------------------------------------------------
173 # Section: AVG Downloads
174 # -----------------------------------------------------------
176 if ($source_url =~ m@
^http
://[^/]*\.(grisoft|avg)\.com/.*\
.(bin
)$@i)
178 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"AVG",$mirror);
181 $request="$xlrator_url $hostaddr $username $method\n";
186 # -------------------------------------------------------------------
190 my $filename = $_[0];
196 open(FILE
, $filename) or die "Unable to read file $filename";
200 ($var, $val) = split /=/, $_, 2;
206 # Untaint variables read from hash
207 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
208 $val =~ /([\w\W]*)/; $val = $1;
209 $hash->{$var} = $val;
216 # -------------------------------------------------------------------
222 open(LOGFILE
,">>$logfile");
223 print LOGFILE
time." $_[0] $_[1] $_[2] $_[3] $_[4]\n";
228 # -------------------------------------------------------------------
234 open(LOGFILE
,">>/var/log/updatexlrator/debug.log");
235 my @now = localtime(time);
236 printf LOGFILE
"%04d-%02d-%02d %02d:%02d:%02d [%d] [%s] %s\n",$now[5]+1900,$now[4]+1,$now[3],$now[2],$now[1],$now[0],$$,"updxlrator",$_[0];
241 # -------------------------------------------------------------------
245 open (FILE
,">>$_[0]");
246 print FILE
"$_[1]\n";
250 # -------------------------------------------------------------------
254 open(DF
,"/bin/df --block-size=1 $_[0]|");
259 my $dfstr = join(' ',@dfdata);
260 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
261 if ($free =~ m/^(\d+)$/)
267 # -------------------------------------------------------------------
271 open(DF
,"/bin/df $_[0]|");
276 my $dfstr = join(' ',@dfdata);
277 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
278 if ($percent =~ m/^(\d+)%$/)
285 # -------------------------------------------------------------------
289 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
294 # -------------------------------------------------------------------
298 my $updsource="UPDCACHE";
307 my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
312 $sourceurl =~ s@\
%2f@
/@ig;
313 $updfile = substr($sourceurl,rindex($sourceurl,"/")+1);
314 $updfile =~ s@\
%20@
@ig;
318 $uuid = `echo $updfile | md5sum`;
320 $uuid = `echo $sourceurl | md5sum`;
323 $uuid =~ s/[^0-9a-f]//g;
324 $uuid =~ s/([a-f\d]{8})([a-f\d]{4})([a-f\d]{4})([a-f\d]{4})([a-f\d]{12})/$1-$2-$3-$4-$5/;
327 $vendorid =~ tr/A-Z/a-z/;
329 &debuglog
("Processing URL $sourceurl");
330 &debuglog
("Vendor ID is $vendorid");
331 &debuglog
("UUID is $uuid");
333 if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
335 $login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
336 if ($proxysettings{'UPSTREAM_PASSWORD'})
338 $login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
342 if ($proxysettings{'UPSTREAM_PROXY'}) { &debuglog
("Using upstream proxy $proxysettings{'UPSTREAM_PROXY'}"); }
344 $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
345 @http_header = `$wget $login --user-agent="$useragent" --spider -S $sourceurl 2>&1`;
346 $ENV{'http_proxy'} = '';
348 foreach (@http_header)
351 if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
352 if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP
::Date
::str2time
($remote_mtime) }
356 (-e
"$updcachedir/$vendorid/$uuid/$updfile") &&
357 ($remote_size == (-s
"$updcachedir/$vendorid/$uuid/$updfile")) &&
358 ($remote_mtime == &getmtime
("$updcachedir/$vendorid/$uuid/$updfile"))
361 &debuglog
("File exists in cache and is up to date");
362 &debuglog
("Retrieving file from cache ($updsource)");
363 &setcachestatus
("$updcachedir/$vendorid/$uuid/access.log",time);
364 system("$apphome/bin/setperms $vendorid/$uuid/access.log");
365 $cacheurl="http://$netsettings{'GREEN_ADDRESS'}:$http_port/updatecache/$vendorid/$uuid/$updfile";
369 if (-e
"$updcachedir/$vendorid/$uuid/$updfile")
371 &debuglog
("Local filesize: " . (-s
"$updcachedir/$vendorid/$uuid/$updfile"));
372 &debuglog
("Local timestamp: " . &getmtime
("$updcachedir/$vendorid/$uuid/$updfile"));
373 } else { &debuglog
("File not found in cache"); }
374 $updsource="DLSOURCE";
375 &debuglog
("Remote filesize: $remote_size");
376 &debuglog
("Remote timestamp: $remote_mtime");
377 &debuglog
("Free disk space: " . &diskfree
($updcachedir));
378 &debuglog
("Disk usage: " . &diskusage
($updcachedir) . "% (max. $maxusage%)");
379 if (-e
"$updcachedir/download/$vendorid/$updfile") { &debuglog
("File download/$vendorid/$updfile exists"); }
380 &debuglog
("Retrieving file from source ($updsource)");
381 if ((!$passive_mode) && (&diskusage
($updcachedir) <= $maxusage) && ($remote_size <= &diskfree
($updcachedir)) && (!-e
"$updcachedir/download/$vendorid/$updfile"))
383 &debuglog
("Running command $nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
384 system("$nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
386 $cacheurl=$sourceurl;
389 &writelog
($_[1],$_[2],$_[3],$updsource,$sourceurl);
394 # -------------------------------------------------------------------