source: trunk/dnsbl/delist-ip@ 32

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

/trunk/dnsbl

Changeset to improve export speed on DNSBL database. By keeping
IP counts for each block, and directly tracking the parent of
each block and IP, an export taking ~90 seconds can be brought
down under 20.

  • updated initial tabledef SQL
  • Add addparents.sql SQL tabeldef and setparents.pl data update script
  • Tweak reporting of IP since it now requires the parent block(s) so the parent field can be filled in

Also add delist-ip script and Makefile

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