]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/updxlrator/updxlrator
3 # This code is distributed under the terms of the GPL
5 # (c) 2006-2009 marco.s - http://update-accelerator.advproxy.net
7 # Portions (c) 2008 by dotzball - http://www.blockouttraffic.de
9 # $Id: updxlrator,v 2.1 2009/01/10 00:00:00 marco.s Exp $
13 # 2012-10-26: nightshift - move curly bracket to capture AVG download source.
14 # - Adding BIG HINT for new update source#
22 my $swroot="/var/ipfire";
23 my $updcachedir="/var/updatecache";
24 my $apphome="/var/ipfire/updatexlrator";
25 my $logfile="/var/log/updatexlrator/cache.log";
26 my $wget="/usr/bin/wget";
27 my $debug=(-e
"$apphome/debug");
31 my %xlratorsettings=();
46 readhash
("${swroot}/ethernet/settings", \
%netsettings);
48 if (-e
"$swroot/updatexlrator/settings")
50 &readhash
("$swroot/updatexlrator/settings", \
%xlratorsettings);
51 if ($xlratorsettings{'ENABLE_LOG'} eq 'on') { $logging=1; };
52 if ($xlratorsettings{'PASSIVE_MODE'} eq 'on') { $passive_mode=1; };
53 $maxusage=$xlratorsettings{'MAX_DISK_USAGE'};
54 if ($xlratorsettings{'LOW_DOWNLOAD_PRIORITY'} eq 'on') { $nice='/bin/nice --adjustment=15 '; };
56 if (!$maxusage) { $maxusage=75; };
58 # dotzball: check for dead downloads
59 system("$apphome/bin/checkdeaddl &");
65 @tmp=split(/ /,$request);
68 $source_url = $tmp[0];
69 $hostaddr = $tmp[1]; while ($hostaddr =~ /.*\/$/) { chop $hostaddr; }
70 $username = $tmp[2]; if ($username eq '') { $username='-'; };
73 $xlrator_url = $source_url;
75 if (($method eq 'GET') || ($method eq 'HEAD'))
78 # -----------------------------------------------------------
79 # Section: Windows Update / Windows Downloads
80 # -----------------------------------------------------------
83 (($source_url =~ m@
^http
://[^/]*\.microsoft\.com/.*\
.(exe
|psf
|msi
|msp
|msu
|cab
)$@i) ||
84 ($source_url =~ m@
^http
://[^/]*\.windowsupdate\.com/.*\
.(exe
|psf
|msi
|msp
|msu
|cab
)$@i))
85 && ($source_url !~ m@
^http
://[^/]*\.microsoft\.com/.*(/autoupd|selfupdate/).*\
.cab
@i)
86 && ($source_url !~ m@\
&@
)
89 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Microsoft",$unique);
92 # -----------------------------------------------------------
93 # Section: Adobe Downloads
94 # -----------------------------------------------------------
98 ($source_url =~ m@
^http
://(ar
)?download\
.adobe\
.com
/.*\
.(exe
|msi
|bin
|dmg
|idx
|gz
)$@i) ||
99 ($source_url =~ m@
^http
://swupdl\
.adobe\
.com
/updates
/.*\
.(exe
|msi
|bin
|dmg
|idx
|gz
|[a
-z
][a
-z
]_
[A
-Z
][A
-Z
])$@i) ||
100 ($source_url =~ m@
^http
://swupmf\
.adobe\
.com
/manifest
/.*\
.upd
$@i)
103 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Adobe",$unique);
106 # -----------------------------------------------------------
107 # Section: Linux Downloads
108 # -----------------------------------------------------------
111 ($source_url =~ m@
^[h
|f
]t?tp
://[^?
]+\
.(deb
|rpm
)$@i) ||
112 ($source_url =~ m@
^[h
|f
]t?tp
://[^?
]+/distfiles/[^?
]+\
.(tar\
.gz
|tar\
.bz2
|tgz
|zip
|patch\
.bz2
|gz
|docx
|patch
|pdf
|exe
)$@i)
115 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Linux",$mirror);
118 # -----------------------------------------------------------
119 # Section: Trend Micro Downloads
120 # -----------------------------------------------------------
123 ($source_url =~ m@
^http
://[^/]*\.trendmicro\.com/activeupdate
/.*@i) &&
124 ($source_url !~ m@
.*/tmnotify\
.dat
$@i) &&
125 ($source_url !~ m@
.*/ini_xml\
.zip
$@i) &&
126 ($source_url !~ m@
.*/server\
.ini
$@i)
129 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"TrendMicro",$mirror);
132 # -----------------------------------------------------------
133 # Section: Symantec Downloads
134 # -----------------------------------------------------------
136 if ($source_url =~ m@
^[h
|f
]tt?p
://[^/]*\.symantec(liveupdate)?\.com/.*\
.(exe
|zip
|vdb
|xdb
)$@i)
138 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Symantec",$unique);
141 # -----------------------------------------------------------
142 # Section: Apple Downloads
143 # -----------------------------------------------------------
146 (($source_url =~ m@
^http
://swcdn\
.apple\
.com
/content
/downloads
/.*\
.(tar
|pkg
)$@i) ||
147 ($source_url =~ m@
^http
://appldnld\
.apple\
.com\
.edgesuite\
.net
/.*\
.(exe
|dmg
)$@i) ||
148 ($source_url =~ m@
^http
://.*\
.g
.akamai
.net
/.*/3093/1/.*\
.(tar
|pkg
|dmg
|exe
)$@i))
151 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Apple",$unique);
154 # -----------------------------------------------------------
155 # Section: Avast Downloads
156 # -----------------------------------------------------------
158 if ($source_url =~ m@
^http
://(ion
|download
)[\d
]+\
.avast\
.com
/.*\
.(exe
|vpu
|vpx
)$@i)
160 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Avast",$mirror);
163 # -----------------------------------------------------------
164 # Section: Mozilla Downloads
165 # -----------------------------------------------------------
167 if ($source_url=~ m@
^http
://.*\
.mozilla\
.net
/.*\
.((complete
|partial
)\
.mar
|exe
)$@i)
169 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Mozilla",$unique);
172 # -----------------------------------------------------------
174 # -----------------------------------------------------------
176 if ($source_url =~ m@
^http
://update\
.nai\
.com
/.*\
.(mcs
|z
|gem
|dat
|zip
)$@i)
178 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"mcafee",$mirror);
181 # -----------------------------------------------------------
182 # Section: Avira Downloads
183 # -----------------------------------------------------------
186 ($source_url =~ m@
^http
://dl[0-9]\
.avgate\
.net
/.*\
.(htm
|html
|gz
)$@i) ||
187 ($source_url =~ m@
^http
://80.190.130.19[4-5]/update/.*\
.(htm
|html
|gz
)$@i) ||
188 ($source_url =~ m@
^http
://62.146.64.14[6-7]/update/.*\
.(htm
|html
|gz
)$@i)
191 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"Avira",$mirror);
194 # -----------------------------------------------------------
195 # Section: IPFire Downloads
196 # -----------------------------------------------------------
198 if ($source_url =~ m@
^[f
|h
]t?tp
://.*\
.(ipfire
)$@i)
200 $xlrator_url = &check_cache
($source_url,$hostaddr,$username,"IPFire",$mirror);
203 # -----------------------------------------------------------
204 # Section: AVG Downloads
205 # -----------------------------------------------------------
207 # if ($source_url =~ m@^http://[^/]*\.(grisoft|avg)\.com/.*\.(bin)$@i)
209 # $xlrator_url = &check_cache($source_url,$hostaddr,$username,"AVG",$mirror);
212 # ----------- ADD NEW SOURCES BEFORE THIS LINE !!! ------------------
215 $request="$xlrator_url $hostaddr $username $method\n";
220 # -------------------------------------------------------------------
224 my $filename = $_[0];
230 open(FILE
, $filename) or die "Unable to read file $filename";
234 ($var, $val) = split /=/, $_, 2;
240 # Untaint variables read from hash
241 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
242 $val =~ /([\w\W]*)/; $val = $1;
243 $hash->{$var} = $val;
250 # -------------------------------------------------------------------
256 open(LOGFILE
,">>$logfile");
257 print LOGFILE
time." $_[0] $_[1] $_[2] $_[3] $_[4]\n";
262 # -------------------------------------------------------------------
268 open(LOGFILE
,">>/var/log/updatexlrator/debug.log");
269 my @now = localtime(time);
270 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];
275 # -------------------------------------------------------------------
279 open (FILE
,">>$_[0]");
280 print FILE
"$_[1]\n";
284 # -------------------------------------------------------------------
288 open(DF
,"/bin/df --block-size=1 $_[0]|");
293 my $dfstr = join(' ',@dfdata);
294 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
295 if ($free =~ m/^(\d+)$/)
301 # -------------------------------------------------------------------
305 open(DF
,"/bin/df $_[0]|");
310 my $dfstr = join(' ',@dfdata);
311 my ($device,$size,$used,$free,$percent,$mount) = split(' ',$dfstr);
312 if ($percent =~ m/^(\d+)%$/)
319 # -------------------------------------------------------------------
323 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat($_[0]);
328 # -------------------------------------------------------------------
332 my $updsource="UPDCACHE";
341 my $useragent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
346 $sourceurl =~ s@\
%2f@
/@ig;
347 $updfile = substr($sourceurl,rindex($sourceurl,"/")+1);
348 $updfile =~ s@\
%20@
@ig;
352 $uuid = `echo $updfile | md5sum`;
354 $uuid = `echo $sourceurl | md5sum`;
357 $uuid =~ s/[^0-9a-f]//g;
358 $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/;
361 $vendorid =~ tr/A-Z/a-z/;
363 &debuglog
("Processing URL $sourceurl");
364 &debuglog
("Vendor ID is $vendorid");
365 &debuglog
("UUID is $uuid");
367 if (($proxysettings{'UPSTREAM_PROXY'}) && ($proxysettings{'UPSTREAM_USER'}))
369 $login = "--proxy-user=\"$proxysettings{'UPSTREAM_USER'}\"";
370 if ($proxysettings{'UPSTREAM_PASSWORD'})
372 $login .= " --proxy-password=\"$proxysettings{'UPSTREAM_PASSWORD'}\"";
376 if ($proxysettings{'UPSTREAM_PROXY'}) { &debuglog
("Using upstream proxy $proxysettings{'UPSTREAM_PROXY'}"); }
378 $ENV{'http_proxy'} = $proxysettings{'UPSTREAM_PROXY'};
379 @http_header = `$wget $login --user-agent="$useragent" --spider -S $sourceurl 2>&1`;
380 $ENV{'http_proxy'} = '';
382 foreach (@http_header)
385 if (/^\s*Content-Length:\s/) { $remote_size = $_; $remote_size =~ s/[^0-9]//g; }
386 if (/^\s*Last-Modified:\s/) { $remote_mtime = $_; $remote_mtime =~ s/^\s*Last-Modified:\s//; $remote_mtime = HTTP
::Date
::str2time
($remote_mtime) }
390 (-e
"$updcachedir/$vendorid/$uuid/$updfile") &&
391 ($remote_size == (-s
"$updcachedir/$vendorid/$uuid/$updfile")) &&
392 ($remote_mtime == &getmtime
("$updcachedir/$vendorid/$uuid/$updfile"))
395 &debuglog
("File exists in cache and is up to date");
396 &debuglog
("Retrieving file from cache ($updsource)");
397 &setcachestatus
("$updcachedir/$vendorid/$uuid/access.log",time);
398 $cacheurl="http://$netsettings{'GREEN_ADDRESS'}:$http_port/updatecache/$vendorid/$uuid/$updfile";
402 if (-e
"$updcachedir/$vendorid/$uuid/$updfile")
404 &debuglog
("Local filesize: " . (-s
"$updcachedir/$vendorid/$uuid/$updfile"));
405 &debuglog
("Local timestamp: " . &getmtime
("$updcachedir/$vendorid/$uuid/$updfile"));
406 } else { &debuglog
("File not found in cache"); }
407 $updsource="DLSOURCE";
408 &debuglog
("Remote filesize: $remote_size");
409 &debuglog
("Remote timestamp: $remote_mtime");
410 &debuglog
("Free disk space: " . &diskfree
($updcachedir));
411 &debuglog
("Disk usage: " . &diskusage
($updcachedir) . "% (max. $maxusage%)");
412 if (-e
"$updcachedir/download/$vendorid/$updfile") { &debuglog
("File download/$vendorid/$updfile exists"); }
413 &debuglog
("Retrieving file from source ($updsource)");
414 if ((!$passive_mode) && (&diskusage
($updcachedir) <= $maxusage) && ($remote_size <= &diskfree
($updcachedir)) && (!-e
"$updcachedir/download/$vendorid/$updfile"))
416 &debuglog
("Running command $nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
417 system("$nice$apphome/bin/download $vendorid $sourceurl $cfmirror &");
419 $cacheurl=$sourceurl;
422 &writelog
($_[1],$_[2],$_[3],$updsource,$sourceurl);
427 # -------------------------------------------------------------------