]>
git.ipfire.org Git - ipfire-2.x.git/blob - config/urlfilter/autoupdate.pl
4 # $Id: autoupdate.pl,v 1.0 2005/06/15 00:00:00 marco Exp $
10 my $swroot = "/var/ipfire";
11 my $target = "$swroot/urlfilter/download";
12 my $dbdir = "$swroot/urlfilter/blacklists";
14 my $sourceurlfile = "$swroot/urlfilter/autoupdate/autoupdate.urls";
15 my $updconffile = "$swroot/urlfilter/autoupdate/autoupdate.conf";
16 my $updflagfile = "$swroot/urlfilter/blacklists/.autoupdate.last";
31 if (-e
"$sourceurlfile")
33 open(FILE
, $sourceurlfile);
34 @source_urllist = <FILE
>;
38 if (-e
"$updconffile") { &readhash
("$updconffile", \
%updatesettings); }
40 if (@ARGV[0] =~ m@
^(f
|h
)tt?ps?
://@
) { $updatesettings{'UPDATE_SOURCE'} = @ARGV[0]; }
42 if ($updatesettings{'UPDATE_SOURCE'} eq 'custom')
44 $blacklist_url=$updatesettings{'CUSTOM_UPDATE_URL'};
46 $blacklist_url=$updatesettings{'UPDATE_SOURCE'};
47 foreach (@source_urllist)
50 $source_name = substr($_,0,rindex($_,","));
51 $source_url = substr($_,index($_,",")+1);
52 if ($blacklist_url eq $source_url) { $blacklist_src=$source_name; }
56 if ($blacklist_src eq '') { $blacklist_src="custom source URL"; }
58 $blacklist_url =~ s/\&/\\\&/;
60 $blacklist=substr($blacklist_url,rindex($blacklist_url,"/")+1);
61 if (($blacklist =~ /\?/) || (!($blacklist =~ /\.t(ar\.)?gz$/))) { $blacklist = 'blacklist.tar.gz'; }
62 $blacklist=$target.'/'.$blacklist;
64 unless ($blacklist_url eq '')
67 if (-d
$target) { system("rm -rf $target"); }
68 system("mkdir $target");
70 system("/usr/bin/wget -o $target/wget.log -O $blacklist $blacklist_url");
74 system("/bin/tar --no-same-owner -xzf $blacklist -C $target");
75 if (-d
"$target/blacklists")
77 open(FILE
, ">$target/update.conf");
79 print FILE
"logdir $target\n";
80 print FILE
"dbhome $target/blacklists\n\n";
82 foreach (<$target/blacklists/*>)
84 if ((-d
$_) && ((-s
"$_/domains") || (-s
"$_/urls")))
86 $category=substr($_,rindex($_,"/")+1);
87 print FILE
"dest $category {\n";
88 if (-s
"$_/domains") { print FILE
" domainlist $category/domains\n"; }
89 if (-s
"$_/urls") { print FILE
" urllist $category/urls\n"; }
94 print FILE
" default {\n";
95 print FILE
" pass none\n";
100 system("/usr/sbin/squidGuard -d -c $target/update.conf -C all");
102 system("cp -r $target/blacklists/* $dbdir");
104 system("chown -R nobody.nobody $dbdir");
106 foreach $category (<$dbdir/*>)
110 system("chmod 755 $category &> /dev/null");
111 foreach $blacklist (<$category/*>)
113 if (-f
$blacklist){ system("chmod 644 $blacklist &> /dev/null"); }
114 if (-d
$blacklist){ system("chmod 755 $blacklist &> /dev/null"); }
116 system("chmod 666 $category/*.db &> /dev/null");
120 system("touch $updflagfile");
121 system("chown nobody.nobody $updflagfile");
123 system("/usr/local/bin/restartsquid");
125 system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\"");
130 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Not a valid URL filter blacklist\"");
133 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: Unable to retrieve blacklist from $blacklist_src\"");
137 system("logger -t installpackage[urlfilter] \"URL filter blacklist - ERROR: No update source defined\"");
140 if ((-d
$target) && ($make_clean)) { system("rm -rf $target"); }
144 # -------------------------------------------------------------------
148 my $filename = $_[0];
154 open(FILE
, $filename) or die "Unable to read file $filename";
158 ($var, $val) = split /=/, $_, 2;
164 # Untaint variables read from hash
165 $var =~ /([A-Za-z0-9_-]*)/; $var = $1;
166 $val =~ /([\w\W]*)/; $val = $1;
167 $hash->{$var} = $val;
174 # -------------------------------------------------------------------