source: trunk/dnsbl/export-dnsbl@ 23

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

/trunk/dnsbl

Shuffle processing in DNSBL::export() for 1.5-10x speedup (depending

on DB version, OS, Perl, phase of moon):

  • prepare some statement handles more globally, so we're not recreating them for each netblock (moved to new sub initexport())
  • pass the bitmask down the recursion chain instead of retrieving parent "islisted?" info for each netblock
  • remove complex JOIN on recursion loop so we don't wait so long for the DB to finish

Trim commented stale code.

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 2.2 KB
Line 
1#!/usr/bin/perl
2# Export DNSBL data
3# 2009/05/26 kdeugau@deepnet.cx
4# need to stub it out so it can use a module to actually write zone
5# data for different NS software
6# completed 2008/08/14
7
8use strict;
9use warnings;
10use DBI;
11
12use DNSBL;
13
14my $dnsbl = new DNSBL;
15
16$dnsbl->connect;
17
18my %iplist;
19my $ipref = \%iplist;
20
21my $mode = $ARGV[0] || 'tiny';
22
23#$dnsbl->export($ipref,$mode,1,'65.60/18');
24#$dnsbl->export($ipref,$mode,1,'67.136.0.0/14');
25#$dnsbl->export($ipref,$mode,1,'83.76/15');
26#$dnsbl->export($ipref,$mode,1,'76.73.0.0/17');
27#$dnsbl->export($ipref,$mode,1,'174.36.0.0/15');
28$dnsbl->initexport;
29$dnsbl->export($ipref,$mode);
30
31##fixme - mode should pick actual output, not just export mode
32if ($mode eq 'cidr') {
33 # SOA, NS records. Maybe dnscache needs them?
34 print "\$SOA 900 company.dnsbl systems.company.com 0 1200 600 600 900\n".
35 "\$NS 3600 127.0.0.1\n".
36 "\$TTL 900\n";
37
38 # more or less raw CIDR block-and-IP info. rbldnsd format for convenience.
39 foreach (sort ipcmp keys %iplist) {
40 print "$_:127.0.0.$iplist{$_}:".
41 ($iplist{$_} & 2 ? '$ relayed a reported spam' : 'Netblock listed on one or more criteria')."\n";
42 }
43} else {
44 foreach (sort ipcmp keys %iplist) {
45 my ($o1,$o2,$o3,$o4) = (/^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?$/);
46 print "+".(defined($o4) ? "$o4." : '').(defined($o3) ? "$o3." : '').(defined($o2) ? "$o2." : '').
47 "$o1.spamhosts.company.com:127.0.0.$iplist{$_}:900:::\n";
48 }
49}
50
51exit 0;
52
53# IP address comparison sub
54sub ipcmp {
55 my ($a1,$a2,$a3,$a4,$a5) = ($a =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
56 my ($b1,$b2,$b3,$b4,$b5) = ($b =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
57# le sigh. knew it wasn't going to be simple...
58 $b2 = -1 if $b2 && $b2 eq '*';
59 $b3 = -1 if $b3 && $b3 eq '*';
60 $b4 = -1 if $b4 && $b4 eq '*';
61 $b5 = 128 if !defined($b5);
62 $a2 = -1 if $a2 && $a2 eq '*';
63 $a3 = -1 if $a3 && $a3 eq '*';
64 $a4 = -1 if $a4 && $a4 eq '*';
65 $a5 = 128 if !defined($a5);
66 return 1 if $a1 > $b1;
67 return -1 if $a1 < $b1;
68 return 1 if $a2 > $b2;
69 return -1 if $a2 < $b2;
70 return 1 if $a3 > $b3;
71 return -1 if $a3 < $b3;
72 return 1 if $a4 > $b4;
73 return -1 if $a4 < $b4;
74 return 1 if $a5 > $b5;
75 return -1 if $a5 < $b5;
76 return 0;
77}
Note: See TracBrowser for help on using the repository browser.