package supporters_conf; use strict; use warnings; use CGI qw(:all); # included only for url() # this should be able to be narrowed BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); # set the version for version checking $VERSION = sprintf "%d.%03d", q$Revision: 1.9 $ =~ /(\d+)/g; @ISA = qw(Exporter); @EXPORT = qw(); %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ], # your exported package globals go here, # as well as any optionally exported functions @EXPORT_OK = qw(%config); } our @EXPORT_OK; # exported package globals go here our %config; # initialize package globals, first exported ones %config = (); END { } # module clean-up code here (global destructor) ## YOUR CODE GOES HERE my @required_vars = qw( lib post_max disable_uploads headers_once db template use_db donor_mail list_mail sub_method admin_ cc admin_from mm_svr_admin mm_svr_admin_eml mm_svr_admin_phn field_coordinator field_coordinator_eml mm_svr_host); # Load our configuration. my $path = $0; $path =~ s/\/[^\/]+$//; # strip off filename component of filespec (and last slash) my $url = url(); my $conf = parse_config_directory($url); my $copy = $conf; $copy =~ s/.conf$/.copy/; my $db = $conf; $db =~ s/\.conf$/.db/; open(DB,"$db") or open(DB,"$path/supporters.db") or open(DB, "supporters.db") or die "Can't open $conf or $path/supporters.db or supporters.db"; while () { chomp; next if /^\s*\#/; # Allow comments next if /^\s*$/; # Allow blank lines unless (/=/) { # All other lines must look like: KEY = VAL die "invalid variable assignment in supporters.db: $_"; } my ($key, $val) = split(/\s*=\s*/,$_,2); # Key and value are separated by equals and maybe space $key =~ s/^\s*//; # Strip any leading space from the key # $val =~ s/(\$(\w+))/$config{$2}/g; # Very simple (read: brittle) variable interpolation $val =~ s/ *$//g; # Strip trailing white space from value $config{'db'}{"$key"} = $val; $config{"$key"} = $val; } close DB; open(CONFIG,"$conf") or open(CONFIG,"$path/supporters.conf") or open(CONFIG, "supporters.conf") or die "Can't open $conf or $path/supporters.conf or supporters.conf"; while () { chomp; next if /^\s*\#/; # Allow comments next if /^\s*$/; # Allow blank lines unless (/=/) { # All other lines must look like: KEY = VAL die "invalid variable assignment in supporters.conf: $_"; } my ($key, $val) = split(/\s*=\s*/,$_,2); # Key and value are separated by equals and maybe space $key =~ s/^\s*//; # Strip any leading space from the key $val =~ s/(\$(\w+))/$config{$2}/g; # Very simple (read: brittle) variable interpolation $config{$key} = $val; $config{'config'}{$key} = $val; } close CONFIG; foreach my $var (@required_vars) { if (!exists($config{$var})) { die "Required configuration variable '$var' not found in supporters.conf"; } } # Replace the 'lib' string with an array of libs $config{'lib'} = [split(/:/, $config{'lib'})]; open(COPY,"$copy") or open(COPY,"$path/supporters.copy") or open(COPY, "supporters.copy") or die "Can't open $copy or $path/supporters.copy or supporters.copy"; my $pending = '0'; my ($copykey,$copyvalue,$junk); while () { chomp; next if /^\s*\#/; # skip comments next if (/^\s*$/ && $pending == '0'); # skip blank lines if (m/<