Changeset 25 for trunk/dnsbl/dnsbl.cgi


Ignore:
Timestamp:
09/03/10 15:18:51 (14 years ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

Changes across the board to support multi-instance without code changes.
DB config is now loaded from a fragment in /etc/dnsbl, and the DB in turn
contains the autolist thresholds and some visual sugar for the web
interface so you know which DB you're dealing with.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/dnsbl.cgi

    r24 r25  
    2424print "Content-type: text/html\n\n";
    2525
    26 my $dbh = $dnsbl->connect;
     26# default DB info - all other settings should be loaded from the DB.
     27my $dbhost = "localhost";
     28my $dbname = "dnsbl";
     29my $dbuser = "dnsbl";
     30my $dbpass = "spambgone";
     31
     32# Load a config ref containing DB host, name, user, and pass info based on
     33# from the server name + full script web path.  This allows us to host
     34# multiple instances without having to duplicate the code.
     35# This file is a Perl fragment to be processed inline.
     36my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME};
     37$cfgname =~ s|[./-]|_|g;
     38$cfgname =~ s|_dnsbl_cgi||;
     39if (-e "/etc/dnsbl/$cfgname.conf") {
     40  my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
     41  ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
     42  eval $cfg;
     43}
     44
     45my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    2746
    2847my $page;
    29 my $templatedir = "templates";
     48my $templatedir = $ENV{SCRIPT_FILENAME};
     49$templatedir =~ s/dnsbl\.cgi//;
     50$templatedir .= "templates";
     51$ENV{HTML_TEMPLATE_ROOT} = $templatedir;
     52
     53my %config;
     54my $sth = $dbh->prepare("SELECT key,value FROM misc");
     55$sth->execute;
     56while (my ($key,$value) = $sth->fetchrow_array) {
     57  $config{$key} = $value;
     58}
    3059
    3160# decide which page to spit out...
    3261if (!$webvar{page}) {
    33   $page = HTML::Template->new(filename => "$templatedir/index.tmpl");
     62  $page = HTML::Template->new(filename => "index.tmpl");
    3463} else {
    35   $page = HTML::Template->new(filename => "$templatedir/$webvar{page}.tmpl");
    36 }
     64  $page = HTML::Template->new(filename => "$webvar{page}.tmpl");
     65}
     66
     67$page->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle});
     68$page->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment});
    3769
    3870if ($webvar{page} eq 'report') {
     
    92124  $page->param(browsebits => browse($dbh,$webvar{ip}));
    93125}
     126
    94127print $page->output;
    95128
Note: See TracChangeset for help on using the changeset viewer.