Changeset 73


Ignore:
Timestamp:
09/05/25 16:04:46 (9 days ago)
Author:
Kris Deugau
Message:

/trunk/dnsbl

The "begin the cleanup from production" cleanup commit

  • Move default DB connect info into DNSBL.pm
  • Move configuration fragment loading into DNSBL.pm
  • Change up configuration fragment to use %siteconfig instead of individual variables
  • Normalize parts of locating the module to at least a "good enough" level
  • if(0) out a chunk of export-dnsbl

Some things may be broken.

Location:
trunk/dnsbl
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/dnsbl/DNSBL.pm

    r72 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2424use warnings;
    2525use Exporter;
     26
    2627use DBI;
    2728use NetAddr::IP;
     
    2930use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
    3031
    31 $VERSION        = 2.2;
     32$VERSION        = 3.0;
    3233@ISA            = qw(Exporter);
    33 @EXPORT_OK      = qw(
    34         );
    35 
    36 @EXPORT         = (); # Export nothing by default.
     34@EXPORT_OK      = qw( $dbh );
     35
     36@EXPORT         = qw( $dbh );
    3737%EXPORT_TAGS    = ( ALL => [qw(
    3838                )]
     
    134134# basic object subs
    135135sub new {
    136 # iff we want to start taking arguments, or doing other things on instantiation
    137 #  my $self = {};
    138 #  bless $self, "DNSBL";
    139 #  return $self;
    140   bless {};
    141 }
     136  my $this = shift;
     137  my $class = ref($this) || $this;
     138  my %args = @_;
     139
     140  # Prepopulate a basic config.  Note some of these *will* cause errors if left unset.
     141  my %defconfig = (
     142        dbhost => "localhost",
     143        dbname => "dnsbl",
     144        dbuser => "dnsbl",
     145        dbpass => "spambgone",
     146  );
     147
     148  my %siteconfig;
     149  my $dbhost;
     150  my $dbname;
     151  my $dbuser;
     152  my $dbpass;
     153  if (defined($args{configfile})) {
     154    if (-e $args{configfile} && -f $args{configfile}) {
     155      my $ret = eval `cat $args{configfile}`;
     156      unless ($ret) {
     157        if ($@) { $errstr = "couldn't parse $args{configfile}: $@\n"; return; }
     158        if (!defined($ret)) { $errstr = "couldn't load $args{configfile}: $!\n"; return; }
     159        if (!$ret) { $errstr = "couldn't load $args{configfile}\n"; return; }
     160      }
     161      # crossload legacy variables, but prefer new %siteconfig values
     162      $siteconfig{dbhost} = $dbhost if !$siteconfig{dbhost} && $dbhost;
     163      $siteconfig{dbname} = $dbname if !$siteconfig{dbname} && $dbname;
     164      $siteconfig{dbuser} = $dbuser if !$siteconfig{dbuser} && $dbuser;
     165      $siteconfig{dbpass} = $dbpass if !$siteconfig{dbpass} && $dbpass;
     166    }
     167  }
     168
     169  # Assemble the object.  Apply configuration hashes in order of precedence.
     170  my $self = {
     171        # Hardcoded defaults
     172        %defconfig,
     173        # Default config file OR caller-specified one, loaded above
     174        %siteconfig,
     175        # Caller-specified arguments
     176        %args
     177        };
     178  bless $self, $class;
     179
     180  return $self;
     181} # new()
    142182
    143183sub DESTROY {
     
    156196sub connect {
    157197  my $self = shift;
    158   my $dbhost = shift;
    159   my $dbname = shift;
    160   my $dbuser = shift;
    161   my $dbpass = shift;
    162198  ## want to NOT autocommit everything, it's unlikely we'll step on our own toes but...
    163   $dbh = DBI->connect("DBI:Pg:host=$dbhost;dbname=$dbname", $dbuser, $dbpass, {
     199  $dbh = DBI->connect("DBI:Pg:host=$self->{dbhost};dbname=$self->{dbname}", $self->{dbuser}, $self->{dbpass}, {
    164200        AutoCommit => 0,
    165201        PrintError => 1
  • trunk/dnsbl/browse.cgi

    r69 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    3030use lib "$FindBin::RealBin/";
    3131
    32 use DNSBL 2.2;
     32use DNSBL 3.0;
    3333use DNSBLweb;
    34 
    35 my $dnsbl = new DNSBL;
    36 
    37 # default DB info - all other settings should be loaded from the DB.
    38 my $dbhost = "localhost";
    39 my $dbname = "dnsbl";
    40 my $dbuser = "dnsbl";
    41 my $dbpass = "spambgone";
    42 
    43 # Load a config ref containing DB host, name, user, and pass info based on
    44 # from the server name + full script web path.  This allows us to host
    45 # multiple instances without having to duplicate the code.
    46 # This file is a Perl fragment to be processed inline.
    47 my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME};
    48 $cfgname =~ s|[./-]|_|g;
    49 $cfgname =~ s|_browse_cgi||;
    50 if (-e "/etc/dnsbl/$cfgname.conf") {
    51   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    52   ($cfg) = ($cfg =~ /^(.+)$/s);                # avoid warnings, failures, and general nastiness with taint mode
    53   eval $cfg;
    54 }
    5534
    5635# Set up the CGI object...
     
    6948print $q->header(-charset=>'utf8');
    7049
    71 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     50# Load a config ref containing DB host, name, user, and pass info based on
     51# from the server name + full script web path.  This allows us to host
     52# multiple instances without having to duplicate the code.
     53# This file is a Perl fragment to be processed inline.
     54my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME};
     55$cfgname =~ s|[./-]|_|g;
     56$cfgname =~ s|_browse_cgi||;
     57$cfgname =~ s|_$||;
     58
     59my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     60$dnsbl->connect;
    7261
    7362my $block = '';
  • trunk/dnsbl/check-iplist.pl

    r40 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2011,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2323use DBI;
    2424
    25 use DNSBL;
     25# push "the directory the script is in" into @INC
     26use FindBin;
     27use lib "$FindBin::RealBin/";
    2628
    27 my $dnsbl = new DNSBL;
    28 
    29 # default DB info - all other settings should be loaded from the DB.
    30 my $dbhost = "localhost";
    31 my $dbname = "dnsbl";
    32 my $dbuser = "dnsbl";
    33 my $dbpass = "spambgone";
     29use DNSBL 3.0;
    3430
    3531die "Need config argument\n" if !$ARGV[0];
    3632my $cfgname = shift @ARGV;
    3733
    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 if (-e "/etc/dnsbl/$cfgname.conf") {
    43   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    44   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    45   eval $cfg;
    46 }
    47 
    48 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     34my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     35$dnsbl->connect;
    4936
    5037print "checking IP containment...\n";
     
    8370  print "$data[0] has no IPs\n" if $cksth->rows == 0;
    8471}
    85 
  • trunk/dnsbl/delist-ip

    r67 r73  
    33##
    44# $Id$
    5 # Copyright 2011, 2012, 2018 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2011,2012,2018,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2323use DBI;
    2424
    25 use DNSBL 2.2;
     25# push "the directory the script is in" into @INC
     26use FindBin;
     27use lib "$FindBin::RealBin/";
    2628
    27 my $dnsbl = new DNSBL;
    28 
    29 # default DB info - all other settings should be loaded from the DB.
    30 my $dbhost = "localhost";
    31 my $dbname = "dnsbl";
    32 my $dbuser = "dnsbl";
    33 my $dbpass = "spambgone";
     29use DNSBL 3.0;
    3430
    3531die "Usage: delist-ip <list> <IP>\n".
     
    3834my $cfgname = shift @ARGV;
    3935
    40 # Load a config ref containing DB host, name, user, and pass info based on
    41 # from the server name + full script web path.  This allows us to host
    42 # multiple instances without having to duplicate the code.
    43 # This file is a Perl fragment to be processed inline.
    44 if (-e "/etc/dnsbl/$cfgname.conf") {
    45   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    46   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    47   eval $cfg;
    48 }
    49 
    50 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     36my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     37$dnsbl->connect;
    5138
    5239my %config;
  • trunk/dnsbl/dnsbl.cgi

    r69 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2012,2014,2015,2017,2018 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2012,2014,2015,2017,2018,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2222use warnings;
    2323no warnings qw(uninitialized);
     24
    2425use CGI::Carp qw (fatalsToBrowser);
    2526use CGI::Simple;
     
    3132use lib "$FindBin::RealBin/";
    3233
    33 use DNSBL 2.2;
     34use DNSBL 3.0;
    3435use DNSBLweb;
    3536
     
    5354# difference from RH<->Debian is still at fault.
    5455print $q->header(-charset=>'utf8');
    55 
    56 # default DB info - all other settings should be loaded from the DB.
    57 my $dbhost = "localhost";
    58 my $dbname = "dnsbl";
    59 my $dbuser = "dnsbl";
    60 my $dbpass = "spambgone";
    6156
    6257# Load a config ref containing DB host, name, user, and pass info based on
     
    6863$cfgname =~ s|_dnsbl_cgi.*||;
    6964$cfgname =~ s|_$||;
    70 if (-e "/etc/dnsbl/$cfgname.conf") {
    71   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    72   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    73   eval $cfg;
    74 }
    75 
    76 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     65
     66my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     67$dnsbl->connect;
    7768
    7869my $page;
  • trunk/dnsbl/export-dnsbl

    r69 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2727use lib "$FindBin::RealBin/";
    2828
    29 use DNSBL 2.2;
    30 
    31 my $dnsbl = new DNSBL;
    32 
    33 # default DB info - all other settings should be loaded from the DB.
    34 my $dbhost = "localhost";
    35 my $dbname = "dnsbl";
    36 my $dbuser = "dnsbl";
    37 my $dbpass = "spambgone";
     29use DNSBL 3.0;
    3830
    3931die "Need config argument\n" if !$ARGV[0];
    4032my $cfgname = shift @ARGV;
    4133
    42 # Load a config ref containing DB host, name, user, and pass info based on
    43 # from the server name + full script web path.  This allows us to host
    44 # multiple instances without having to duplicate the code.
    45 # This file is a Perl fragment to be processed inline.
    46 if (-e "/etc/dnsbl/$cfgname.conf") {
    47   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    48   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    49   eval $cfg;
    50 }
    51 
    52 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     34my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     35$dnsbl->connect;
    5336
    5437my %config;
     
    6144my %iplist;
    6245my $ipref = \%iplist;
     46my @iplist2;
     47my $ipref2 = \@iplist2;
    6348
    6449my $mode = $ARGV[0] || 'tiny';
     
    6651$dnsbl->initexport;
    6752#$dnsbl->export($ipref,$mode,1,'50.22.0.0/15');
    68 $dnsbl->export($ipref,$mode);
     53#$dnsbl->export($ipref,$mode);
     54$dnsbl->export_alt($ipref2, $mode);
     55
    6956
    7057##fixme - mode should pick actual output, not just export mode
     
    7764
    7865  # more or less raw CIDR block-and-IP info.  rbldnsd format for convenience.
    79   foreach (sort ipcmp keys %iplist) {
     66
     67
     68
     69if (0) {
     70#  foreach (sort ipcmp keys %iplist) {
     71  foreach (keys %iplist) {
    8072    my $entry;
    8173    if ($iplist{$_} == -1) {
     
    10496    print $out;
    10597  }
     98}
     99
     100
    106101} else {
    107102  # default "mode";  tinyDNS data format
  • trunk/dnsbl/orgmove

    r40 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2010 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2010,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2323use DBI;
    2424
    25 use DNSBL;
     25# push "the directory the script is in" into @INC
     26use FindBin;
     27use lib "$FindBin::RealBin/";
    2628
    27 my $dnsbl = new DNSBL;
    28 
    29 # default DB info - all other settings should be loaded from the DB.
    30 my $dbhost = "localhost";
    31 my $dbname = "dnsbl";
    32 my $dbuser = "dnsbl";
    33 my $dbpass = "spambgone";
     29use DNSBL 3.0;
    3430
    3531die "Usage: orgmove <config name> <old orgid> <new orgid>\n" if !$ARGV[2];
    3632my $cfgname = shift @ARGV;
    3733
    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 if (-e "/etc/dnsbl/$cfgname.conf") {
    43   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    44   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    45   eval $cfg;
    46 }
    47 
    48 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     34my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     35$dnsbl->connect;
    4936
    5037$dbh->{AutoCommit} = 0;
  • trunk/dnsbl/setparents.pl

    r40 r73  
    33##
    44# $Id$
    5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>
     5# Copyright 2009-2011,2025 Kris Deugau <kdeugau@deepnet.cx>
    66#
    77#    This program is free software: you can redistribute it and/or modify
     
    2323use DBI;
    2424
    25 use DNSBL;
     25# push "the directory the script is in" into @INC
     26use FindBin;
     27use lib "$FindBin::RealBin/";
    2628
    27 my $dnsbl = new DNSBL;
    28 
    29 # default DB info - all other settings should be loaded from the DB.
    30 my $dbhost = "dbhost";
    31 my $dbname = "dnsbl";
    32 my $dbuser = "dnsbl";
    33 my $dbpass = "spambgone";
     29use DNSBL 3.0;
    3430
    3531die "Need config argument\n" if !$ARGV[0];
    3632my $cfgname = shift @ARGV;
    3733
    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 if (-e "/etc/dnsbl/$cfgname.conf") {
    43   my $cfg = `cat /etc/dnsbl/$cfgname.conf`;
    44   ($cfg) = ($cfg =~ /^(.+)$/s);         # avoid warnings, failures, and general nastiness with taint mode
    45   eval $cfg;
    46 }
    47 
    48 my $dbh = $dnsbl->connect($dbhost, $dbname, $dbuser, $dbpass);
     34my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf");
     35$dnsbl->connect;
    4936
    5037print "block parents\n";
Note: See TracChangeset for help on using the changeset viewer.