1 | #!/usr/bin/perl
|
---|
2 | # quickndirty browse-the-damned-by-web
|
---|
3 |
|
---|
4 | use strict;
|
---|
5 | use warnings;
|
---|
6 | use DBI;
|
---|
7 | use CGI::Carp qw(fatalsToBrowser);
|
---|
8 | use HTML::Template;
|
---|
9 |
|
---|
10 | use DNSBL;
|
---|
11 |
|
---|
12 | my $dnsbl = new DNSBL;
|
---|
13 |
|
---|
14 | my $dbh = $dnsbl->connect;
|
---|
15 |
|
---|
16 | print "Content-Type: text/html\n\n";
|
---|
17 |
|
---|
18 | my @lvl0 = ("foo", "bar", "bax");
|
---|
19 | my $template = HTML::Template->new(filename => 'templates/browse.tmpl');
|
---|
20 |
|
---|
21 | my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments ".
|
---|
22 | "FROM blocks b INNER JOIN orgs o ON b.orgid=o.orgid ".
|
---|
23 | "WHERE b.block <<= ";
|
---|
24 | my $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");
|
---|
26 | my $sth1 = $dbh->prepare($basesql."? AND b.level=1 ORDER BY block");
|
---|
27 | my $sth2 = $dbh->prepare($basesql."? AND b.level=2 ORDER BY block");
|
---|
28 | my $sthiplist = $dbh->prepare("select * from iplist where ip <<= ? order by ip");
|
---|
29 |
|
---|
30 | print $template->output;
|
---|
31 |
|
---|
32 | my %ipseen;
|
---|
33 |
|
---|
34 | $sth0->execute;
|
---|
35 | while (my ($block0,$org0,$listmeb0,$listmeo0,$comments0) = $sth0->fetchrow_array) {
|
---|
36 | print "<div class=\"lvl0".($dnsbl->autolist_block($block0) ? ' auto0"' : '"').
|
---|
37 | "><span".($listmeb0 ? ' class=b0list' : '').">$block0</span> ".
|
---|
38 | "<span".($listmeo0 ? ' class=b0org' : '').">$org0</span>\n";
|
---|
39 | $sth1->execute($block0);
|
---|
40 | if ($sth1->rows > 0) {
|
---|
41 | while (my ($block1,$org1,$listmeb1,$listmeo1,$comments1) = $sth1->fetchrow_array) {
|
---|
42 | # lvl 1 div open
|
---|
43 | print " <div class=\"lvl1".($dnsbl->autolist_block($block1) ? ' auto1"' : '"').
|
---|
44 | "><span".($listmeb1 ? ' class=b1list' : '').">$block1</span> ".
|
---|
45 | "<span".($listmeo1 ? ' class=b1org' : '').">$org1</span>\n";
|
---|
46 | $sth2->execute($block1);
|
---|
47 | if ($sth2->rows > 0) {
|
---|
48 | while (my ($block2,$org2,$listmeb2,$listmeo2,$comments2) = $sth2->fetchrow_array) {
|
---|
49 | # lvl 2 div open
|
---|
50 | print " <div class=\"lvl2".($dnsbl->autolist_block($block2) ? ' auto2"' : '"').
|
---|
51 | "><span".($listmeb2 ? ' class=b2list' : '').">$block2</span> ".
|
---|
52 | "<span".($listmeo2 ? ' class=b2org' : '').">$org2</span>\n";
|
---|
53 | $sthiplist->execute($block2);
|
---|
54 | print " <div class=iplist>\n";
|
---|
55 | while (my @data4 = $sthiplist->fetchrow_array) {
|
---|
56 | print " $data4[0]<br>\n";
|
---|
57 | $ipseen{$data4[0]} = 1;
|
---|
58 | }
|
---|
59 | print " </div>\n";
|
---|
60 | # lvl2 div close
|
---|
61 | print " </div>\n";
|
---|
62 | }
|
---|
63 | } else {
|
---|
64 | $sthiplist->execute($block1);
|
---|
65 | print " <div class=iplist>\n";
|
---|
66 | while (my @data4 = $sthiplist->fetchrow_array) {
|
---|
67 | print " $data4[0]<br>\n";
|
---|
68 | $ipseen{$data4[0]} = 1;
|
---|
69 | }
|
---|
70 | print " </div>\n";
|
---|
71 | }
|
---|
72 |
|
---|
73 | my $sqlalt = "select ip from iplist where ip << ?";
|
---|
74 | my $sthalt = $dbh->prepare($sqlalt);
|
---|
75 | $sthalt->execute($block1);
|
---|
76 | my @newips;
|
---|
77 | while (my @data4 = $sthalt->fetchrow_array) {
|
---|
78 | push @newips, $data4[0] if !$ipseen{$data4[0]};
|
---|
79 | $ipseen{$data4[0]} = 1;
|
---|
80 | }
|
---|
81 | if ($#newips > -1) {
|
---|
82 | print " <div class=iplist>\n";
|
---|
83 | foreach (@newips) {
|
---|
84 | print " $_<br>\n";
|
---|
85 | }
|
---|
86 | print " </div>\n";
|
---|
87 | }
|
---|
88 | # lvl 1 div close
|
---|
89 | print " </div>\n";
|
---|
90 | }
|
---|
91 | } else {
|
---|
92 | $sthiplist->execute($block0);
|
---|
93 | print " <div class=iplist>\n";
|
---|
94 | while (my @data4 = $sthiplist->fetchrow_array) {
|
---|
95 | print " $data4[0]<br>\n";
|
---|
96 | $ipseen{$data4[0]} = 1;
|
---|
97 | }
|
---|
98 | print " </div>\n";
|
---|
99 | }
|
---|
100 |
|
---|
101 | my $sqlalt = "select ip from iplist where ip << ?";
|
---|
102 | my $sthalt = $dbh->prepare($sqlalt);
|
---|
103 | $sthalt->execute($block0);
|
---|
104 | my @newips;
|
---|
105 | while (my @data4 = $sthalt->fetchrow_array) {
|
---|
106 | push @newips, $data4[0] if (!$ipseen{$data4[0]});
|
---|
107 | }
|
---|
108 | if ($#newips > -1) {
|
---|
109 | print " <div class=iplist>\n";
|
---|
110 | foreach (@newips) {
|
---|
111 | print " $_<br>\n";
|
---|
112 | }
|
---|
113 | print " </div>\n";
|
---|
114 | }
|
---|
115 |
|
---|
116 | print "</div>\n";
|
---|
117 | }
|
---|