Changeset 73
- Timestamp:
- 09/05/25 16:04:46 (9 days ago)
- Location:
- trunk/dnsbl
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/dnsbl/DNSBL.pm
r72 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 24 24 use warnings; 25 25 use Exporter; 26 26 27 use DBI; 27 28 use NetAddr::IP; … … 29 30 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 30 31 31 $VERSION = 2.2;32 $VERSION = 3.0; 32 33 @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 ); 37 37 %EXPORT_TAGS = ( ALL => [qw( 38 38 )] … … 134 134 # basic object subs 135 135 sub 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() 142 182 143 183 sub DESTROY { … … 156 196 sub connect { 157 197 my $self = shift; 158 my $dbhost = shift;159 my $dbname = shift;160 my $dbuser = shift;161 my $dbpass = shift;162 198 ## 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}, { 164 200 AutoCommit => 0, 165 201 PrintError => 1 -
trunk/dnsbl/browse.cgi
r69 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 30 30 use lib "$FindBin::RealBin/"; 31 31 32 use DNSBL 2.2;32 use DNSBL 3.0; 33 33 use 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 on44 # from the server name + full script web path. This allows us to host45 # 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 mode53 eval $cfg;54 }55 34 56 35 # Set up the CGI object... … … 69 48 print $q->header(-charset=>'utf8'); 70 49 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. 54 my $cfgname = $ENV{SERVER_NAME}.$ENV{SCRIPT_NAME}; 55 $cfgname =~ s|[./-]|_|g; 56 $cfgname =~ s|_browse_cgi||; 57 $cfgname =~ s|_$||; 58 59 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 60 $dnsbl->connect; 72 61 73 62 my $block = ''; -
trunk/dnsbl/check-iplist.pl
r40 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2011,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 23 23 use DBI; 24 24 25 use DNSBL; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 26 28 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"; 29 use DNSBL 3.0; 34 30 35 31 die "Need config argument\n" if !$ARGV[0]; 36 32 my $cfgname = shift @ARGV; 37 33 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); 34 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 35 $dnsbl->connect; 49 36 50 37 print "checking IP containment...\n"; … … 83 70 print "$data[0] has no IPs\n" if $cksth->rows == 0; 84 71 } 85 -
trunk/dnsbl/delist-ip
r67 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2011, 2012, 2018Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2011,2012,2018,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 23 23 use DBI; 24 24 25 use DNSBL 2.2; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 26 28 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"; 29 use DNSBL 3.0; 34 30 35 31 die "Usage: delist-ip <list> <IP>\n". … … 38 34 my $cfgname = shift @ARGV; 39 35 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); 36 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 37 $dnsbl->connect; 51 38 52 39 my %config; -
trunk/dnsbl/dnsbl.cgi
r69 r73 3 3 ## 4 4 # $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> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 22 22 use warnings; 23 23 no warnings qw(uninitialized); 24 24 25 use CGI::Carp qw (fatalsToBrowser); 25 26 use CGI::Simple; … … 31 32 use lib "$FindBin::RealBin/"; 32 33 33 use DNSBL 2.2;34 use DNSBL 3.0; 34 35 use DNSBLweb; 35 36 … … 53 54 # difference from RH<->Debian is still at fault. 54 55 print $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";61 56 62 57 # Load a config ref containing DB host, name, user, and pass info based on … … 68 63 $cfgname =~ s|_dnsbl_cgi.*||; 69 64 $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 66 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 67 $dnsbl->connect; 77 68 78 69 my $page; -
trunk/dnsbl/export-dnsbl
r69 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2012,2014,2018 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2012,2014,2018,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 27 27 use lib "$FindBin::RealBin/"; 28 28 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"; 29 use DNSBL 3.0; 38 30 39 31 die "Need config argument\n" if !$ARGV[0]; 40 32 my $cfgname = shift @ARGV; 41 33 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); 34 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 35 $dnsbl->connect; 53 36 54 37 my %config; … … 61 44 my %iplist; 62 45 my $ipref = \%iplist; 46 my @iplist2; 47 my $ipref2 = \@iplist2; 63 48 64 49 my $mode = $ARGV[0] || 'tiny'; … … 66 51 $dnsbl->initexport; 67 52 #$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 69 56 70 57 ##fixme - mode should pick actual output, not just export mode … … 77 64 78 65 # more or less raw CIDR block-and-IP info. rbldnsd format for convenience. 79 foreach (sort ipcmp keys %iplist) { 66 67 68 69 if (0) { 70 # foreach (sort ipcmp keys %iplist) { 71 foreach (keys %iplist) { 80 72 my $entry; 81 73 if ($iplist{$_} == -1) { … … 104 96 print $out; 105 97 } 98 } 99 100 106 101 } else { 107 102 # default "mode"; tinyDNS data format -
trunk/dnsbl/orgmove
r40 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2010 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2010,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 23 23 use DBI; 24 24 25 use DNSBL; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 26 28 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"; 29 use DNSBL 3.0; 34 30 35 31 die "Usage: orgmove <config name> <old orgid> <new orgid>\n" if !$ARGV[2]; 36 32 my $cfgname = shift @ARGV; 37 33 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); 34 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 35 $dnsbl->connect; 49 36 50 37 $dbh->{AutoCommit} = 0; -
trunk/dnsbl/setparents.pl
r40 r73 3 3 ## 4 4 # $Id$ 5 # Copyright 2009-2011 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2009-2011,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 23 23 use DBI; 24 24 25 use DNSBL; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 26 28 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"; 29 use DNSBL 3.0; 34 30 35 31 die "Need config argument\n" if !$ARGV[0]; 36 32 my $cfgname = shift @ARGV; 37 33 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); 34 my $dnsbl = new DNSBL (configfile => "/etc/dnsbl/$cfgname.conf"); 35 $dnsbl->connect; 49 36 50 37 print "block parents\n";
Note:
See TracChangeset
for help on using the changeset viewer.