Index: trunk/dnsbl/dnsbl.cgi
===================================================================
--- trunk/dnsbl/dnsbl.cgi	(revision 46)
+++ trunk/dnsbl/dnsbl.cgi	(revision 51)
@@ -3,5 +3,5 @@
 ##
 # $Id$
-# Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>
+# Copyright 2009-2011,2014 Kris Deugau <kdeugau@deepnet.cx>
 # 
 #    This program is free software: you can redistribute it and/or modify
@@ -27,4 +27,5 @@
 
 use DNSBL;
+use DNSBLweb;
 
 # Set up the CGI object...
@@ -98,5 +99,6 @@
   my $count = $dnsbl->ipexists($webvar{ip});
   $page->param(nreports => $count) if $count;
-  $page->param(browsebits => browse($dbh,$webvar{ip}));
+  $page->param(browsebits =>
+	DNSBLweb::retlvl($dbh, $dnsbl, 0, ip => $webvar{ip}, block => $dnsbl->getcontainer($webvar{ip},0) ));
   for (my $i=0; $i<3; $i++) {
     my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i);
@@ -157,128 +159,7 @@
   $page->param(err => $err);
 
-  $page->param(browsebits => browse($dbh,$webvar{ip}));
+  $page->param(browsebits => 
+	DNSBLweb::retlvl($dbh, $dnsbl, 0, ip => $webvar{ip}, block => $dnsbl->getcontainer($webvar{ip},0) ));
 }
 
 print $page->output;
-
-exit 0;
-
-
-
-## extra subs.  should probably put this in a module somehow to share with browse.cgi
-
-sub browse {
-  my $dbh = shift;
-  my $ip = shift;
-  my $ipcidr = new NetAddr::IP $ip;
-
-  my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ".
-	"FROM blocks b INNER JOIN orgs o ON b.orgid=o.orgid ".
-	"WHERE b.block ";
-
-  my $sth0 = $dbh->prepare($basesql." >> ? AND b.level=0 ORDER BY block");
-  my $sth1 = $dbh->prepare($basesql." <<= ? AND b.level=1 ORDER BY block");
-  my $sth2 = $dbh->prepare($basesql." <<= ? AND b.level=2 ORDER BY block");
-  my $sthiplist = $dbh->prepare("select * from iplist where ip <<= ? order by ip");
-
-  my %ipseen;
-  my $out = '';
-
-  my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');
-
-  $sth0->execute($ip);
-  while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {
-    my $block0cidr = new NetAddr::IP $block0;
-    $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : '').
-	( $ipcidr->within($block0cidr) ? ' inhere' : ''));
-    $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));
-    $tmpl0->param(net => $block0);
-    $tmpl0->param(orgclass => ($listmeo0 ? 'b0org' : ''));
-    $tmpl0->param(org => $org0);
-    $tmpl0->param(bcomment => $bcomments0) if $bcomments0;
-    $tmpl0->param(ocomment => $ocomments0) if $ocomments0;
-    $sth1->execute($block0);
-    my $lvl1out = '';
-    if ($sth1->rows > 0) {
-      while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {
-	my $block1cidr = new NetAddr::IP $block1;
-	my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');
-	$tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : '').
-		( $ipcidr->within($block1cidr) ? ' inhere' : ''));
-	$tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));
-	$tmpl1->param(net => $block1);
-	$tmpl1->param(orgclass => ($listmeo1 ? 'b1org' : ''));
-	$tmpl1->param(org => $org1);
-	$tmpl1->param(bcomment => $bcomments1) if $bcomments1;
-	$tmpl1->param(ocomment => $ocomments1) if $ocomments1;
-	$tmpl1->param(indent => '  ');
-        my $lvl2out = '';
-	$sth2->execute($block1);
-	if ($sth2->rows > 0) {
-	  while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
-	    my $block2cidr = new NetAddr::IP $block2;
-	    my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');
-	    $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : '').
-		( $ipcidr->within($block2cidr) ? ' inhere' : ''));
-	    $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));
-	    $tmpl2->param(net => $block2);
-	    $tmpl2->param(orgclass => ($listmeo2 ? 'b2org' : ''));
-	    $tmpl2->param(org => $org2);
-	    $tmpl2->param(bcomment => $bcomments2) if $bcomments2;
-	    $tmpl2->param(ocomment => $ocomments2) if $ocomments2;
-	    $tmpl2->param(indent => '    ');
-	    $sthiplist->execute($block2);
-	    my @iprows;
-	    while (my @data4 = $sthiplist->fetchrow_array) {
-	      my %iprow;
-	      $iprow{ip} = $data4[0];
-	      $iprow{ipcount} = $data4[1];
-	      $iprow{indent} = '    ';
-	      $iprow{repeater} = 1 if $ip eq $data4[0];
-#       ip        | count | s4list |             added
-	      push @iprows, \%iprow;
-	      $ipseen{$data4[0]} = 1;
-	    }
-	    $tmpl2->param(iplist => \@iprows);
-	    $lvl2out .= $tmpl2->output;
-	  }
-	}
-
-	$sthiplist->execute($block1);
-	my @iprows;
-	while (my @data4 = $sthiplist->fetchrow_array) {
-	  next if $ipseen{$data4[0]};
-	  my %iprow;
-	  $iprow{ip} = $data4[0];
-	  $iprow{ipcount} = $data4[1];
-	  $iprow{indent} = '  ';
-	  $iprow{repeater} = 1 if $ip eq $data4[0];
-#       ip        | count | s4list |             added
-	  push @iprows, \%iprow;
-	  $ipseen{$data4[0]} = 1;
-	}
-	$tmpl1->param(iplist => \@iprows);
-	$tmpl1->param(subs => $lvl2out);
-        $lvl1out .= $tmpl1->output;
-
-      }
-    } # sth1->rows
-    $sthiplist->execute($block0);
-    my @iprows;
-    while (my @data4 = $sthiplist->fetchrow_array) {
-      next if $ipseen{$data4[0]};
-      my %iprow;
-      $iprow{ip} = $data4[0];
-      $iprow{ipcount} = $data4[1];
-      $iprow{indent} = '';
-      $iprow{repeater} = 1 if $ip eq $data4[0];
-#       ip        | count | s4list |             added
-      push @iprows, \%iprow;
-      $ipseen{$data4[0]} = 1;
-    }
-    $tmpl0->param(iplist => \@iprows);
-    $tmpl0->param(subs => $lvl1out);
-  }
-
-  return $tmpl0->output;
-} # end browse()
