1 | #!/usr/bin/perl -I/home/kdeugau/dnsbl/
|
---|
2 | # Delist a URI
|
---|
3 |
|
---|
4 | use strict;
|
---|
5 | use warnings;
|
---|
6 | use DBI;
|
---|
7 |
|
---|
8 | use URIdb;
|
---|
9 |
|
---|
10 | my $uridb = new URIdb;
|
---|
11 |
|
---|
12 | # default DB info - all other settings should be loaded from the DB.
|
---|
13 | my $dbhost = "localhost";
|
---|
14 | my $dbname = "dnsbl";
|
---|
15 | my $dbuser = "dnsbl";
|
---|
16 | my $dbpass = "spambgone";
|
---|
17 |
|
---|
18 | die "Usage: delist-uri <domain>\n"
|
---|
19 | if !$ARGV[0];
|
---|
20 |
|
---|
21 | # Load a config ref containing DB host, name, user, and pass info based on
|
---|
22 | # from the server name + full script web path. This allows us to host
|
---|
23 | # multiple instances without having to duplicate the code.
|
---|
24 | # This file is a Perl fragment to be processed inline.
|
---|
25 | if (-e "/etc/uridb/uridb.conf") {
|
---|
26 | my $cfg = `cat /etc/uridb/uridb.conf`;
|
---|
27 | ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
|
---|
28 | eval $cfg;
|
---|
29 | }
|
---|
30 |
|
---|
31 | my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
|
---|
32 |
|
---|
33 | my %config;
|
---|
34 | my $sth = $dbh->prepare("SELECT key,value FROM misc");
|
---|
35 | $sth->execute;
|
---|
36 | while (my ($key,$value) = $sth->fetchrow_array) {
|
---|
37 | $config{$key} = $value;
|
---|
38 | }
|
---|
39 |
|
---|
40 | my $removeme = $ARGV[0];
|
---|
41 |
|
---|
42 | $sth = $dbh->prepare("SELECT uri,list,count,added,comment FROM urilist WHERE uri=?");
|
---|
43 | $sth->execute($removeme);
|
---|
44 | my ($uri,$list,$count,$added,$comment) = $sth->fetchrow_array;
|
---|
45 |
|
---|
46 | die "URI $removeme not found. Exiting.\n" if !$uri;
|
---|
47 |
|
---|
48 | # need to do the next in a single transaction
|
---|
49 | local $dbh->{AutoCommit} = 0;
|
---|
50 | local $dbh->{RaiseError} = 1;
|
---|
51 | eval {
|
---|
52 | $sth = $dbh->prepare("INSERT INTO waslisted (uri,list,count,origadded,comment) VALUES (?,?,?,?,?)");
|
---|
53 | $sth->execute($uri,$list,$count,$added,$comment);
|
---|
54 | $sth = $dbh->prepare("DELETE FROM urilist WHERE uri=?");
|
---|
55 | $sth->execute($uri);
|
---|
56 | $dbh->commit;
|
---|
57 | };
|
---|
58 | if ($@) {
|
---|
59 | my $msg = $@;
|
---|
60 | eval { $dbh->rollback; };
|
---|
61 | print "Failed to move record from urilist to waslisted: $msg\n";
|
---|
62 | }
|
---|