1 | #!/usr/bin/perl
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 | use CGI::Carp qw (fatalsToBrowser);
|
---|
6 | use CGI::Simple;
|
---|
7 | use HTML::Template;
|
---|
8 | use DNSBL;
|
---|
9 |
|
---|
10 | # Set up the CGI object...
|
---|
11 | my $q = new CGI::Simple;
|
---|
12 | # ... and get query-string params as well as POST params if necessary
|
---|
13 | $q->parse_query_string;
|
---|
14 |
|
---|
15 | my %webvar;
|
---|
16 | # This is probably excessive fiddling, but it puts the parameters somewhere my fingers know about...
|
---|
17 | foreach ($q->param()) {
|
---|
18 | $webvar{$_} = $q->param($_);
|
---|
19 | }
|
---|
20 |
|
---|
21 | my $dnsbl = new DNSBL;
|
---|
22 |
|
---|
23 | $dnsbl->connect;
|
---|
24 |
|
---|
25 | print "Content-type: text/html\n\n";
|
---|
26 |
|
---|
27 | my $page;
|
---|
28 | my $templatedir = "templates";
|
---|
29 |
|
---|
30 | # decide which page to spit out...
|
---|
31 | if (!$webvar{page}) {
|
---|
32 | $page = HTML::Template->new(filename => "$templatedir/index.tmpl");
|
---|
33 | } else {
|
---|
34 | $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
|
---|
35 | }
|
---|
36 |
|
---|
37 | if ($webvar{page} eq 'report') {
|
---|
38 | $page->param(ip => $webvar{ip});
|
---|
39 | for (my $i=0; $i<3; $i++) {
|
---|
40 | my ($block,$org) = $dnsbl->getcontainer($webvar{ip},$i);
|
---|
41 | if ($block) {
|
---|
42 | $page->param("block$i" => $block);
|
---|
43 | $page->param("org$i" => $org);
|
---|
44 | }
|
---|
45 | }
|
---|
46 | } elsif ($webvar{page} eq 'dbreport') {
|
---|
47 | my $count = $dnsbl->report($webvar{ip});
|
---|
48 | my $org0id = $dnsbl->orgexists($webvar{org0});
|
---|
49 | if (!$org0id) {
|
---|
50 | $org0id = $dnsbl->addorg($webvar{org0});
|
---|
51 | $page->param(org0 => $webvar{org0});
|
---|
52 | }
|
---|
53 | if (!$dnsbl->blockexists($webvar{block0})) {
|
---|
54 | $dnsbl->addblock($webvar{block0}, $org0id, 0);
|
---|
55 | $page->param(block0 => $webvar{block0});
|
---|
56 | }
|
---|
57 | # yes, this is grotty. PTHBTT!
|
---|
58 | if ($webvar{block1}) {
|
---|
59 | my $org1id = $dnsbl->orgexists($webvar{org1});
|
---|
60 | if (!$org1id) {
|
---|
61 | $org1id = $dnsbl->addorg($webvar{org1});
|
---|
62 | $page->param(org1 => $webvar{org1});
|
---|
63 | }
|
---|
64 | if (!$dnsbl->blockexists($webvar{block1})) {
|
---|
65 | $dnsbl->addblock($webvar{block1}, $org1id, 1);
|
---|
66 | $page->param(block1 => $webvar{block1});
|
---|
67 | }
|
---|
68 | if ($webvar{block2}) {
|
---|
69 | my $org2id = $dnsbl->orgexists($webvar{org2});
|
---|
70 | if (!$org2id) {
|
---|
71 | $org2id = $dnsbl->addorg($webvar{org2});
|
---|
72 | $page->param(org2 => $webvar{org2});
|
---|
73 | }
|
---|
74 | if (!$dnsbl->blockexists($webvar{block2})) {
|
---|
75 | $dnsbl->addblock($webvar{block2}, $org2id, 2);
|
---|
76 | $page->param(block2 => $webvar{block2});
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | $page->param(ip => $webvar{ip});
|
---|
82 | }
|
---|
83 | print $page->output;
|
---|