Changeset 25


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.

Location:
trunk/dnsbl
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r24 r25  
    100100sub DESTROY {
    101101  my $self = shift;
    102   $self->dbclose();
     102  $self->dbclose() if $dbh;
    103103}
    104104
     
    112112
    113113sub connect {
    114   my $DSN = "DBI:Pg:host=dbhost;dbname=dnsbl";
    115 #  my $DSN = "DBI:Pg:dbname=dnsbl";
    116   my $user = "dnsbl";
    117   my $pass = "spambgone";
     114  my $self = shift;
     115  my $dbhost = shift;
     116  my $dbname = shift;
     117  my $dbuser = shift;
     118  my $dbpass = shift;
    118119  ## want to NOT autocommit everything, it's unlikely we'll step on our own toes but...
    119   $dbh = DBI->connect($DSN, $user, $pass, {
     120  $dbh = DBI->connect("DBI:Pg:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, {
    120121        AutoCommit => 0,
    121122        PrintError => 1
  • trunk/dnsbl/browse.cgi

    r19 r25  
    1212my $dnsbl = new DNSBL;
    1313
    14 my $dbh = $dnsbl->connect;
     14# default DB info - all other settings should be loaded from the DB.
     15my $dbhost = "localhost";
     16my $dbname = "dnsbl";
     17my $dbuser = "dnsbl";
     18my $dbpass = "spambgone";
     19
     20# Load a config ref containing DB host, name, user, and pass info based on
     21# from the server name + full script web path.  This allows us to host
     22# multiple instances without having to duplicate the code.
     23# This file is a Perl fragment to be processed inline.
     24my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME};
     25$cfgname =~ s|[./-]|_|g;
     26$cfgname =~ s|_browse_cgi||;
     27if (-e "/etc/dnsbl/$cfgname.conf") {
     28  my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
     29  ($cfg) = ($cfg =~ /^(.+)$/s);                # avoid warnings, failures, and general nastiness with taint mode
     30  eval $cfg;
     31}
     32
     33my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    1534
    1635print "Content-Type: text/html\n\n";
    1736
    18 my @lvl0 = ("foo", "bar", "bax");
    19 my $template = HTML::Template->new(filename => 'templates/browse.tmpl');
     37my $templatedir = $ENV{SCRIPT_FILENAME};
     38$templatedir =~ s/browse\.cgi//;
     39$templatedir .= "templates";
     40$ENV{HTML_TEMPLATE_ROOT} = $templatedir;
     41
     42my %config;
     43my $sth = $dbh->prepare("SELECT key,value FROM misc");
     44$sth->execute;
     45while (my ($key,$value) = $sth->fetchrow_array) {
     46  $config{$key} = $value;
     47}
     48
     49my $template = HTML::Template->new(filename => "browse.tmpl");
     50
     51$template->param(pgtitle => $config{pgtitle}) if defined($config{pgtitle});
     52$template->param(pgcomment => $config{pgcomment}) if defined($config{pgcomment});
    2053
    2154my $basesql = "SELECT b.block,o.orgname,b.listme,o.listme,b.comments,o.comments ".
     
    2861my $sthiplist = $dbh->prepare("select * from iplist where ip <<= ? order by ip");
    2962
    30 print $template->output;
    31 
    3263my %ipseen;
    3364
     
    3667$sth0->execute;
    3768while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {
    38   my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     69  my $tmpl0 = new HTML::Template(filename => "browse-block.tmpl");
    3970  $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : ''));
    4071  $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));
     
    4879  if ($sth1->rows > 0) {
    4980    while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {
    50       my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     81      my $tmpl1 = new HTML::Template(filename => "browse-block.tmpl");
    5182      $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : ''));
    5283      $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));
     
    6192      if ($sth2->rows > 0) {
    6293        while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
    63           my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');
     94          my $tmpl2 = new HTML::Template(filename => "browse-block.tmpl");
    6495          $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : ''));
    6596          $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));
     
    120151}
    121152
    122 print $out;
     153# probably more efficient ways to do this somewhere...
     154$template->param(enchilada => $out);
     155print $template->output;
  • trunk/dnsbl/check-iplist.pl

    r2 r25  
    99my $dnsbl = new DNSBL;
    1010
    11 my $dbh = $dnsbl->connect;
     11# default DB info - all other settings should be loaded from the DB.
     12my $dbhost = "localhost";
     13my $dbname = "dnsbl";
     14my $dbuser = "dnsbl";
     15my $dbpass = "spambgone";
     16
     17die "Need config argument\n" if !$ARGV[0];
     18my $cfgname = shift @ARGV;
     19
     20# Load a config ref containing DB host, name, user, and pass info based on
     21# from the server name + full script web path.  This allows us to host
     22# multiple instances without having to duplicate the code.
     23# This file is a Perl fragment to be processed inline.
     24if (-e "/etc/dnsbl/$cfgname.conf") {
     25  my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
     26  ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
     27  eval $cfg;
     28}
     29
     30my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    1231
    1332print "checking IP containment...\n";
  • 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
  • trunk/dnsbl/dnsbl.sql

    r2 r25  
    55SET client_encoding = 'UTF8';
    66SET check_function_bodies = false;
    7 SET client_min_messages = warning;
    87
    98--
    10 -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
    11 --
    12 
    13 COMMENT ON SCHEMA public IS 'Standard public schema';
    14 
    15 
    16 SET search_path = public, pg_catalog;
    17 
    18 SET default_tablespace = '';
    19 
    20 SET default_with_oids = false;
    21 
    22 --
    23 -- Name: blocks; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace:
     9-- TOC entry 7 (OID 196077)
     10-- Name: blocks; Type: TABLE; Schema: public; Owner: dnsbl
    2411--
    2512
     
    3421
    3522--
    36 -- Name: iplist; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace:
     23-- TOC entry 8 (OID 196085)
     24-- Name: iplist; Type: TABLE; Schema: public; Owner: dnsbl
    3725--
    3826
     
    4634
    4735--
    48 -- Name: orgs; Type: TABLE; Schema: public; Owner: dnsbl; Tablespace:
     36-- TOC entry 9 (OID 196090)
     37-- Name: orgs; Type: TABLE; Schema: public; Owner: dnsbl
    4938--
    5039
     
    5847
    5948--
    60 -- Name: blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace:
     49-- TOC entry 10 (OID 196099)
     50-- Name: autolist; Type: TABLE; Schema: public; Owner: dnsbl
     51--
     52
     53CREATE TABLE autolist (
     54    masklen smallint NOT NULL,
     55    ipcount bigint
     56);
     57
     58
     59--
     60-- TOC entry 11 (OID 196147)
     61-- Name: misc; Type: TABLE; Schema: public; Owner: dnsbl
     62--
     63
     64CREATE TABLE misc (
     65    "key" character varying(30),
     66    value character varying(255)
     67);
     68
     69
     70--
     71-- Data for TOC entry 23 (OID 196099)
     72-- Name: autolist; Type: TABLE DATA; Schema: public; Owner: dnsbl
     73--
     74
     75COPY autolist (masklen, ipcount) FROM stdin;
     7631      1
     7730      1
     7829      2
     7928      3
     8027      4
     8126      5
     8225      6
     8324      7
     8423      8
     8522      10
     8621      13
     8720      16
     8819      19
     8918      22
     9017      26
     9116      30
     9215      34
     9314      38
     9413      42
     9512      46
     9611      50
     9710      54
     989       58
     998       62
     1007       2147483648
     1016       2147483648
     1025       2147483648
     1034       2147483648
     1043       2147483648
     1052       2147483648
     1061       2147483648
     1070       2147483648
     108\.
     109
     110
     111--
     112-- TOC entry 12 (OID 196101)
     113-- Name: blocks_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl
    61114--
    62115
     
    66119
    67120--
    68 -- Name: iplist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace:
     121-- TOC entry 13 (OID 196103)
     122-- Name: iplist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl
    69123--
    70124
     
    74128
    75129--
    76 -- Name: orgs_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl; Tablespace:
     130-- TOC entry 14 (OID 196105)
     131-- Name: orgs_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl
    77132--
    78133
     
    82137
    83138--
     139-- TOC entry 15 (OID 196215)
     140-- Name: autolist_pkey; Type: CONSTRAINT; Schema: public; Owner: dnsbl
     141--
     142
     143ALTER TABLE ONLY autolist
     144    ADD CONSTRAINT autolist_pkey PRIMARY KEY (masklen);
     145
     146
     147--
     148-- TOC entry 25 (OID 196107)
    84149-- Name: blocks_orgid_fkey; Type: FK CONSTRAINT; Schema: public; Owner: dnsbl
    85150--
     
    88153    ADD CONSTRAINT blocks_orgid_fkey FOREIGN KEY (orgid) REFERENCES orgs(orgid);
    89154
    90 
    91 --
    92 -- Name: public; Type: ACL; Schema: -; Owner: postgres
    93 --
    94 
    95 REVOKE ALL ON SCHEMA public FROM PUBLIC;
    96 REVOKE ALL ON SCHEMA public FROM postgres;
    97 GRANT ALL ON SCHEMA public TO postgres;
    98 GRANT ALL ON SCHEMA public TO PUBLIC;
    99 
    100 
    101 --
    102 -- PostgreSQL database dump complete
    103 --
    104 
  • trunk/dnsbl/export-dnsbl

    r23 r25  
    1414my $dnsbl = new DNSBL;
    1515
    16 $dnsbl->connect;
     16# default DB info - all other settings should be loaded from the DB.
     17my $dbhost = "localhost";
     18my $dbname = "dnsbl";
     19my $dbuser = "dnsbl";
     20my $dbpass = "spambgone";
     21
     22die "Need config argument\n" if !$ARGV[0];
     23my $cfgname = shift @ARGV;
     24
     25# Load a config ref containing DB host, name, user, and pass info based on
     26# from the server name + full script web path.  This allows us to host
     27# multiple instances without having to duplicate the code.
     28# This file is a Perl fragment to be processed inline.
     29if (-e "/etc/dnsbl/$cfgname.conf") {
     30  my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
     31  ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
     32  eval $cfg;
     33}
     34
     35my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    1736
    1837my %iplist;
  • trunk/dnsbl/orgmove

    r2 r25  
    1010my $dnsbl = new DNSBL;
    1111
    12 my $dbh = $dnsbl->connect;
     12# default DB info - all other settings should be loaded from the DB.
     13my $dbhost = "localhost";
     14my $dbname = "dnsbl";
     15my $dbuser = "dnsbl";
     16my $dbpass = "spambgone";
     17
     18die "Usage: orgmove <config name> <old orgid> <new orgid>\n" if !$ARGV[2];
     19my $cfgname = shift @ARGV;
     20
     21# Load a config ref containing DB host, name, user, and pass info based on
     22# from the server name + full script web path.  This allows us to host
     23# multiple instances without having to duplicate the code.
     24# This file is a Perl fragment to be processed inline.
     25if (-e "/etc/dnsbl/$cfgname.conf") {
     26  my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
     27  ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
     28  eval $cfg;
     29}
     30
     31my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
    1332
    1433$dbh->{AutoCommit} = 0;
  • trunk/dnsbl/templates/browse.tmpl

    r7 r25  
    1 <html><head><title>show all IPs and listing status</title>
     1<html>
     2<head>
     3<title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF> - show all IPs and listing status</title>
    24<link rel="stylesheet" type="text/css" href="templates/dnsbl.css" />
    35</head>
    46<body>
     7<TMPL_VAR NAME=pgcomment>
     8<TMPL_VAR NAME=enchilada>
     9</body>
     10</html>
  • trunk/dnsbl/templates/dbreport.tmpl

    r22 r25  
    11<html>
    22<head>
    3 <title>added <TMPL_VAR NAME=ip></title>
     3<title><TMPL_IF pgtitle><TMPL_VAR NAME=pgtitle><TMPL_ELSE>DNSBL Database</TMPL_IF> - added <TMPL_VAR NAME=ip></title>
    44<link rel="stylesheet" type="text/css" href="templates/dnsbl.css" />
    55</head>
    66<body>
     7<TMPL_VAR NAME=pgcomment>
    78<table><tr><td valign=top>
    89added <TMPL_VAR NAME=ip>
  • trunk/dnsbl/templates/index.tmpl

    r22 r25  
    11<html>
    22<head>
    3 <title>DNSBL database</title>
     3<title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF></title>
    44</head>
    55<body>
     6<TMPL_VAR NAME=pgcomment>
    67<table>
    78<form action="dnsbl.cgi"><input type=hidden name=page value=report>
  • trunk/dnsbl/templates/report.tmpl

    r17 r25  
    11<html>
    22<head>
    3 <title>adding <TMPL_VAR NAME=ip></title>
     3<title><TMPL_IF pgtitle><TMPL_VAR pgtitle><TMPL_ELSE>DNSBL database</TMPL_IF> - adding <TMPL_VAR NAME=ip></title>
    44<link rel="stylesheet" type="text/css" href="templates/dnsbl.css" />
    55</head>
    66<body>
     7<TMPL_VAR NAME=pgcomment>
    78<table><tr><td valign=top>
    89<table border=1><tr><td>
Note: See TracChangeset for help on using the changeset viewer.