[2] | 1 | #!/usr/bin/perl
|
---|
| 2 |
|
---|
| 3 | use strict;
|
---|
| 4 | use warnings;
|
---|
| 5 | use DBI;
|
---|
| 6 |
|
---|
| 7 | use DNSBL;
|
---|
| 8 |
|
---|
| 9 | my $dnsbl = new DNSBL;
|
---|
| 10 |
|
---|
[25] | 11 | # default DB info - all other settings should be loaded from the DB.
|
---|
| 12 | my $dbhost = "localhost";
|
---|
| 13 | my $dbname = "dnsbl";
|
---|
| 14 | my $dbuser = "dnsbl";
|
---|
| 15 | my $dbpass = "spambgone";
|
---|
[2] | 16 |
|
---|
[25] | 17 | die "Need config argument\n" if !$ARGV[0];
|
---|
| 18 | my $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.
|
---|
| 24 | if (-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 |
|
---|
| 30 | my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
|
---|
| 31 |
|
---|
[2] | 32 | print "checking IP containment...\n";
|
---|
| 33 | my $sth = $dbh->prepare("select ip from iplist order by ip");
|
---|
| 34 | $sth->execute;
|
---|
| 35 | my $cksth = $dbh->prepare("select block from blocks where block >> ?");
|
---|
| 36 | while (my @data = $sth->fetchrow_array) {
|
---|
| 37 | $cksth->execute($data[0]);
|
---|
| 38 | print "$data[0] has no container\n" if $cksth->rows == 0;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | print "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");
|
---|
| 45 | while (my @data = $sth->fetchrow_array) {
|
---|
| 46 | $cksth->execute($data[0]);
|
---|
| 47 | print "$data[0] has no container\n" if $cksth->rows == 0;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | print "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");
|
---|
| 54 | while (my @data = $sth->fetchrow_array) {
|
---|
| 55 | $cksth->execute($data[0]);
|
---|
| 56 | print "$data[0] has no container\n" if $cksth->rows == 0;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | print "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 << ?");
|
---|
| 63 | while (my @data = $sth->fetchrow_array) {
|
---|
| 64 | $cksth->execute($data[0]);
|
---|
| 65 | print "$data[0] has no IPs\n" if $cksth->rows == 0;
|
---|
| 66 | }
|
---|
| 67 |
|
---|