]>
git.ipfire.org Git - 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 $
13 my $swroot = "/var/ipfire";
14 my $target = "$swroot/urlfilter/download";
15 my $tempdb = "$target/blacklists";
16 my $dbdir = "$swroot/urlfilter/blacklists";
18 my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
19 my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
20 my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
36 if (-e
"$sourceurlfile")
38 open(FILE
, $sourceurlfile);
39 @source_urllist = <FILE
>;
43 if (-e
"$updconffile") { &readhash
("$updconffile", \
%updatesettings); }
45 if (@ARGV[0] =~ m@
^(f
|h
)tt?ps?
://@
) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
47 if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
49 $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
51 $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
52 foreach (@source_urllist)
55 $source_name = substr($_,0,rindex($_,","));
56 $source_url = substr($_,index($_,",")+1);
57 if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
61 if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
63 $blacklist_url =~ s/\&/\\\&/;
65 $blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
66 if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
67 $blacklist=$target.'/'.$blacklist;
69 unless ($blacklist_url eq '')
72 if (-d
$target) { system("rm -rf $target"); }
73 system("mkdir $target");
75 system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
79 system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
80 if (-d
"$target/BL") { system ("mv $target/BL $target/blacklists"); }
84 &getblockcategory
($tempdb);
85 foreach (@categories) { $_ = substr($_,length($tempdb)+1); }
87 open(FILE
, ">$target/update.conf");
89 print FILE
"logdir $target\n";
90 print FILE
"dbhome $tempdb\n\n";
92 foreach $category (@categories) {
93 $blacklist = $category;
94 $category =~ s/\//_
/g
;
95 print FILE
"dest $category {\n";
96 if (-s
"$tempdb/$blacklist/domains") {
97 print FILE
" domainlist $blacklist\/domains\n";
99 if (-s
"$tempdb/$blacklist/urls") {
100 print FILE
" urllist $blacklist\/urls\n";
103 $category = $blacklist;
106 print FILE
"acl {\n";
107 print FILE
" default {\n";
108 print FILE
" pass none\n";
113 system("/usr/bin/squidGuard -d -c $target/update.conf -C all");
115 system("cp -r $target/blacklists/* $dbdir");
117 system("chown -R nobody.nobody $dbdir");
119 &setpermissions
($dbdir);
121 system("touch $updflagfile");
122 system("chown nobody.nobody $updflagfile");
124 system("/etc/init.d/squid restart");
126 system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
131 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
134 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
138 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
141 if ((-d
$target) && ($make_clean)) { system("rm -rf $target"); }
145 # -------------------------------------------------------------------
149 my $filename = $_[0];
155 open(FILE
, $filename) or die "Unable to read file $filename";
159 ($var, $val) = split /=/, $_, 2;
165 # Untaint variables read from hash
166 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
167 $val =~ /([\w\W]*)/; $val = $1;
168 $hash->{$var} = $val;
175 # -------------------------------------------------------------------
179 foreach $category (<$_[0]/*>)
183 if ((-s
"$category/domains") || (-s
"$category/urls"))
185 unless ($category =~ /\bcustom\b/) { push(@categories,$category); }
187 &getblockcategory
($category);
192 # -------------------------------------------------------------------
198 foreach $category (<$bldir/*>)
201 system("chmod 755 $category &> /dev/null");
202 foreach $blacklist (<$category/*>)
204 if (-f
$blacklist) { system("chmod 644 $blacklist &> /dev/null"); }
205 if (-d
$blacklist) { system("chmod 755 $blacklist &> /dev/null"); }
207 system("chmod 666 $category/*.db &> /dev/null");
208 &setpermissions
($category);
213 # -------------------------------------------------------------------