- Timestamp:
- 12/11/14 17:22:28 (10 years ago)
- Location:
- trunk/dnsbl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dnsbl/DNSBL.pm
r50 r54 272 272 273 273 274 # take an arbitrary IP range and an IP, and return the CIDR block (if any) the IP is in. 275 sub 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 274 304 # add a block. requires the orgid 275 305 ##fixme needs error handling -
trunk/dnsbl/DNSBLweb.pm
r49 r54 40 40 41 41 my %args = @_; 42 $args{ipseen} = \%ipseen if !defined($args{ipseen}); 42 43 my $pblock = $args{block} || '0/0'; 43 44 my $ip; … … 68 69 $tmpl->param(ocomment => $ocomments) if $ocomments; 69 70 $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})); 71 72 $sthiplist->execute($block); 72 73 my @iprows; 73 74 while (my @data4 = $sthiplist->fetchrow_array) { 74 next if $ ipseen{$data4[0]};75 next if $args{ipseen}->{$data4[0]}; 75 76 my %iprow; 76 77 $iprow{ip} = $data4[0]; … … 79 80 # ip | count | s4list | added 80 81 push @iprows, \%iprow; 81 $ ipseen{$data4[0]} = 1;82 $args{ipseen}->{$data4[0]} = 1; 82 83 } 83 84 $tmpl->param(iplist => \@iprows); -
trunk/dnsbl/Makefile
r42 r54 9 9 MANIFEST = \ 10 10 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 \ 12 12 COPYING sa-dnsbl-example.cf 13 13 14 14 PKGNAME=dnsbl 15 VERSION=0. 2.215 VERSION=0.3.0 16 16 17 17 all: -
trunk/dnsbl/dnsbl.cgi
r51 r54 41 41 42 42 my $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 45 my $maxlvl = 4 43 46 44 47 # try to be friendly to non-US-ASCII characters. Still need to find what … … 101 104 $page->param(browsebits => 102 105 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++) { 104 107 my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i); 105 108 if ($block) { … … 119 122 120 123 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)}; 125 152 } 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 156 154 my $count = $dnsbl->report($webvar{ip}); 157 155
Note:
See TracChangeset
for help on using the changeset viewer.