source: trunk/uribl/delist-uri@ 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: 1.7 KB
Line 
1#!/usr/bin/perl -I/home/kdeugau/dnsbl/
2# Delist a URI
3
4use strict;
5use warnings;
6use DBI;
7
8use URIdb;
9
10my $uridb = new URIdb;
11
12# default DB info - all other settings should be loaded from the DB.
13my $dbhost = "localhost";
14my $dbname = "dnsbl";
15my $dbuser = "dnsbl";
16my $dbpass = "spambgone";
17
18die "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.
25if (-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
31my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);
32
33my %config;
34my $sth = $dbh->prepare("SELECT key,value FROM misc");
35$sth->execute;
36while (my ($key,$value) = $sth->fetchrow_array) {
37 $config{$key} = $value;
38}
39
40my $removeme = $ARGV[0];
41
42$sth = $dbh->prepare("SELECT uri,list,count,added,comment FROM urilist WHERE uri=?");
43$sth->execute($removeme);
44my ($uri,$list,$count,$added,$comment) = $sth->fetchrow_array;
45
46die "URI $removeme not found. Exiting.\n" if !$uri;
47
48# need to do the next in a single transaction
49local $dbh->{AutoCommit} = 0;
50local $dbh->{RaiseError} = 1;
51eval {
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};
58if ($@) {
59 my $msg = $@;
60 eval { $dbh->rollback; };
61 print "Failed to move record from urilist to waslisted: $msg\n";
62}
Note: See TracBrowser for help on using the repository browser.