Changeset 51
- Timestamp:
- 12/09/14 17:11:39 (10 years ago)
- Location:
- trunk/dnsbl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dnsbl/browse.cgi
r40 r51 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2011,2014 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 26 26 27 27 use DNSBL; 28 use DNSBLweb; 28 29 29 30 my $dnsbl = new DNSBL; … … 69 70 $template->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment}); 70 71 71 my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ". 72 "FROM blocks b INNER JOIN orgs o ON b.orgid=o.orgid ". 73 "WHERE b.parent = "; 74 my $sth0 = $dbh->prepare($basesql."'0/0' AND b.level=0 ORDER BY block"); 75 #my $sth0 = $dbh->prepare($basesql."'64/8' AND b.level=0 ORDER BY block"); 76 my $sth1 = $dbh->prepare($basesql."? AND b.level=1 ORDER BY block"); 77 my $sth2 = $dbh->prepare($basesql."? AND b.level=2 ORDER BY block"); 78 my $sthiplist = $dbh->prepare("select * from iplist where parent = ? order by ip"); 72 my $out = DNSBLweb::retlvl($dbh, $dnsbl, 0, block => '0/0'); 79 73 80 my %ipseen;81 82 my $out = '';83 84 $sth0->execute;85 while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {86 my $tmpl0 = new HTML::Template(filename => "browse-block.tmpl");87 $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : ''));88 $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));89 $tmpl0->param(net => $block0);90 $tmpl0->param(orgclass => ($listmeo0 ? 'b0org' : ''));91 $tmpl0->param(org => $org0);92 $tmpl0->param(bcomment => $bcomments0) if $bcomments0;93 $tmpl0->param(ocomment => $ocomments0) if $ocomments0;94 $sth1->execute($block0);95 my $lvl1out = '';96 if ($sth1->rows > 0) {97 while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {98 my $tmpl1 = new HTML::Template(filename => "browse-block.tmpl");99 $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : ''));100 $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));101 $tmpl1->param(net => $block1);102 $tmpl1->param(orgclass => ($listmeo1 ? 'b1org' : ''));103 $tmpl1->param(org => $org1);104 $tmpl1->param(bcomment => $bcomments1) if $bcomments1;105 $tmpl1->param(ocomment => $ocomments1) if $ocomments1;106 $tmpl1->param(indent => ' ');107 my $lvl2out = '';108 $sth2->execute($block1);109 if ($sth2->rows > 0) {110 while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {111 my $tmpl2 = new HTML::Template(filename => "browse-block.tmpl");112 $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : ''));113 $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));114 $tmpl2->param(net => $block2);115 $tmpl2->param(orgclass => ($listmeo2 ? 'b2org' : ''));116 $tmpl2->param(org => $org2);117 $tmpl2->param(bcomment => $bcomments2) if $bcomments2;118 $tmpl2->param(ocomment => $ocomments2) if $ocomments2;119 $tmpl2->param(indent => ' ');120 $sthiplist->execute($block2);121 my @iprows;122 while (my @data4 = $sthiplist->fetchrow_array) {123 my %iprow;124 $iprow{ip} = $data4[0];125 $iprow{ipcount} = $data4[1];126 $iprow{indent} = ' ';127 # ip | count | s4list | added128 push @iprows, \%iprow;129 $ipseen{$data4[0]} = 1;130 }131 $tmpl2->param(iplist => \@iprows);132 $lvl2out .= $tmpl2->output;133 }134 }135 136 $sthiplist->execute($block1);137 my @iprows;138 while (my @data4 = $sthiplist->fetchrow_array) {139 next if $ipseen{$data4[0]};140 my %iprow;141 $iprow{ip} = $data4[0];142 $iprow{ipcount} = $data4[1];143 $iprow{indent} = ' ';144 # ip | count | s4list | added145 push @iprows, \%iprow;146 $ipseen{$data4[0]} = 1;147 }148 $tmpl1->param(iplist => \@iprows);149 $tmpl1->param(subs => $lvl2out);150 $lvl1out .= $tmpl1->output;151 }152 } # sth1->rows153 $sthiplist->execute($block0);154 my @iprows;155 while (my @data4 = $sthiplist->fetchrow_array) {156 next if $ipseen{$data4[0]};157 my %iprow;158 $iprow{ip} = $data4[0];159 $iprow{ipcount} = $data4[1];160 $iprow{indent} = '';161 # ip | count | s4list | added162 push @iprows, \%iprow;163 $ipseen{$data4[0]} = 1;164 }165 $tmpl0->param(iplist => \@iprows);166 $tmpl0->param(subs => $lvl1out);167 $out .= $tmpl0->output;168 }169 170 # probably more efficient ways to do this somewhere...171 74 $template->param(enchilada => $out); 172 75 print $template->output; -
trunk/dnsbl/dnsbl.cgi
r46 r51 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2011,2014 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 27 27 28 28 use DNSBL; 29 use DNSBLweb; 29 30 30 31 # Set up the CGI object... … … 98 99 my $count = $dnsbl->ipexists($webvar{ip}); 99 100 $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) )); 101 103 for (my $i=0; $i<3; $i++) { 102 104 my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i); … … 157 159 $page->param(err => $err); 158 160 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) )); 160 163 } 161 164 162 165 print $page->output; 163 164 exit 0;165 166 167 168 ## extra subs. should probably put this in a module somehow to share with browse.cgi169 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 | added239 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 | added257 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->rows266 $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 | added276 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.