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

Last change on this file since 86 was 86, checked in by Kris Deugau, 5 days ago

/trunk/uribl

Move the %config blurb inside the module so it's not splattered across all
the scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.3 KB
Line 
1#!/usr/bin/perl
2# Import a tinydns-formatted URI blacklist
3##
4# $Id: import-cur.pl 86 2025-09-11 21:57:24Z 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 @months = ('null','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
41
42my $uridate = 'Tue Nov 9 16:26:29 EST 2010';
43my $uricomment;
44
45#my $count = 0;
46while (<>) {
47 next if /^\s*$/;
48 if (/^#/) {
49 $uricomment = '';
50 if (/^# (\w\w\w \w\w\w ?\d\d? ?\d\d?:\d\d:\d\d \w\w\w \d{4})\s*$/) {
51 $uridate = $1;
52 print "setting date on following URIs to $uridate\n";
53 } elsif (m|^# (\d\d\d\d)/(\d\d)/(\d\d?) ?(\d\d:\d\d:?\d?\d?)?$|) {
54 $uridate = "$months[$2] $3 $1";
55 $uridate .= ($4 ? " $4" : " 10:30:42");
56 print "setting date on following URIs to $uridate\n";
57 } else {
58 chomp;
59 s/^#\s+//;
60 $uricomment = $_;
61 print "setting comment on next URI to $uricomment\n";
62 }
63 next;
64 }
65 chomp;
66 s/^\+//;
67 my ($domain,$list,$rest) = split /:/;
68 ($list) = ($list =~ /\.(\d+)$/);
69 $domain =~ s/$config{blzone}$//;
70 if (!$uridb->exists($domain)) {
71 print "adding $domain, $list\n";
72 $uridb->report($domain, $list, $uricomment);
73 $datesth->execute($uridate, $domain) or die "bad date-foo: ".$dbh->errstr."\n";
74 $dbh->commit;
75 } else {
76 print "$domain exists, not adding\n";
77 }
78 $uricomment = '';
79# last if $count++ > 1000;
80}
Note: See TracBrowser for help on using the repository browser.