source: trunk/dnsbl/check-iplist.pl@ 25

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

/trunk/dnsbl

Changes across the board to support multi-instance without code changes.
DB config is now loaded from a fragment in /etc/dnsbl, and the DB in turn
contains the autolist thresholds and some visual sugar for the web
interface so you know which DB you're dealing with.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use DBI;
6
7use DNSBL;
8
9my $dnsbl = new DNSBL;
10
11# default DB info - all other settings should be loaded from the DB.
12my $dbhost = "localhost";
13my $dbname = "dnsbl";
14my $dbuser = "dnsbl";
15my $dbpass = "spambgone";
16
17die "Need config argument\n" if !$ARGV[0];
18my $cfgname = shift @ARGV;
19
20# Load a config ref containing DB host, name, user, and pass info based on
21# from the server name + full script web path. This allows us to host
22# multiple instances without having to duplicate the code.
23# This file is a Perl fragment to be processed inline.
24if (-e "/etc/dnsbl/$cfgname.conf") {
25 my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
26 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
27 eval $cfg;
28}
29
30my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
31
32print "checking IP containment...\n";
33my $sth = $dbh->prepare("select ip from iplist order by ip");
34$sth->execute;
35my $cksth = $dbh->prepare("select block from blocks where block >> ?");
36while (my @data = $sth->fetchrow_array) {
37 $cksth->execute($data[0]);
38 print "$data[0] has no container\n" if $cksth->rows == 0;
39}
40
41print "checking level 2 blocks...\n";
42$sth = $dbh->prepare("select block from blocks where level=2");
43$sth->execute;
44$cksth = $dbh->prepare("select block from blocks where block >> ? and level=1");
45while (my @data = $sth->fetchrow_array) {
46 $cksth->execute($data[0]);
47 print "$data[0] has no container\n" if $cksth->rows == 0;
48}
49
50print "checking level 1 blocks...\n";
51$sth = $dbh->prepare("select block from blocks where level=1");
52$sth->execute;
53$cksth = $dbh->prepare("select block from blocks where block >> ? and level=0");
54while (my @data = $sth->fetchrow_array) {
55 $cksth->execute($data[0]);
56 print "$data[0] has no container\n" if $cksth->rows == 0;
57}
58
59print "checking for empty blocks\n";
60$sth = $dbh->prepare("select block from blocks");
61$sth->execute;
62$cksth = $dbh->prepare("select ip from iplist where ip << ?");
63while (my @data = $sth->fetchrow_array) {
64 $cksth->execute($data[0]);
65 print "$data[0] has no IPs\n" if $cksth->rows == 0;
66}
67
Note: See TracBrowser for help on using the repository browser.