Changeset 54


Ignore:
Timestamp:
12/11/14 17:22:28 (10 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Extend the number of layers/depth from 3 to 7 internally. Note that only

5 are exposed in the "add" UI.

Add support to extract the CIDR range when a WHOIS lookup gives a non-CIDR

range.

Fix tracking of "seen" IPs creating the browse display.
Add the new DNSBLweb.pm to the Makefile MANIFEST, and bump the version in

the Makefile

Location:
trunk/dnsbl
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r50 r54  
    272272
    273273
     274# take an arbitrary IP range and an IP, and return the CIDR block (if any) the IP is in.
     275sub range2cidr {
     276  my $self = shift;
     277  my $rstart = shift;
     278  my $rend = shift;
     279  my $ip = shift;
     280
     281  $rstart = new NetAddr::IP $rstart;
     282  $rend = new NetAddr::IP $rend;
     283  # Basic algoithm:  Set the mask on the IP, and see if both $rstart and $rend
     284  # are within the range defined by that IP/mask.  Continue making the mask
     285  # larger until success.
     286
     287  my $mask;
     288  for ($mask = 32; $mask > 0; $mask--) {
     289    my $ip = NetAddr::IP->new("$ip/$mask");
     290    if (NetAddr::IP->new($ip->network->addr)   >= $rstart    &&
     291        NetAddr::IP->new($ip->broadcast->addr) <= $rend) {
     292      next;
     293    } else {
     294      $mask++;
     295      last;
     296    }
     297  }
     298  my $realnet = NetAddr::IP->new("$ip/$mask")->network;
     299
     300  return "$realnet";
     301} # end range2cidr()
     302
     303
    274304# add a block.  requires the orgid
    275305##fixme needs error handling
  • trunk/dnsbl/DNSBLweb.pm

    r49 r54  
    4040
    4141  my %args = @_;
     42  $args{ipseen} = \%ipseen if !defined($args{ipseen});
    4243  my $pblock = $args{block} || '0/0';
    4344  my $ip; 
     
    6869    $tmpl->param(ocomment => $ocomments) if $ocomments;
    6970    $tmpl->param(indent => '  'x$lvl);
    70     $tmpl->param(subs => DNSBLweb::retlvl($dbh, $dnsbl, $lvl+1, block => $block, ip => $ip));
     71    $tmpl->param(subs => DNSBLweb::retlvl($dbh, $dnsbl, $lvl+1, block => $block, ip => $ip, ipseen => $args{ipseen}));
    7172    $sthiplist->execute($block);
    7273    my @iprows;
    7374    while (my @data4 = $sthiplist->fetchrow_array) {
    74       next if $ipseen{$data4[0]};
     75      next if $args{ipseen}->{$data4[0]};
    7576      my %iprow;
    7677      $iprow{ip} = $data4[0];
     
    7980#       ip        | count | s4list |             added
    8081      push @iprows, \%iprow;
    81       $ipseen{$data4[0]} = 1;
     82      $args{ipseen}->{$data4[0]} = 1;
    8283    }
    8384    $tmpl->param(iplist => \@iprows);
  • trunk/dnsbl/Makefile

    r42 r54  
    99MANIFEST = \
    1010        browse.cgi check-iplist.pl delist-ip export-dnsbl index.shtml Makefile \
    11         dnsbl.cgi DNSBL.pm dnsbl.sql templates/ addparents.sql setparents.pl \
     11        dnsbl.cgi DNSBL.pm DNSBLweb.pm dnsbl.sql templates/ addparents.sql setparents.pl \
    1212        COPYING sa-dnsbl-example.cf
    1313
    1414PKGNAME=dnsbl
    15 VERSION=0.2.2
     15VERSION=0.3.0
    1616
    1717all:
  • trunk/dnsbl/dnsbl.cgi

    r51 r54  
    4141
    4242my $dnsbl = new DNSBL;
     43# here be drag'ns, should theoretically be $DNSBL::maxlvl, but we
     44# only have up to level 4 in the report HTML/template
     45my $maxlvl = 4
    4346
    4447# try to be friendly to non-US-ASCII characters.  Still need to find what
     
    101104  $page->param(browsebits =>
    102105        DNSBLweb::retlvl($dbh, $dnsbl, 0, ip => $webvar{ip}, block => $dnsbl->getcontainer($webvar{ip},0) ));
    103   for (my $i=0; $i<3; $i++) {
     106  for (my $i=0; $i <= $maxlvl; $i++) {
    104107    my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i);
    105108    if ($block) {
     
    119122
    120123  my $err = '';
    121   my $org0id = $dnsbl->orgexists($webvar{org0});
    122   if (!$org0id) {
    123     $org0id = $dnsbl->addorg($webvar{org0});
    124     $page->param(org0 => $webvar{org0});
     124
     125  # basic algo:  for each listing level, add the org and block if not already present.
     126  # escape the loop if we check a level with no block entered.
     127
     128  # there are still error checks that should probably be done.  changes in block
     129  # level/parenting should also Just Work(TM), rather than requiring setparents.pl
     130  # or setparents-full.pl
     131  for (my $i = 0; $i <= $maxlvl; $i++) {
     132    my $orgn = "org$i";
     133    my $blockn = "block$i";
     134    my $orgid = $dnsbl->orgexists($webvar{$orgn});
     135    if (!$orgid) {
     136      $orgid = $dnsbl->addorg($webvar{$orgn});
     137      $page->param($orgn => $webvar{$orgn});
     138    }
     139    if ($webvar{$blockn} =~ /-/) {
     140      $err .= "Autofinding CIDR block containing $webvar{ip} for range '$webvar{$blockn}': ";
     141      my ($s,$f) = split /[\s-]+/, $webvar{$blockn};
     142      my $cidr = $dnsbl->range2cidr($s, $f, $webvar{ip});
     143      $err .= "$cidr<br>\n";
     144      $webvar{$blockn} = $cidr;
     145    }
     146    if (!$dnsbl->blockexists($webvar{$blockn})) {
     147      my $ret = $dnsbl->addblock($webvar{$blockn}, $orgid, $i);
     148      $err .= "error adding $webvar{$blockn}: $ret<br>\n" if $ret;
     149      $page->param($blockn => $webvar{$blockn});
     150    }
     151    last unless $webvar{"block".($i+1)};
    125152  }
    126   if (!$dnsbl->blockexists($webvar{block0})) {
    127     my $ret = $dnsbl->addblock($webvar{block0}, $org0id, 0);
    128     $err .= "error adding $webvar{block0}: $ret<br>\n" if $ret;
    129     $page->param(block0 => $webvar{block0});
    130   }
    131 # yes, this is grotty.  PTHBTT!
    132   if ($webvar{block1}) {
    133     my $org1id = $dnsbl->orgexists($webvar{org1});
    134     if (!$org1id) {
    135       $org1id = $dnsbl->addorg($webvar{org1});
    136       $page->param(org1 => $webvar{org1});
    137     }
    138     if (!$dnsbl->blockexists($webvar{block1})) {
    139       my $ret = $dnsbl->addblock($webvar{block1}, $org1id, 1);
    140       $err .= "error adding $webvar{block1}: $ret<br>\n" if $ret;
    141       $page->param(block1 => $webvar{block1});
    142     }
    143     if ($webvar{block2}) {
    144       my $org2id = $dnsbl->orgexists($webvar{org2});
    145       if (!$org2id) {
    146         $org2id = $dnsbl->addorg($webvar{org2});
    147         $page->param(org2 => $webvar{org2});
    148       }
    149       if (!$dnsbl->blockexists($webvar{block2})) {
    150         my $ret = $dnsbl->addblock($webvar{block2}, $org2id, 2);
    151         $err .= "error adding $webvar{block2}: $ret<br>\n" if $ret;
    152         $page->param(block2 => $webvar{block2});
    153       }
    154     }
    155   }
     153
    156154  my $count = $dnsbl->report($webvar{ip});
    157155
Note: See TracChangeset for help on using the changeset viewer.