]>
git.ipfire.org Git - people/stevee/ipfire-2.x.git/blob - config/urlfilter/autoupdate.pl
3 # This code is distributed under the terms of the GPL
5 # (c) 2004-2007 marco.s - http://www.urlfilter.net
7 # $Id: autoupdate.pl,v 1.1 2007/03/14 00:00:00 marco.s Exp $
11 require "/var/ipfire/general-functions.pl";
15 my $swroot = "/var/ipfire";
16 my $target = "$swroot/urlfilter/download";
17 my $tempdb = "$target/blacklists";
18 my $dbdir = "$swroot/urlfilter/blacklists";
20 my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
21 my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
22 my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
38 if (-e
"$sourceurlfile")
40 open(FILE
, $sourceurlfile);
41 @source_urllist = <FILE
>;
45 if (-e
"$updconffile") { &readhash
("$updconffile", \
%updatesettings); }
47 if (@ARGV[0] =~ m@
^(f
|h
)tt?ps?
://@
) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
49 if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
51 $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
53 $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
54 foreach (@source_urllist)
57 $source_name = substr($_,0,rindex($_,","));
58 $source_url = substr($_,index($_,",")+1);
59 if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
63 if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
65 $blacklist_url =~ s/\&/\\\&/;
67 $blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
68 if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
69 $blacklist=$target.'/'.$blacklist;
71 unless ($blacklist_url eq '')
74 if (-d
$target) { system("rm -rf $target"); }
75 system("mkdir $target");
77 &Network
::setup_upstream_proxy
();
78 system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
82 system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
83 if (-d
"$target/BL") { system ("mv $target/BL $target/blacklists"); }
87 &getblockcategory
($tempdb);
88 foreach (@categories) { $_ = substr($_,length($tempdb)+1); }
90 open(FILE
, ">$target/update.conf");
92 print FILE
"logdir $target\n";
93 print FILE
"dbhome $tempdb\n\n";
95 foreach $category (@categories) {
96 $blacklist = $category;
97 $category =~ s/\//_
/g
;
98 print FILE
"dest $category {\n";
99 if (-s
"$tempdb/$blacklist/domains") {
100 print FILE
" domainlist $blacklist\/domains\n";
102 if (-s
"$tempdb/$blacklist/urls") {
103 print FILE
" urllist $blacklist\/urls\n";
106 $category = $blacklist;
109 print FILE
"acl {\n";
110 print FILE
" default {\n";
111 print FILE
" pass none\n";
116 system("/usr/bin/squidGuard -d -c $target/update.conf -C all");
118 system("cp -r $target/blacklists/* $dbdir");
120 system("chown -R nobody.nobody $dbdir");
122 &setpermissions
($dbdir);
124 system("touch $updflagfile");
125 system("chown nobody.nobody $updflagfile");
127 system("/etc/init.d/squid restart");
129 system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
134 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
137 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
141 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
144 if ((-d
$target) && ($make_clean)) { system("rm -rf $target"); }
148 # -------------------------------------------------------------------
152 my $filename = $_[0];
158 open(FILE
, $filename) or die "Unable to read file $filename";
162 ($var, $val) = split /=/, $_, 2;
168 # Untaint variables read from hash
169 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
170 $val =~ /([\w\W]*)/; $val = $1;
171 $hash->{$var} = $val;
178 # -------------------------------------------------------------------
182 foreach $category (<$_[0]/*>)
186 if ((-s
"$category/domains") || (-s
"$category/urls"))
188 unless ($category =~ /\bcustom\b/) { push(@categories,$category); }
190 &getblockcategory
($category);
195 # -------------------------------------------------------------------
201 foreach $category (<$bldir/*>)
204 system("chmod 755 $category &> /dev/null");
205 foreach $blacklist (<$category/*>)
207 if (-f
$blacklist) { system("chmod 644 $blacklist &> /dev/null"); }
208 if (-d
$blacklist) { system("chmod 755 $blacklist &> /dev/null"); }
210 system("chmod 666 $category/*.db &> /dev/null");
211 &setpermissions
($category);
216 # -------------------------------------------------------------------