Changeset 51 for trunk/dnsbl/dnsbl.cgi


Ignore:
Timestamp:
12/09/14 17:11:39 (9 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Update browse.cgi and dnsbl.cgi to display extended depth entries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/dnsbl.cgi

    r46 r51  
    33##
    44# $Id$
    5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2011,2014 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2727
    2828use DNSBL;
     29use DNSBLweb;
    2930
    3031# Set up the CGI object...
     
    9899  my $count = $dnsbl->ipexists($webvar{ip});
    99100  $page->param(nreports => $count) if $count;
    100   $page->param(browsebits => browse($dbh,$webvar{ip}));
     101  $page->param(browsebits =>
     102        DNSBLweb::retlvl($dbh, $dnsbl, 0, ip => $webvar{ip}, block => $dnsbl->getcontainer($webvar{ip},0) ));
    101103  for (my $i=0; $i<3; $i++) {
    102104    my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i);
     
    157159  $page->param(err => $err);
    158160
    159   $page->param(browsebits => browse($dbh,$webvar{ip}));
     161  $page->param(browsebits =>
     162        DNSBLweb::retlvl($dbh, $dnsbl, 0, ip => $webvar{ip}, block => $dnsbl->getcontainer($webvar{ip},0) ));
    160163}
    161164
    162165print $page->output;
    163 
    164 exit 0;
    165 
    166 
    167 
    168 ## extra subs.  should probably put this in a module somehow to share with browse.cgi
    169 
    170 sub browse {
    171   my $dbh = shift;
    172   my $ip = shift;
    173   my $ipcidr = new NetAddr::IP $ip;
    174 
    175   my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ".
    176         "FROM blocks b INNER JOIN orgs o ON b.orgid=o.orgid ".
    177         "WHERE b.block ";
    178 
    179   my $sth0 = $dbh->prepare($basesql." >> ? AND b.level=0 ORDER BY block");
    180   my $sth1 = $dbh->prepare($basesql." <<= ? AND b.level=1 ORDER BY block");
    181   my $sth2 = $dbh->prepare($basesql." <<= ? AND b.level=2 ORDER BY block");
    182   my $sthiplist = $dbh->prepare("select * from iplist where ip <<= ? order by ip");
    183 
    184   my %ipseen;
    185   my $out = '';
    186 
    187   my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');
    188 
    189   $sth0->execute($ip);
    190   while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {
    191     my $block0cidr = new NetAddr::IP $block0;
    192     $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : '').
    193         ( $ipcidr->within($block0cidr) ? ' inhere' : ''));
    194     $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));
    195     $tmpl0->param(net => $block0);
    196     $tmpl0->param(orgclass => ($listmeo0 ? 'b0org' : ''));
    197     $tmpl0->param(org => $org0);
    198     $tmpl0->param(bcomment => $bcomments0) if $bcomments0;
    199     $tmpl0->param(ocomment => $ocomments0) if $ocomments0;
    200     $sth1->execute($block0);
    201     my $lvl1out = '';
    202     if ($sth1->rows > 0) {
    203       while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {
    204         my $block1cidr = new NetAddr::IP $block1;
    205         my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');
    206         $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : '').
    207                 ( $ipcidr->within($block1cidr) ? ' inhere' : ''));
    208         $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));
    209         $tmpl1->param(net => $block1);
    210         $tmpl1->param(orgclass => ($listmeo1 ? 'b1org' : ''));
    211         $tmpl1->param(org => $org1);
    212         $tmpl1->param(bcomment => $bcomments1) if $bcomments1;
    213         $tmpl1->param(ocomment => $ocomments1) if $ocomments1;
    214         $tmpl1->param(indent => '  ');
    215         my $lvl2out = '';
    216         $sth2->execute($block1);
    217         if ($sth2->rows > 0) {
    218           while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
    219             my $block2cidr = new NetAddr::IP $block2;
    220             my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');
    221             $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : '').
    222                 ( $ipcidr->within($block2cidr) ? ' inhere' : ''));
    223             $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));
    224             $tmpl2->param(net => $block2);
    225             $tmpl2->param(orgclass => ($listmeo2 ? 'b2org' : ''));
    226             $tmpl2->param(org => $org2);
    227             $tmpl2->param(bcomment => $bcomments2) if $bcomments2;
    228             $tmpl2->param(ocomment => $ocomments2) if $ocomments2;
    229             $tmpl2->param(indent => '    ');
    230             $sthiplist->execute($block2);
    231             my @iprows;
    232             while (my @data4 = $sthiplist->fetchrow_array) {
    233               my %iprow;
    234               $iprow{ip} = $data4[0];
    235               $iprow{ipcount} = $data4[1];
    236               $iprow{indent} = '    ';
    237               $iprow{repeater} = 1 if $ip eq $data4[0];
    238 #       ip        | count | s4list |             added
    239               push @iprows, \%iprow;
    240               $ipseen{$data4[0]} = 1;
    241             }
    242             $tmpl2->param(iplist => \@iprows);
    243             $lvl2out .= $tmpl2->output;
    244           }
    245         }
    246 
    247         $sthiplist->execute($block1);
    248         my @iprows;
    249         while (my @data4 = $sthiplist->fetchrow_array) {
    250           next if $ipseen{$data4[0]};
    251           my %iprow;
    252           $iprow{ip} = $data4[0];
    253           $iprow{ipcount} = $data4[1];
    254           $iprow{indent} = '  ';
    255           $iprow{repeater} = 1 if $ip eq $data4[0];
    256 #       ip        | count | s4list |             added
    257           push @iprows, \%iprow;
    258           $ipseen{$data4[0]} = 1;
    259         }
    260         $tmpl1->param(iplist => \@iprows);
    261         $tmpl1->param(subs => $lvl2out);
    262         $lvl1out .= $tmpl1->output;
    263 
    264       }
    265     } # sth1->rows
    266     $sthiplist->execute($block0);
    267     my @iprows;
    268     while (my @data4 = $sthiplist->fetchrow_array) {
    269       next if $ipseen{$data4[0]};
    270       my %iprow;
    271       $iprow{ip} = $data4[0];
    272       $iprow{ipcount} = $data4[1];
    273       $iprow{indent} = '';
    274       $iprow{repeater} = 1 if $ip eq $data4[0];
    275 #       ip        | count | s4list |             added
    276       push @iprows, \%iprow;
    277       $ipseen{$data4[0]} = 1;
    278     }
    279     $tmpl0->param(iplist => \@iprows);
    280     $tmpl0->param(subs => $lvl1out);
    281   }
    282 
    283   return $tmpl0->output;
    284 } # end browse()
Note: See TracChangeset for help on using the changeset viewer.