source: trunk/dnsbl/DNSBLweb.pm@ 49

Last change on this file since 49 was 49, checked in by Kris Deugau, 9 years ago

/trunk/dnsbl

Add DNSBLweb.pm for browsing sub that doesn't go into DNSBL.pm well
Update copyright dates on DNSBL.pm

File size: 3.0 KB
Line 
1# Perl fragment for spitting out the browse pane of dnsbl.cgi and for browse.cgi
2# Module-ized because it's apparently (next to) impossible to do a C-style
3# "#include <file>", and this doesn't fit well into the main DNSBL module.
4##
5# $Id: DNSBL.pm 48 2014-12-09 21:29:34Z kdeugau $
6# Copyright 2014 Kris Deugau <kdeugau@deepnet.cx>
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20##
21
22package DNSBLweb;
23
24use Exporter;
25use HTML::Template;
26use NetAddr::IP;
27
28use DNSBL;
29
30sub retlvl {
31 my %ipseen;
32 my $dbh = shift;
33 my $dnsbl = shift;
34 my $lvl = shift;
35 if ($lvl > $DNSBL::maxlvl) {
36 warn "$lvl past max ".$DNSBL::maxlvl.", breaking off\n";
37 return;
38 }
39 my $ret;
40
41 my %args = @_;
42 my $pblock = $args{block} || '0/0';
43 my $ip;
44 if ($args{ip}) {
45 $ip = $args{ip};
46 } else {
47 $ip = '0/0';
48 }
49 my $ipcidr = new NetAddr::IP $ip;
50
51 my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ".
52 "FROM blocks b INNER JOIN orgs o ON b.orgid=o.orgid ".
53 "WHERE b.block <<=";
54 my $allsth = $dbh->prepare($basesql."? AND b.level=? ORDER BY block");
55 my $sthiplist = $dbh->prepare("SELECT * FROM iplist WHERE ip <<= ? ORDER BY ip");
56 $allsth->execute($pblock,$lvl);
57 while (my ($block,$org,$listmeb,$listmeo,$bcomments,$ocomments) = $allsth->fetchrow_array) {
58 my $tmpl = new HTML::Template(filename => "browse-block.tmpl");
59 my $blockcidr = new NetAddr::IP $block;
60 $tmpl->param(lvlclass => "lvl$lvl".($dnsbl->autolist_block($block) ? " auto$lvl" : '').
61 ( $ipcidr->within($blockcidr) ? ' inhere' : ''));
62
63 $tmpl->param(netclass => ($listmeb ? "b$lvl".'list' : ''));
64 $tmpl->param(net => $block);
65 $tmpl->param(orgclass => ($listmeo ? "b$lvl".'org' : ''));
66 $tmpl->param(org => $org);
67 $tmpl->param(bcomment => $bcomments) if $bcomments;
68 $tmpl->param(ocomment => $ocomments) if $ocomments;
69 $tmpl->param(indent => ' 'x$lvl);
70 $tmpl->param(subs => DNSBLweb::retlvl($dbh, $dnsbl, $lvl+1, block => $block, ip => $ip));
71 $sthiplist->execute($block);
72 my @iprows;
73 while (my @data4 = $sthiplist->fetchrow_array) {
74 next if $ipseen{$data4[0]};
75 my %iprow;
76 $iprow{ip} = $data4[0];
77 $iprow{ipcount} = $data4[1];
78 $iprow{indent} = ' 'x$lvl;
79# ip | count | s4list | added
80 push @iprows, \%iprow;
81 $ipseen{$data4[0]} = 1;
82 }
83 $tmpl->param(iplist => \@iprows);
84 $ret .= $tmpl->output;
85 }
86 return $ret;
87}
88
89# because Perl.
901;
Note: See TracBrowser for help on using the repository browser.