1 | #!/usr/bin/perl
|
---|
2 | # quickndirty browse-the-damned-by-web
|
---|
3 | ##
|
---|
4 | # $Id: browse.cgi 66 2018-01-05 23:06:47Z kdeugau $
|
---|
5 | # Copyright 2009-2011,2014 Kris Deugau <kdeugau@deepnet.cx>
|
---|
6 | #
|
---|
7 | # This program is free software: you can redistribute it and/or modify
|
---|
8 | # it under the terms of the GNU General Public License as published by
|
---|
9 | # the Free Software Foundation, either version 3 of the License, or
|
---|
10 | # (at your option) any later version.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ##
|
---|
20 |
|
---|
21 | use strict;
|
---|
22 | use warnings;
|
---|
23 | use DBI;
|
---|
24 | use CGI::Carp qw(fatalsToBrowser);
|
---|
25 | use HTML::Template;
|
---|
26 |
|
---|
27 | use DNSBL;
|
---|
28 | use DNSBLweb;
|
---|
29 |
|
---|
30 | my $dnsbl = new DNSBL;
|
---|
31 |
|
---|
32 | # default DB info - all other settings should be loaded from the DB.
|
---|
33 | my $dbhost = "localhost";
|
---|
34 | my $dbname = "dnsbl";
|
---|
35 | my $dbuser = "dnsbl";
|
---|
36 | my $dbpass = "spambgone";
|
---|
37 |
|
---|
38 | # Load a config ref containing DB host, name, user, and pass info based on
|
---|
39 | # from the server name + full script web path. This allows us to host
|
---|
40 | # multiple instances without having to duplicate the code.
|
---|
41 | # This file is a Perl fragment to be processed inline.
|
---|
42 | my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME};
|
---|
43 | $cfgname =~ s|[./-]|_|g;
|
---|
44 | $cfgname =~ s|_browse_cgi||;
|
---|
45 | if (-e "/etc/dnsbl/$cfgname.conf") {
|
---|
46 | my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
|
---|
47 | ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode
|
---|
48 | eval $cfg;
|
---|
49 | }
|
---|
50 |
|
---|
51 | my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
|
---|
52 |
|
---|
53 | print "Content-Type: text/html\n\n";
|
---|
54 |
|
---|
55 | my $templatedir = $ENV{SCRIPT_FILENAME};
|
---|
56 | $templatedir =~ s/browse\.cgi//;
|
---|
57 | $templatedir .= "templates";
|
---|
58 | $ENV{HTML_TEMPLATE_ROOT} = $templatedir;
|
---|
59 |
|
---|
60 | my %config;
|
---|
61 | my $sth = $dbh->prepare("SELECT key,value FROM misc");
|
---|
62 | $sth->execute;
|
---|
63 | while (my ($key,$value) = $sth->fetchrow_array) {
|
---|
64 | $config{$key} = $value;
|
---|
65 | }
|
---|
66 |
|
---|
67 | my $template = HTML::Template->new(filename => "browse.tmpl");
|
---|
68 |
|
---|
69 | $template->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle});
|
---|
70 | $template->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment});
|
---|
71 |
|
---|
72 | my $out = DNSBLweb::retlvl($dbh, $dnsbl, 0, block => '162.144.0.0/16');
|
---|
73 |
|
---|
74 | $template->param(enchilada => $out);
|
---|
75 | print $template->output;
|
---|