source: trunk/dnsbl/export-dnsbl@ 29

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

/trunk/dnsbl

Add islisted()
Add waslisted table in SQL def
Indicate block status on adding an IP to an existing block
Fix for scripts-not-at-webroot
Tweak for scrolling "blocks in this registrar block" list
Load more config from DB on export

  • Property svn:executable set to *
  • Property svn:keywords set to Date Rev Author Id
File size: 3.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# default DB info - all other settings should be loaded from the DB.
17my $dbhost = "localhost";
18my $dbname = "dnsbl";
19my $dbuser = "dnsbl";
20my $dbpass = "spambgone";
21
22die "Need config argument\n" if !$ARGV[0];
23my $cfgname = shift @ARGV;
24
25# Load a config ref containing DB host, name, user, and pass info based on
26# from the server name + full script web path. This allows us to host
27# multiple instances without having to duplicate the code.
28# This file is a Perl fragment to be processed inline.
29if (-e "/etc/dnsbl/$cfgname.conf") {
30 my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
31 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
32 eval $cfg;
33}
34
35my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
36
37my %config;
38my $sth = $dbh->prepare("SELECT key,value FROM misc");
39$sth->execute;
40while (my ($key,$value) = $sth->fetchrow_array) {
41 $config{$key} = $value;
42}
43
44my %iplist;
45my $ipref = \%iplist;
46
47my $mode = $ARGV[0] || 'tiny';
48
49#$dnsbl->export($ipref,$mode,1,'65.60/18');
50#$dnsbl->export($ipref,$mode,1,'67.136.0.0/14');
51#$dnsbl->export($ipref,$mode,1,'83.76/15');
52#$dnsbl->export($ipref,$mode,1,'76.73.0.0/17');
53#$dnsbl->export($ipref,$mode,1,'174.36.0.0/15');
54$dnsbl->initexport;
55$dnsbl->export($ipref,$mode);
56
57##fixme - mode should pick actual output, not just export mode
58if ($mode eq 'cidr') {
59 # SOA, NS records. Maybe dnscache needs them?
60 print "\$SOA 900 ".($config{blzone} ? $config{blzone} : 'company').".dnsbl systems.company.com 0 1200 600 600 900\n".
61 "\$NS 3600 127.0.0.1\n".
62 "\$TTL 900\n";
63
64 # more or less raw CIDR block-and-IP info. rbldnsd format for convenience.
65 foreach (sort ipcmp keys %iplist) {
66 print "$_:127.0.0.$iplist{$_}:".
67 ($iplist{$_} & 2 ?
68 ($config{iplisted} ? $config{iplisted} : '$ relayed a reported spam') :
69 ($config{blocklisted} ? $config{blocklisted} : 'Netblock listed on one or more criteria')
70 )."\n";
71 }
72} else {
73 foreach (sort ipcmp keys %iplist) {
74 my ($o1,$o2,$o3,$o4) = (/^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?$/);
75 print "+".(defined($o4) ? "$o4." : '').(defined($o3) ? "$o3." : '').(defined($o2) ? "$o2." : '').
76 "$o1.spamhosts.company.com:127.0.0.$iplist{$_}:900:::\n";
77 }
78}
79
80exit 0;
81
82# IP address comparison sub
83sub ipcmp {
84 my ($a1,$a2,$a3,$a4,$a5) = ($a =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
85 my ($b1,$b2,$b3,$b4,$b5) = ($b =~ /^(\d+)\.([\d*]+)(?:\.([\d*]+)(?:\.([\d*]+))?)?(?:\/(\d+))?$/);
86# le sigh. knew it wasn't going to be simple...
87 $b2 = -1 if $b2 && $b2 eq '*';
88 $b3 = -1 if $b3 && $b3 eq '*';
89 $b4 = -1 if $b4 && $b4 eq '*';
90 $b5 = 128 if !defined($b5);
91 $a2 = -1 if $a2 && $a2 eq '*';
92 $a3 = -1 if $a3 && $a3 eq '*';
93 $a4 = -1 if $a4 && $a4 eq '*';
94 $a5 = 128 if !defined($a5);
95 return 1 if $a1 > $b1;
96 return -1 if $a1 < $b1;
97 return 1 if $a2 > $b2;
98 return -1 if $a2 < $b2;
99 return 1 if $a3 > $b3;
100 return -1 if $a3 < $b3;
101 return 1 if $a4 > $b4;
102 return -1 if $a4 < $b4;
103 return 1 if $a5 > $b5;
104 return -1 if $a5 < $b5;
105 return 0;
106}
Note: See TracBrowser for help on using the repository browser.