diff options
author | ivan <ivan> | 1998-11-13 09:56:57 +0000 |
---|---|---|
committer | ivan <ivan> | 1998-11-13 09:56:57 +0000 |
commit | 0bf5ad9ff0a65195db88ed0bac3aa11c33ec1ad3 (patch) | |
tree | e1f4e0dd775f4b4c82f23140f27609d26216f9fe /site_perl | |
parent | f6ef3dec7840be2e7ac7c39bed32a7ea68425b2d (diff) |
change configuration file layout to support multiple distinct databases (with
own set of config files, export, etc.)
Diffstat (limited to 'site_perl')
-rw-r--r-- | site_perl/Record.pm | 17 | ||||
-rw-r--r-- | site_perl/UID.pm | 106 | ||||
-rw-r--r-- | site_perl/cust_bill.pm | 14 | ||||
-rw-r--r-- | site_perl/cust_main.pm | 72 | ||||
-rw-r--r-- | site_perl/svc_acct.pm | 17 | ||||
-rw-r--r-- | site_perl/svc_acct_sm.pm | 12 | ||||
-rw-r--r-- | site_perl/svc_domain.pm | 91 |
7 files changed, 200 insertions, 129 deletions
diff --git a/site_perl/Record.pm b/site_perl/Record.pm index a90e76b1e..111bb82a2 100644 --- a/site_perl/Record.pm +++ b/site_perl/Record.pm @@ -12,11 +12,12 @@ use FS::dbdef; @ISA = qw(Exporter); @EXPORT_OK = qw(dbh fields hfields qsearch qsearchs dbdef); -$File::CounterFile::DEFAULT_DIR = "/var/spool/freeside/counters" ; - -$dbdef_file = "/var/spool/freeside/dbdef.". datasrc; - -reload_dbdef unless $setup_hack; +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::Record'} = sub { + $File::CounterFile::DEFAULT_DIR = "/usr/local/etc/freeside/counters". datasrc; + $dbdef_file = "/usr/local/etc/freeside/dbdef.". datasrc; + &reload_dbdef unless $setup_hack; #$setup_hack needed now? +}; =head1 NAME @@ -870,7 +871,11 @@ added pod documentation ivan@sisd.com 98-sep-6 ut_phonen got ''; at the end ivan@sisd.com 98-sep-27 $Log: Record.pm,v $ -Revision 1.4 1998-11-10 07:45:25 ivan +Revision 1.5 1998-11-13 09:56:51 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + +Revision 1.4 1998/11/10 07:45:25 ivan doc clarification Revision 1.2 1998/11/07 05:17:18 ivan diff --git a/site_perl/UID.pm b/site_perl/UID.pm index 7959343e0..77c40aad5 100644 --- a/site_perl/UID.pm +++ b/site_perl/UID.pm @@ -2,7 +2,11 @@ package FS::UID; use strict; use vars qw( - @ISA @EXPORT_OK $cgi $dbh $freeside_uid $conf $datasrc $db_user $db_pass + @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user + $conf_dir $secrets $datasrc $db_user $db_pass %callback +); +use subs qw( + getsecrets cgisetotaker ); use Exporter; use Carp; @@ -15,9 +19,7 @@ use FS::Conf; $freeside_uid = scalar(getpwnam('freeside')); -my $conf = new FS::Conf; -($datasrc, $db_user, $db_pass) = $conf->config('secrets') - or die "Can't get secrets: $!"; +$conf_dir = "/usr/local/etc/freeside/"; =head1 NAME @@ -28,7 +30,7 @@ FS::UID - Subroutines for database login and assorted other stuff use FS::UID qw(adminsuidsetup cgisuidsetup dbh datasrc getotaker checkeuid checkruid swapuid); - adminsuidsetup; + adminsuidsetup $user; $cgi = new CGI; $dbh = cgisuidsetup($cgi); @@ -45,18 +47,23 @@ Provides a hodgepodge of subroutines. =over 4 -=item adminsuidsetup +=item adminsuidsetup USER +Sets the user to USER (see config.html from the base documentation). Cleans the environment. Make sure the script is running as freeside, or setuid freeside. Opens a connection to the database. Swaps real and effective UIDs. +Runs any defined callbacks (see below). Returns the DBI database handle (usually you don't need this). =cut sub adminsuidsetup { + $user = shift; + croak "fatal: adminsuidsetup called without arguements" unless $user; + $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin'; $ENV{'SHELL'} = '/bin/sh'; $ENV{'IFS'} = " \t\n"; @@ -65,16 +72,18 @@ sub adminsuidsetup { $ENV{'BASH_ENV'} = ''; croak "Not running uid freeside!" unless checkeuid(); + getsecrets; $dbh = DBI->connect($datasrc,$db_user,$db_pass, { - # hack for web demo - # my($user)=getotaker(); - # $dbh = DBI->connect("$datasrc:$user",$db_user,$db_pass, { 'AutoCommit' => 'true', 'ChopBlanks' => 'true', - } ) or die "DBI->connect error: $DBI::errstr\n";; + } ) or die "DBI->connect error: $DBI::errstr\n"; swapuid(); #go to non-privledged user if running setuid freeside + foreach ( keys %callback ) { + &{$callback{$_}}; + } + $dbh; } @@ -86,13 +95,14 @@ Runs adminsuidsetup. =cut sub cgisuidsetup { - $cgi=$_[0]; + $cgi=shift; if ( $cgi->isa('CGI::Base') ) { carp "Use of CGI::Base is depriciated"; } elsif ( ! $cgi->isa('CGI') ) { croak "Pass a CGI object to cgisuidsetup!"; } - adminsuidsetup; + cgisetotaker; + adminsuidsetup($user); } =item cgi @@ -136,20 +146,31 @@ sub suidsetup { =item getotaker -Returns the current Freeside user. Currently that means the CGI REMOTE_USER, -or 'freeside'. +Returns the current Freeside user. =cut sub getotaker { - if ( $cgi && $cgi->can('var') && defined $cgi->var('REMOTE_USER')) { + $user; +} + +=item cgisetotaker + +Sets and returns the CGI REMOTE_USER. $cgi should be defined as a CGI.pm +object. Support for CGI::Base and derived classes is depriciated. + +=cut + +sub cgisetotaker { + if ( $cgi && $cgi->isa('CGI::Base') && defined $cgi->var('REMOTE_USER')) { carp "Use of CGI::Base is depriciated"; - return $cgi->var('REMOTE_USER'); #for now - } elsif ( $cgi && $cgi->can('remote_user') && defined $cgi->remote_user ) { - return $cgi->remote_user; + $user = $cgi->var('REMOTE_USER'); + } elsif ( $cgi && $cgi->isa('CGI') && defined $cgi->remote_user ) { + $user = $cgi->remote_user; } else { - return 'freeside'; + die "fatal: Can't get REMOTE_USER!"; } + return $user; } =item checkeuid @@ -182,18 +203,57 @@ sub swapuid { ($<,$>) = ($>,$<); } +=item getsecrets [ USER ] + +Sets the user to USER, if supplied. +Sets and returns the DBI datasource, username and password for this user from +the `/usr/local/etc/freeside/mapsecrets' file. + +=cut + +sub getsecrets { + my($setuser) = shift; + $user = $setuser if $setuser; + die "No user!" unless $user; + my($conf) = new FS::Conf $conf_dir; + my($line) = grep /^\s*$user\s/, $conf->config('mapsecrets'); + $line =~ /^\s*$user\s+(.*)$/; + $secrets = $1; + die "User not found in mapsecrets file!" unless $secrets; + ($datasrc, $db_user, $db_pass) = $conf->config($secrets) + or die "Can't get secrets: $!"; + $FS::Conf::default_dir .= "/conf.$datasrc"; + ($datasrc, $db_user, $db_pass); +} + =back +=head1 CALLBACKS + +Warning: this interface is likely to change in future releases. + +A package can install a callback to be run in adminsuidsetup by putting a +coderef into the hash %FS::UID::callback : + + $coderef = sub { warn "Hi, I'm returning your call!" }; + $FS::UID::callback{'Package::Name'}; + =head1 BUGS +Too many package-global variables. + Not OO. No capabilities yet. When mod_perl and Authen::DBI are implemented, cgisuidsetup will go away as well. +Goes through contortions to support non-OO syntax with multiple datasrc's. + +Callbacks are inelegant. + =head1 SEE ALSO -L<FS::Record>, L<CGI>, L<DBI> +L<FS::Record>, L<CGI>, L<DBI>, config.html from the base documentation. =head1 HISTORY @@ -222,7 +282,11 @@ inlined suidsetup ivan@sisd.com 98-sep-12 $Log: UID.pm,v $ -Revision 1.3 1998-11-08 10:45:42 ivan +Revision 1.4 1998-11-13 09:56:52 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + +Revision 1.3 1998/11/08 10:45:42 ivan got sub cgi for FS::CGI Revision 1.2 1998/11/08 09:38:43 ivan diff --git a/site_perl/cust_bill.pm b/site_perl/cust_bill.pm index bc9424233..455fc2d4f 100644 --- a/site_perl/cust_bill.pm +++ b/site_perl/cust_bill.pm @@ -8,9 +8,11 @@ use FS::Record qw(fields qsearch qsearchs); @ISA = qw(FS::Record Exporter); -$conf = new FS::Conf; - -($add1,$add2,$add3,$add4) = $conf->config('address'); +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::cust_bill'} = sub { + $conf = new FS::Conf; + ( $add1, $add2, $add3, $add4 ) = $conf->config('address'); +}; =head1 NAME @@ -490,7 +492,11 @@ charges can be negative ivan@sisd.com 98-jul-13 pod, ingegrate with FS::Invoice ivan@sisd.com 98-sep-20 $Log: cust_bill.pm,v $ -Revision 1.2 1998-11-07 10:24:24 ivan +Revision 1.3 1998-11-13 09:56:53 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + +Revision 1.2 1998/11/07 10:24:24 ivan don't use depriciated FS::Bill and FS::Invoice, other miscellania diff --git a/site_perl/cust_main.pm b/site_perl/cust_main.pm index 0ef69cba4..83a7d786d 100644 --- a/site_perl/cust_main.pm +++ b/site_perl/cust_main.pm @@ -24,39 +24,43 @@ use FS::cust_pay; @ISA = qw(FS::Record Exporter); @EXPORT_OK = qw(hfields); -$conf = new FS::Conf; -$lpr = $conf->config('lpr'); - -if ( $conf->exists('cybercash3.2') ) { - require CCMckLib3_2; - #qw($MCKversion %Config InitConfig CCError CCDebug CCDebug2); - require CCMckDirectLib3_2; - #qw(SendCC2_1Server); - require CCMckErrno3_2; - #qw(MCKGetErrorMessage $E_NoErr); - import CCMckErrno3_2 qw($E_NoErr); - my $merchant_conf; - ($merchant_conf,$xaction)= $conf->config('cybercash3.2'); - my $status = &CCMckLib3_2::InitConfig($merchant_conf); - if ( $status != $E_NoErr ) { - warn "CCMckLib3_2::InitConfig error:\n"; - foreach my $key (keys %CCMckLib3_2::Config) { - warn " $key => $CCMckLib3_2::Config{$key}\n" +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::cust_main'} = sub { + $conf = new FS::Conf; + $lpr = $conf->config('lpr'); + + if ( $conf->exists('cybercash3.2') ) { + require CCMckLib3_2; + #qw($MCKversion %Config InitConfig CCError CCDebug CCDebug2); + require CCMckDirectLib3_2; + #qw(SendCC2_1Server); + require CCMckErrno3_2; + #qw(MCKGetErrorMessage $E_NoErr); + import CCMckErrno3_2 qw($E_NoErr); + + my $merchant_conf; + ($merchant_conf,$xaction)= $conf->config('cybercash3.2'); + my $status = &CCMckLib3_2::InitConfig($merchant_conf); + if ( $status != $E_NoErr ) { + warn "CCMckLib3_2::InitConfig error:\n"; + foreach my $key (keys %CCMckLib3_2::Config) { + warn " $key => $CCMckLib3_2::Config{$key}\n" + } + my($errmsg) = &CCMckErrno3_2::MCKGetErrorMessage($status); + die "CCMckLib3_2::InitConfig fatal error: $errmsg\n"; } - my($errmsg) = &CCMckErrno3_2::MCKGetErrorMessage($status); - die "CCMckLib3_2::InitConfig fatal error: $errmsg\n"; + $processor='cybercash3.2'; + } elsif ( $conf->exists('cybercash2') ) { + require CCLib; + #qw(sendmserver); + ( $main::paymentserverhost, + $main::paymentserverport, + $main::paymentserversecret, + $xaction, + ) = $conf->config('cybercash2'); + $processor='cybercash2'; } - $processor='cybercash3.2'; -} elsif ( $conf->exists('cybercash2') ) { - require CCLib; - #qw(sendmserver); - ( $main::paymentserverhost, - $main::paymentserverport, - $main::paymentserversecret, - $xaction, - ) = $conf->config('cybercash2'); - $processor='cybercash2'; -} +}; =head1 NAME @@ -864,7 +868,11 @@ enable cybercash, cybercash v3 support, don't need to import FS::UID::{datasrc,checkruid} ivan@sisd.com 98-sep-19-21 $Log: cust_main.pm,v $ -Revision 1.2 1998-11-07 10:24:25 ivan +Revision 1.3 1998-11-13 09:56:54 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + +Revision 1.2 1998/11/07 10:24:25 ivan don't use depriciated FS::Bill and FS::Invoice, other miscellania diff --git a/site_perl/svc_acct.pm b/site_perl/svc_acct.pm index a43af6b1a..fdc9f0bc1 100644 --- a/site_perl/svc_acct.pm +++ b/site_perl/svc_acct.pm @@ -12,10 +12,13 @@ use FS::cust_svc; @ISA = qw(FS::Record Exporter); @EXPORT_OK = qw(fields); -$conf = new FS::Conf; -$dir_prefix = $conf->config('home'); -@shells = $conf->config('shells'); -$shellmachine = $conf->config('shellmachine'); +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::svc_acct'} = sub { + $conf = new FS::Conf; + $dir_prefix = $conf->config('home'); + @shells = $conf->config('shells'); + $shellmachine = $conf->config('shellmachine'); +}; @saltset = ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); @pw_set = ( 'a'..'z', 'A'..'Z', '0'..'9', '(', ')', '#', '!', '.', ',' ); @@ -551,6 +554,12 @@ arbitrary radius attributes ivan@sisd.com 98-aug-13 pod and FS::conf ivan@sisd.com 98-sep-22 +$Log: svc_acct.pm,v $ +Revision 1.2 1998-11-13 09:56:55 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + + =cut 1; diff --git a/site_perl/svc_acct_sm.pm b/site_perl/svc_acct_sm.pm index c87ed2c54..4293e0365 100644 --- a/site_perl/svc_acct_sm.pm +++ b/site_perl/svc_acct_sm.pm @@ -11,11 +11,13 @@ use FS::Conf; @ISA = qw(FS::Record Exporter); @EXPORT_OK = qw(fields); -$conf = new FS::Conf; - -$shellmachine = $conf->exists('qmailmachines') - ? $conf->config('shellmachine') - : ''; +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::svc_acct_sm'} = sub { + $conf = new FS::Conf; + $shellmachine = $conf->exists('qmailmachines') + ? $conf->config('shellmachine') + : ''; +}; =head1 NAME diff --git a/site_perl/svc_domain.pm b/site_perl/svc_domain.pm index c12819ec3..69b225eb5 100644 --- a/site_perl/svc_domain.pm +++ b/site_perl/svc_domain.pm @@ -1,7 +1,9 @@ package FS::svc_domain; use strict; -use vars qw(@ISA @EXPORT_OK $whois_hack $conf $mydomain $smtpmachine); +use vars qw(@ISA @EXPORT_OK $whois_hack $conf $mydomain $smtpmachine + $tech_contact $from $to @nameservers @nameserver_ips @template +); use Exporter; use Carp; use Mail::Internet; @@ -14,60 +16,31 @@ use FS::Conf; @ISA = qw(FS::Record Exporter); @EXPORT_OK = qw(fields); -$conf = new FS::Conf; - -$mydomain = $conf->config('domain'); -$smtpmachine = $conf->config('smtpmachine'); - -my($internic)="/var/spool/freeside/conf/registries/internic"; -my($conf_tech)="$internic/tech_contact"; -my($conf_from)="$internic/from"; -my($conf_to)="$internic/to"; -my($nameservers)="$internic/nameservers"; -my($template)="$internic/template"; - -open(TECH_CONTACT,$conf_tech) or die "Can't open $conf_tech: $!"; -my($tech_contact)=map { - /^(.*)$/ or die "Illegal line in $conf_tech!"; #yes, we trust the file - $1; -} grep $_ !~ /^(#|$)/, <TECH_CONTACT>; -close TECH_CONTACT; - -open(FROM,$conf_from) or die "Can't open $conf_from: $!"; -my($from)=map { - /^(.*)$/ or die "Illegal line in $conf_from!"; #yes, we trust the file - $1; -} grep $_ !~ /^(#|$)/, <FROM>; -close FROM; - -open(TO,$conf_to) or die "Can't open $conf_to: $!"; -my($to)=map { - /^(.*)$/ or die "Illegal line in $conf_to!"; #yes, we trust the file - $1; -} grep $_ !~ /^(#|$)/, <TO>; -close TO; - -open(NAMESERVERS,$nameservers) or die "Can't open $nameservers: $!"; -my(@nameservers)=map { - /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/ - or die "Illegal line in $nameservers!"; #yes, we trust the file - $1; -} grep $_ !~ /^(#|$)/, <NAMESERVERS>; -close NAMESERVERS; -open(NAMESERVERS,$nameservers) or die "Can't open $nameservers: $!"; -my(@nameserver_ips)=map { - /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/ - or die "Illegal line in $nameservers!"; #yes, we trust the file - $1; -} grep $_ !~ /^(#|$)/, <NAMESERVERS>; -close NAMESERVERS; - -open(TEMPLATE,$template) or die "Can't open $template: $!"; -my(@template)=map { - /^(.*)$/ or die "Illegal line in $to!"; #yes, we trust the file - $1. "\n"; -} <TEMPLATE>; -close TEMPLATE; +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::domain'} = sub { + $conf = new FS::Conf; + + $mydomain = $conf->config('domain'); + $smtpmachine = $conf->config('smtpmachine'); + + my($internic)="/registries/internic"; + $tech_contact = $conf->config("$internic/tech_contact"); + $from = $conf->config("$internic/from"); + $to = $conf->config("$internic/to"); + my(@ns) = $conf->config("$internic/nameservers"); + @nameservers=map { + /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/ + or die "Illegal line in $internic/nameservers"; + $1; + } @ns; + @nameserver_ips=map { + /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/ + or die "Illegal line in $internic/nameservers!"; + $1; + } @ns; + @template = map { $_. "\n" } $conf->config("$internic/template"); + +}; =head1 NAME @@ -523,7 +496,7 @@ config.html from the base documentation. =head1 VERSION -$Id: svc_domain.pm,v 1.2 1998-10-14 08:18:21 ivan Exp $ +$Id: svc_domain.pm,v 1.3 1998-11-13 09:56:57 ivan Exp $ =head1 HISTORY @@ -542,7 +515,11 @@ ivan@sisd.com 98-jul-17-19 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23 $Log: svc_domain.pm,v $ -Revision 1.2 1998-10-14 08:18:21 ivan +Revision 1.3 1998-11-13 09:56:57 ivan +change configuration file layout to support multiple distinct databases (with +own set of config files, export, etc.) + +Revision 1.2 1998/10/14 08:18:21 ivan More informative error messages and better doc for admin contact email stuff |