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 |
|
---|
21 | use strict;
|
---|
22 | use warnings;
|
---|
23 | use DBI;
|
---|
24 |
|
---|
25 | # push "the directory the script is in" into @INC
|
---|
26 | use FindBin;
|
---|
27 | use lib "$FindBin::RealBin/";
|
---|
28 |
|
---|
29 | use URIdb 2.0;
|
---|
30 |
|
---|
31 | die "Usage: import-cur.pl <list>\n"
|
---|
32 | if !$ARGV[0]
|
---|
33 |
|
---|
34 | my $cfgname = shift @ARGV;
|
---|
35 |
|
---|
36 | my $dbh = $uridb->connect(configfile => "/etc/uridb/$cfgname.conf");
|
---|
37 |
|
---|
38 | my $datesth = $dbh->prepare("UPDATE urilist SET added=? WHERE uri=?");
|
---|
39 |
|
---|
40 | my %config;
|
---|
41 | my $sth = $dbh->prepare("SELECT key,value FROM misc");
|
---|
42 | $sth->execute;
|
---|
43 | while (my ($key,$value) = $sth->fetchrow_array) {
|
---|
44 | $config{$key} = $value;
|
---|
45 | }
|
---|
46 | $config{blzone} = 'uribl.company.com' if !$config{blzone};
|
---|
47 |
|
---|
48 | my @months = ('null','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
|
---|
49 |
|
---|
50 | my $uridate = 'Tue Nov 9 16:26:29 EST 2010';
|
---|
51 | my $uricomment;
|
---|
52 |
|
---|
53 | #my $count = 0;
|
---|
54 | while (<>) {
|
---|
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 | }
|
---|