[27] | 1 | #!/usr/bin/perl
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 | use warnings;
|
---|
| 5 | use DBI;
|
---|
| 6 |
|
---|
| 7 | use URIdb;
|
---|
| 8 |
|
---|
| 9 | my $uridb = new URIdb;
|
---|
| 10 |
|
---|
| 11 | # default DB info - all other settings should be loaded from the DB.
|
---|
| 12 | my $dbhost = "localhost";
|
---|
| 13 | my $dbname = "uridb";
|
---|
| 14 | my $dbuser = "uridb";
|
---|
| 15 | my $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.
|
---|
| 21 | if (-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 |
|
---|
| 27 | my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
|
---|
| 28 |
|
---|
| 29 | my $datesth = $dbh->prepare("UPDATE urilist SET added=? WHERE uri=?");
|
---|
| 30 |
|
---|
| 31 | my %config;
|
---|
| 32 | my $sth = $dbh->prepare("SELECT key,value FROM misc");
|
---|
| 33 | $sth->execute;
|
---|
| 34 | while (my ($key,$value) = $sth->fetchrow_array) {
|
---|
| 35 | $config{$key} = $value;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | my @months = ('null','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
|
---|
| 39 |
|
---|
| 40 | my $uridate = 'Tue Nov 9 16:26:29 EST 2010';
|
---|
| 41 | my $uricomment;
|
---|
| 42 |
|
---|
| 43 | #my $count = 0;
|
---|
| 44 | while (<>) {
|
---|
| 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 | }
|
---|