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

Last change on this file since 27 was 27, checked in by Kris Deugau, 14 years ago

/trunk/uribl

Add URI blacklist database interface code

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.2 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use DBI;
6
7use URIdb;
8
9my $uridb = new URIdb;
10
11# default DB info - all other settings should be loaded from the DB.
12my $dbhost = "localhost";
13my $dbname = "uridb";
14my $dbuser = "uridb";
15my $dbpass = "spambgone";
16
17# Load a config ref containing DB host, name, user, and pass info based on
18# from the server name + full script web path. This allows us to host
19# multiple instances without having to duplicate the code.
20# This file is a Perl fragment to be processed inline.
21if (-e "/etc/uridb/uridb.conf") {
22 my $cfg = `cat /etc/uridb/uridb.conf`;
23 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
24 eval $cfg;
25}
26
27my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
28
29my $datesth = $dbh->prepare("UPDATE urilist SET added=? WHERE uri=?");
30
31my %config;
32my $sth = $dbh->prepare("SELECT key,value FROM misc");
33$sth->execute;
34while (my ($key,$value) = $sth->fetchrow_array) {
35 $config{$key} = $value;
36}
37
38my @months = ('null','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
39
40my $uridate = 'Tue Nov 9 16:26:29 EST 2010';
41my $uricomment;
42
43#my $count = 0;
44while (<>) {
45 next if /^\s*$/;
46 if (/^#/) {
47 $uricomment = '';
48 if (/^# (\w\w\w \w\w\w ?\d\d? ?\d\d?:\d\d:\d\d \w\w\w \d{4})\s*$/) {
49 $uridate = $1;
50 print "setting date on following URIs to $uridate\n";
51 } elsif (m|^# (\d\d\d\d)/(\d\d)/(\d\d?) ?(\d\d:\d\d:?\d?\d?)?$|) {
52 $uridate = "$months[$2] $3 $1";
53 $uridate .= ($4 ? " $4" : " 10:30:42");
54 print "setting date on following URIs to $uridate\n";
55 } else {
56 chomp;
57 s/^#\s+//;
58 $uricomment = $_;
59 print "setting comment on next URI to $uricomment\n";
60 }
61 next;
62 }
63 chomp;
64 s/^\+//;
65 my ($domain,$list,$rest) = split /:/;
66 ($list) = ($list =~ /\.(\d+)$/);
67 $domain =~ s/\.uribl\.company\.com$//;
68 if (!$uridb->exists($domain)) {
69 print "adding $domain, $list\n";
70 $uridb->report($domain, $list, $uricomment);
71 $datesth->execute($uridate, $domain) or die "bad date-foo: ".$dbh->errstr."\n";
72 $dbh->commit;
73 } else {
74 print "$domain exists, not adding\n";
75 }
76 $uricomment = '';
77# last if $count++ > 1000;
78}
Note: See TracBrowser for help on using the repository browser.