Changeset 19 for trunk/dnsbl/browse.cgi


Ignore:
Timestamp:
05/04/10 16:22:50 (14 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Update dnsbl.cgi and browse.cgi to display all IPs with count properly,

use HTML::Template for structure instead of hand-spewing HTML

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/browse.cgi

    r7 r19  
    2323        "WHERE b.block <<= ";
    2424my $sth0 = $dbh->prepare($basesql."'0/0' AND b.level=0 ORDER BY block");
    25 #my $sth0 = $dbh->prepare($basesql."'76.73.0.0/17' AND b.level=0 ORDER BY block");
     25#my $sth0 = $dbh->prepare($basesql."'64/8' AND b.level=0 ORDER BY block");
    2626my $sth1 = $dbh->prepare($basesql."? AND b.level=1 ORDER BY block");
    2727my $sth2 = $dbh->prepare($basesql."? AND b.level=2 ORDER BY block");
     
    3232my %ipseen;
    3333
     34my $out = '';
     35
    3436$sth0->execute;
    3537while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {
    36   print "<div class=\"lvl0".($dnsbl->autolist_block($block0) ? ' auto0"' : '"').
    37         "><span".($listmeb0 ? ' class=b0list' : '').">$block0".
    38         ($listmeb0 ? " ($bcomments0)" : '')."</span> ".
    39         "<span".($listmeo0 ? ' class=b0org' : '').">$org0".
    40         ($listmeo0 ? " ($ocomments0)" : '')."</span>\n";
     38  my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     39  $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : ''));
     40  $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));
     41  $tmpl0->param(net => $block0);
     42  $tmpl0->param(orgclass => ($listmeo0 ? 'b0org' : ''));
     43  $tmpl0->param(org => $org0);
     44  $tmpl0->param(bcomment => $bcomments0) if $bcomments0;
     45  $tmpl0->param(ocomment => $ocomments0) if $ocomments0;
    4146  $sth1->execute($block0);
     47  my $lvl1out = '';
    4248  if ($sth1->rows > 0) {
    4349    while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {
    44 # lvl 1 div open
    45       print "  <div class=\"lvl1".($dnsbl->autolist_block($block1) ? ' auto1"' : '"').
    46         "><span".($listmeb1 ? ' class=b1list' : '').">$block1".
    47         ($listmeb1 ? " ($bcomments1)" : '')."</span> ".
    48         "<span".($listmeo1 ? ' class=b1org' : '').">$org1".
    49         ($listmeo1 ? " ($ocomments1)" : '')."</span>\n";
     50      my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     51      $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : ''));
     52      $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));
     53      $tmpl1->param(net => $block1);
     54      $tmpl1->param(orgclass => ($listmeo1 ? 'b1org' : ''));
     55      $tmpl1->param(org => $org1);
     56      $tmpl1->param(bcomment => $bcomments1) if $bcomments1;
     57      $tmpl1->param(ocomment => $ocomments1) if $ocomments1;
     58      $tmpl1->param(indent => '  ');
     59      my $lvl2out = '';
    5060      $sth2->execute($block1);
    5161      if ($sth2->rows > 0) {
    52         while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
    53 # lvl 2 div open
    54           print "    <div class=\"lvl2".($dnsbl->autolist_block($block2) ? ' auto2"' : '"').
    55                 "><span".($listmeb2 ? ' class=b2list' : '').">$block2".
    56                 ($listmeb2 ? " ($bcomments2)" : '')."</span> ".
    57                 "<span".($listmeo2 ? ' class=b2org' : '').">$org2".
    58                 ($listmeo2 ? " ($ocomments2)" : '')."</span>\n";
    59           $sthiplist->execute($block2);
    60           print "      <div class=iplist>\n";
    61           while (my @data4 = $sthiplist->fetchrow_array) {
    62             print "        $data4[0]<br>\n";
    63             $ipseen{$data4[0]} = 1;
    64           }
    65           print "      </div>\n";
    66 # lvl2 div close
    67           print "    </div>\n";
    68         }
    69       } else {
    70         $sthiplist->execute($block1);
    71         print "    <div class=iplist>\n";
    72         while (my @data4 = $sthiplist->fetchrow_array) {
    73           print "      $data4[0]<br>\n";
    74           $ipseen{$data4[0]} = 1;
    75         }
    76         print "    </div>\n";
     62        while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
     63          my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     64          $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : ''));
     65          $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));
     66          $tmpl2->param(net => $block2);
     67          $tmpl2->param(orgclass => ($listmeo2 ? 'b2org' : ''));
     68          $tmpl2->param(org => $org2);
     69          $tmpl2->param(bcomment => $bcomments2) if $bcomments2;
     70          $tmpl2->param(ocomment => $ocomments2) if $ocomments2;
     71          $tmpl2->param(indent => '    ');
     72          $sthiplist->execute($block2);
     73          my @iprows;
     74          while (my @data4 = $sthiplist->fetchrow_array) {
     75            my %iprow;
     76            $iprow{ip} = $data4[0];
     77            $iprow{ipcount} = $data4[1];
     78            $iprow{indent} = '    ';
     79#       ip        | count | s4list |             added
     80            push @iprows, \%iprow;
     81            $ipseen{$data4[0]} = 1;
     82          }
     83          $tmpl2->param(iplist => \@iprows);
     84          $lvl2out .= $tmpl2->output;
     85        }
    7786      }
    7887
    79       my $sqlalt = "select ip from iplist where ip << ?";
    80       my $sthalt = $dbh->prepare($sqlalt);
    81       $sthalt->execute($block1);
    82       my @newips;
    83       while (my @data4 = $sthalt->fetchrow_array) {
    84         push @newips, $data4[0] if !$ipseen{$data4[0]};
    85         $ipseen{$data4[0]} = 1;
     88      $sthiplist->execute($block1);
     89      my @iprows;
     90      while (my @data4 = $sthiplist->fetchrow_array) {
     91        next if $ipseen{$data4[0]};
     92        my %iprow;
     93        $iprow{ip} = $data4[0];
     94        $iprow{ipcount} = $data4[1];
     95        $iprow{indent} = '  ';
     96#       ip        | count | s4list |             added
     97        push @iprows, \%iprow;
     98        $ipseen{$data4[0]} = 1;
    8699      }
    87       if ($#newips > -1) {
    88         print "    <div class=iplist>\n";
    89         foreach (@newips) {
    90           print "      $_<br>\n";
    91         }
    92         print "    </div>\n";
    93       }
    94 # lvl 1 div close
    95       print "  </div>\n";
     100      $tmpl1->param(iplist => \@iprows);
     101      $tmpl1->param(subs => $lvl2out);
     102      $lvl1out .= $tmpl1->output;
    96103    }
    97   } else {
    98     $sthiplist->execute($block0);
    99     print "  <div class=iplist>\n";
    100     while (my @data4 = $sthiplist->fetchrow_array) {
    101       print "    $data4[0]<br>\n";
    102       $ipseen{$data4[0]} = 1;
    103     }
    104     print "  </div>\n";
     104  } # sth1->rows
     105  $sthiplist->execute($block0);
     106  my @iprows;
     107  while (my @data4 = $sthiplist->fetchrow_array) {
     108    next if $ipseen{$data4[0]};
     109    my %iprow;
     110    $iprow{ip} = $data4[0];
     111    $iprow{ipcount} = $data4[1];
     112    $iprow{indent} = '';
     113#       ip        | count | s4list |             added
     114    push @iprows, \%iprow;
     115    $ipseen{$data4[0]} = 1;
    105116  }
     117  $tmpl0->param(iplist => \@iprows);
     118  $tmpl0->param(subs => $lvl1out);
     119  $out .= $tmpl0->output;
     120}
    106121
    107   my $sqlalt = "select ip from iplist where ip << ?";
    108   my $sthalt = $dbh->prepare($sqlalt);
    109   $sthalt->execute($block0);
    110   my @newips;
    111   while (my @data4 = $sthalt->fetchrow_array) {
    112     push @newips, $data4[0] if (!$ipseen{$data4[0]});
    113   }
    114   if ($#newips > -1) {
    115     print "  <div class=iplist>\n";
    116     foreach (@newips) {
    117       print "    $_<br>\n";
    118     }
    119     print "  </div>\n";
    120   }
    121 
    122   print "</div>\n";
    123 }
     122print $out;
Note: See TracChangeset for help on using the changeset viewer.