source: trunk/uribl/import-cur.pl@ 84

Last change on this file since 84 was 84, checked in by Kris Deugau, 4 days ago

/trunk/uribl

Update semistale import script's module usage to match the others

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.5 KB
Line 
1#!/usr/bin/perl
2# Import a tinydns-formatted URI blacklist
3##
4# $Id: import-cur.pl 84 2025-09-11 21:37:37Z kdeugau $
5# Copyright 2010,2025 Kris Deugau <kdeugau@deepnet.cx>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19##
20
21use strict;
22use warnings;
23use DBI;
24
25# push "the directory the script is in" into @INC
26use FindBin;
27use lib "$FindBin::RealBin/";
28
29use URIdb 2.0;
30
31die "Usage: import-cur.pl <list>\n"
32 if !$ARGV[0]
33
34my $cfgname = shift @ARGV;
35
36my $dbh = $uridb->connect(configfile => "/etc/uridb/$cfgname.conf");
37
38my $datesth = $dbh->prepare("UPDATE urilist SET added=? WHERE uri=?");
39
40my %config;
41my $sth = $dbh->prepare("SELECT key,value FROM misc");
42$sth->execute;
43while (my ($key,$value) = $sth->fetchrow_array) {
44 $config{$key} = $value;
45}
46$config{blzone} = 'uribl.company.com' if !$config{blzone};
47
48my @months = ('null','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
49
50my $uridate = 'Tue Nov 9 16:26:29 EST 2010';
51my $uricomment;
52
53#my $count = 0;
54while (<>) {
55 next if /^\s*$/;
56 if (/^#/) {
57 $uricomment = '';
58 if (/^# (\w\w\w \w\w\w ?\d\d? ?\d\d?:\d\d:\d\d \w\w\w \d{4})\s*$/) {
59 $uridate = $1;
60 print "setting date on following URIs to $uridate\n";
61 } elsif (m|^# (\d\d\d\d)/(\d\d)/(\d\d?) ?(\d\d:\d\d:?\d?\d?)?$|) {
62 $uridate = "$months[$2] $3 $1";
63 $uridate .= ($4 ? " $4" : " 10:30:42");
64 print "setting date on following URIs to $uridate\n";
65 } else {
66 chomp;
67 s/^#\s+//;
68 $uricomment = $_;
69 print "setting comment on next URI to $uricomment\n";
70 }
71 next;
72 }
73 chomp;
74 s/^\+//;
75 my ($domain,$list,$rest) = split /:/;
76 ($list) = ($list =~ /\.(\d+)$/);
77 $domain =~ s/$config{blzone}$//;
78 if (!$uridb->exists($domain)) {
79 print "adding $domain, $list\n";
80 $uridb->report($domain, $list, $uricomment);
81 $datesth->execute($uridate, $domain) or die "bad date-foo: ".$dbh->errstr."\n";
82 $dbh->commit;
83 } else {
84 print "$domain exists, not adding\n";
85 }
86 $uricomment = '';
87# last if $count++ > 1000;
88}
Note: See TracBrowser for help on using the repository browser.