Changeset 80
- Timestamp:
- 09/11/25 16:28:23 (3 days ago)
- Location:
- trunk/uribl
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/uribl/URIdb.pm
r41 r80 3 3 ## 4 4 # $Id$ 5 # Copyright 2010 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2010,2025 Kris Deugau <kdeugau@deepnet.cx> 6 6 # 7 7 # This program is free software: you can redistribute it and/or modify … … 29 29 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 30 30 31 $VERSION = 1.0;31 $VERSION = 2.0; 32 32 @ISA = qw(Exporter); 33 @EXPORT_OK = qw( 34 ); 35 36 @EXPORT = (); # Export nothing by default. 33 @EXPORT_OK = qw( $dbh ); 34 35 @EXPORT = ( $dbh ); 36 37 37 %EXPORT_TAGS = ( ALL => [qw( 38 38 )] … … 60 60 # basic object subs 61 61 sub new { 62 # iff we want to start taking arguments, or doing other things on instantiation 63 # my $self = {}; 64 # bless $self, "DNSBL"; 65 # return $self; 66 bless {}; 62 my $this = shift; 63 my $class = ref($this) || $this; 64 my %args = @_; 65 66 # Prepopulate a basic config. Note some of these *will* cause errors if left unset. 67 my %defconfig = ( 68 dbhost => "localhost", 69 dbname => "dnsbl", 70 dbuser => "dnsbl", 71 dbpass => "spambgone", 72 ); 73 74 my %siteconfig; 75 my $dbhost; 76 my $dbname; 77 my $dbuser; 78 my $dbpass; 79 if (defined($args{configfile})) { 80 if (-e $args{configfile} && -f $args{configfile}) { 81 my $ret = eval `cat $args{configfile}`; 82 unless ($ret) { 83 if ($@) { $errstr = "couldn't parse $args{configfile}: $@\n"; return; } 84 if (!defined($ret)) { $errstr = "couldn't load $args{configfile}: $!\n"; return; } 85 if (!$ret) { $errstr = "couldn't load $args{configfile}\n"; return; } 86 } 87 # crossload legacy variables, but prefer new %siteconfig values 88 $siteconfig{dbhost} = $dbhost if !$siteconfig{dbhost} && $dbhost; 89 $siteconfig{dbname} = $dbname if !$siteconfig{dbname} && $dbname; 90 $siteconfig{dbuser} = $dbuser if !$siteconfig{dbuser} && $dbuser; 91 $siteconfig{dbpass} = $dbpass if !$siteconfig{dbpass} && $dbpass; 92 } 93 } 94 95 # Assemble the object. Apply configuration hashes in order of precedence. 96 my $self = { 97 # Hardcoded defaults 98 %defconfig, 99 # Default config file OR caller-specified one, loaded above 100 %siteconfig, 101 # Caller-specified arguments 102 %args 103 }; 104 bless $self, $class; 105 106 return $self; 67 107 } 68 108 … … 82 122 sub connect { 83 123 my $self = shift; 84 my $dbhost = shift;85 my $dbname = shift;86 my $dbuser = shift;87 my $dbpass = shift;88 124 ## want to NOT autocommit everything, it's unlikely we'll step on our own toes but... 89 $dbh = DBI->connect("DBI:Pg:host=$ dbhost;dbname=$dbname", $dbuser, $dbpass, {125 $dbh = DBI->connect("DBI:Pg:host=$self->{dbhost};dbname=$self->{dbname}", $self->{dbuser}, $self->{dbpass}, { 90 126 AutoCommit => 0, 91 127 PrintError => 1 -
trunk/uribl/delist-uri
r41 r80 3 3 ## 4 4 # $Id$ 5 # Copyright 2010 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 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 URIdb; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 28 29 use URIdb 2.0; 26 30 27 31 my $uridb = new URIdb; 28 32 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"; 33 die "Usage: delist-uri <domain>\n" 34 if !$ARGV[1]; 34 35 35 die "Usage: delist-uri <domain>\n" 36 if !$ARGV[0]; 36 my $cfgname = shift @ARGV; 37 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 if (-e "/etc/uridb/uridb.conf") { 43 my $cfg = `cat /etc/uridb/uridb.conf`; 44 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 45 eval $cfg; 46 } 47 48 my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass); 38 my $uridb = new URIdb (configfile => "/etc/uridb/$cfgname.conf"); 39 $uridb->connect; 49 40 50 41 my %config; -
trunk/uribl/export-uridb
r41 r80 3 3 ## 4 4 # $Id$ 5 # Copyright 2010 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 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 URIdb; 25 # push "the directory the script is in" into @INC 26 use FindBin; 27 use lib "$FindBin::RealBin/"; 28 29 use URIdb 2.0; 26 30 27 31 my $uridb = new URIdb; 28 32 29 # default DB info - all other settings should be loaded from the DB. 30 my $dbhost = "localhost"; 31 my $dbname = "uridb"; 32 my $dbuser = "uridb"; 33 my $dbpass = "spambgone"; 33 die "Usage: export-uridb <list> [type]\n" 34 if !$ARGV[0]; 34 35 35 warn "Need DNS data type argument\n" if !$ARGV[0]; 36 my $cfgname = shift @ARGV; 37 38 warn "Missing DNS data type argument, defaulting to rbldnsd\n" if !$ARGV[0]; 36 39 my $mode = shift @ARGV || 'rbldnsd'; 37 40 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/uridb/uridb.conf") { 43 my $cfg = `cat /etc/uridb/uridb.conf`; 44 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode 45 eval $cfg; 46 } 47 48 my $dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass); 41 my $uridb = new URIdb (configfile => "/etc/uridb/$cfgname.conf"); 42 $uridb->connect; 49 43 50 44 my %config; -
trunk/uribl/uridb.cgi
r62 r80 3 3 ## 4 4 # $Id$ 5 # Copyright 2010 Kris Deugau <kdeugau@deepnet.cx>5 # Copyright 2010,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; … … 27 28 use Encode; 28 29 29 use URIdb; 30 # push "the directory the script is in" into @INC 31 use FindBin; 32 use lib "$FindBin::RealBin/"; 33 34 use URIdb 2.0; 30 35 31 36 # Set up the CGI object... … … 40 45 } 41 46 42 my $uridb = new URIdb;43 44 47 print $q->header(-charset=>'utf8'); 45 46 # default DB info - all other settings should be loaded from the DB.47 my $dbhost = "localhost";48 my $dbname = "uridb";49 my $dbuser = "uridb";50 my $dbpass = "spambgone";51 48 52 49 #my %status = (0 => "Don't list", … … 64 61 $cfgname =~ s|_uridb_cgi.*||; 65 62 $cfgname =~ s|_$||; 66 if (-e "/etc/uridb/$cfgname.conf") {67 my $cfg = `cat /etc/uridb/$cfgname.conf`;68 ($cfg) = ($cfg =~ /^(.+)$/s); # avoid warnings, failures, and general nastiness with taint mode69 eval $cfg;70 }71 63 72 my $ dbh = $uridb->connect($dbhost, $dbname, $dbuser, $dbpass);64 my $uridb = new URIdb (configfile => "/etc/uridb/$cfgname.conf"); 73 65 74 66 my $page;
Note:
See TracChangeset
for help on using the changeset viewer.