diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/bill | 242 | ||||
-rwxr-xr-x | bin/dbdef-create | 18 | ||||
-rwxr-xr-x | bin/fs-setup | 165 | ||||
-rwxr-xr-x | bin/svc_acct.export | 89 | ||||
-rwxr-xr-x | bin/svc_acct.import | 63 | ||||
-rwxr-xr-x | bin/svc_acct_sm.export | 69 | ||||
-rwxr-xr-x | bin/svc_acct_sm.import | 77 |
7 files changed, 439 insertions, 284 deletions
@@ -1,83 +1,4 @@ -#!/usr/local/bin/perl -Tw -# -# bill: Bill customer(s) -# -# Usage: bill [ -c [ i ] ] [ -d 'date' ] [ -b ] -# -# Bills all customers. -# -# Adds record to /dbin/cust_bill and /dbin/cust_pay (if payment made - -# CARD & COMP), prints invoice / charges card etc. -# -# -c: Turn on collecting (you probably want this). -# -# -i: real-time billing (as opposed to batch billing). only relevant -# for credit cards. -# -# -d: Pretent it's 'date'. Date is in any format Date::Parse is happy with, -# but be careful. -# -# ## n/a ## -b: send batch when done billing -# -# ivan@voicenet.com sep/oct 96 -# -# separated billing and collections, cleaned up code. -# ivan@voicenet.com 96-nov-11 -# -# added -d option -# ivan@voicenet.com 96-nov-13 -# -# added -v option and started to implement it, added 'd:' to getopts call -# (oops!) -# ivan@voicenet.com 97-jan-2 -# -# added more debug messages, moved some searches to fssearch.pl library (for -# speed) -# rewrote "all customer" finder to know about bill dates, for speed. -# ivan@voicenet.com 97-jan-8 -# -# thought about it a while, and removed passing of the -d option to collect...? -# ivan@voicenet.com 97-jan-14 -# -# make all -v stuff STDERR -# ivan@voicenet.com 97-feb-4 -# -# added pkgnum as argument to program from /db/part_pkg, with kludge for the -# "/bin/echo XX" 's already there. -# ivan@voicenet.com 97-feb-23 -# -# - general cleanup -# - customers who are suspended can still be billed for the setup fee -# - cust_pkg record is re-read after the package setup fee program is run. -# this way, -# that program can modify the record (for example, to start accounts off -# suspended) -# (best to think four or five times before modifying anything else!) -# ivan@voicenet.com 97-feb-26 -# -# don't bill recurring fee if its not time! (was removed) -# ivan@voicenet.com 97-mar-6 -# -# added -b option, send batch when done billing. -# ivan@voicenet.com 97-apr-4 -# -#insecure dependency on line 179ish below needs to be fixed before bill is -#used setuid -# ivan@voicenet.com 97-jun-2 -# -# removed running of setup program (depriciated) -# ivan@voicenet.com 97-jul-21 -# -# rewrote for new API, removed option to specify custnums (use FS::Bill -# instead), removed -v option (?) -# ivan@voicenet.com 97-jul-22 - 23 - 25 -28 -# (need to add back in email stuff, look in /home/ivan/old/dbin/collect) -# -# s/suidsetup/adminsuidsetup/, s/FS::Search/FS::Record/, added some batch -# exporting stuff (which still needs to be generalized) and removed &idiot -# ivan@sisd.com 98-may-27 - -# setup +#!/usr/bin/perl -Tw use strict; use Fcntl qw(:flock); @@ -85,16 +6,14 @@ use Date::Parse; use Getopt::Std; use FS::UID qw(adminsuidsetup swapuid); use FS::Record qw(qsearch qsearchs); -use FS::Bill; - -my($batchfile)="/var/spool/freeside/batch"; -my($batchlock)="/var/spool/freeside/batch.lock"; - -adminsuidsetup; +use FS::cust_main; &untaint_argv; #what it sounds like (eww) use vars qw($opt_b $opt_c $opt_i $opt_d); getopts("bcid:"); #switches +my $user = shift or die &usage; + +adminsuidsetup $user; #we're at now now (and later). my($time)= $main::opt_d ? str2time($main::opt_d) : $^T; @@ -111,15 +30,15 @@ foreach $cust_main ( } else { (); } - } qsearch('cust_pkg',{'cancel'=>''}) + } ( qsearch('cust_pkg', { 'cancel' => '' }), + qsearch('cust_pkg', { 'cancel' => 0 }), + ) ) { # and bill them print "Billing customer #" . $cust_main->getfield('custnum') . "\n"; - bless($cust_main,"FS::Bill"); - my($error); $error=$cust_main->bill('time'=>$time); @@ -139,44 +58,6 @@ foreach $cust_main ( } -#if ($main::opt_b) { -# -# die "Batch still waiting for reply? ($batchlock exists)\n" if -e $batchlock; -# open(BATCHLOCK,"+>>$batchlock") or die "Can't open $batchlock: $!"; -# select(BATCHLOCK); $|=1; select(STDOUT); -# unless ( flock(BATCHLOCK,,LOCK_EX|LOCK_NB) ) { -# seek(BATCHLOCK,0,0); -# my($pid)=<BATCHLOCK>; -# chop($pid); -# die "Is a batch running? (pid $pid)\n"; -# } -# seek(BATCHLOCK,0,0); -# print BATCHLOCK $$,"\n"; -# -# ( open(BATCH,">$batchfile") -# and flock(BATCH,LOCK_EX|LOCK_NB) -# ) or die "Can't open $batchfile: $!"; -# -# my($cust_pay_batch); -# foreach $cust_pay_batch (qsearch('cust_pay_batch',{})) { -# print BATCH join(':', -# $_->getfield('cardnum'), -# $_->getfield('exp'), -# $_->getfield('amount'), -# $_->getfield('payname') -# || $_->getfield('first'). ' '. $_->getfield('last'), -# "Description", -# $_->getfield('zip'), -# ),"\n"; -# } -# -# flock(BATCH,LOCK_UN); -# close BATCH; -# -# flock(BATCHLOCK,LOCK_UN); -# close BATCHLOCK; -#} - # subroutines sub untaint_argv { @@ -186,3 +67,110 @@ sub untaint_argv { } } +sub usage { + die "Usage:\n\n bill [ -c [ i ] ] [ -d 'date' ] [ -b ] user\n"; +} + +=head1 NAME + +bill - Command line (crontab, script) interface to customer billing. + +=head1 SYNOPSIS + + bill [ -c [ i ] ] [ -d 'date' ] user + +=head1 DESCRIPTION + +Bills all customers. Searches for customers who are due for billing and calls +the bill and collect methods of a cust_main object. See L<FS::cust_main>. + +-c: Turn on collecting (you probably want this). + +-i: real-time billing (as opposed to batch billing). only relevant + for credit cards. + +-d: Pretent it's 'date'. Date is in any format Date::Parse is happy with, + but be careful. + +user: From the mapsecrets file - see config.html from the base documentation + +=head1 VERSION + +$Id: bill,v 1.6 1998-11-15 02:53:00 ivan Exp $ + +=head1 BUGS + +=head1 SEE ALSO + +L<FS::cust_main>, config.html from the base documentation + +=head1 HISTORY + +ivan@voicenet.com sep/oct 96 + +separated billing and collections, cleaned up code. +ivan@voicenet.com 96-nov-11 + +added -d option +ivan@voicenet.com 96-nov-13 + +added -v option and started to implement it, added 'd:' to getopts call + (oops!) +ivan@voicenet.com 97-jan-2 + +added more debug messages, moved some searches to fssearch.pl library (for +speed) +rewrote "all customer" finder to know about bill dates, for speed. +ivan@voicenet.com 97-jan-8 + +thought about it a while, and removed passing of the -d option to collect...? +ivan@voicenet.com 97-jan-14 + +make all -v stuff STDERR +ivan@voicenet.com 97-feb-4 + +added pkgnum as argument to program from /db/part_pkg, with kludge for the +"/bin/echo XX" 's already there. +ivan@voicenet.com 97-feb-23 + +- general cleanup +- customers who are suspended can still be billed for the setup fee +- cust_pkg record is re-read after the package setup fee program is run. + this way, + that program can modify the record (for example, to start accounts off + suspended) + (best to think four or five times before modifying anything else!) +ivan@voicenet.com 97-feb-26 + +don't bill recurring fee if its not time! (was removed) +ivan@voicenet.com 97-mar-6 + +added -b option, send batch when done billing. +ivan@voicenet.com 97-apr-4 + +insecure dependency on line 179ish below needs to be fixed before bill is +used setuid +ivan@voicenet.com 97-jun-2 + +removed running of setup program (depriciated) +ivan@voicenet.com 97-jul-21 + +rewrote for new API, removed option to specify custnums (use FS::Bill +instead), removed -v option (?) +ivan@voicenet.com 97-jul-22 - 23 - 25 -28 +(need to add back in email stuff, look in /home/ivan/old/dbin/collect) + +s/suidsetup/adminsuidsetup/, s/FS::Search/FS::Record/, added some batch +exporting stuff (which still needs to be generalized) and removed &idiot +ivan@sisd.com 98-may-27 + +$Log: bill,v $ +Revision 1.6 1998-11-15 02:53:00 ivan +afterthought + +Revision 1.4 1998/11/07 08:21:26 ivan +missing use + +=cut + + diff --git a/bin/dbdef-create b/bin/dbdef-create index eb62c77e3..fe7475bec 100755 --- a/bin/dbdef-create +++ b/bin/dbdef-create @@ -1,19 +1,28 @@ #!/usr/bin/perl -Tw # +# $Id: dbdef-create,v 1.2 1998-11-19 11:17:44 ivan Exp $ +# # create dbdef file for existing mySQL database (needs SHOW|DESCRIBE command # not in Pg) based on fs-setup # # ivan@sisd.com 98-jun-2 +# +# $Log: dbdef-create,v $ +# Revision 1.2 1998-11-19 11:17:44 ivan +# adminsuidsetup requires argument +# use strict; use DBI; use FS::dbdef; use FS::UID qw(adminsuidsetup datasrc); -#needs to match FS::Record -my($dbdef_file) = "/var/spool/freeside/dbdef.". datasrc; +my $user = shift or die &usage; -my($dbh)=adminsuidsetup; +my($dbh)=adminsuidsetup $user; + +#needs to match FS::Record +my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; my($tables_sth)=$dbh->prepare("SHOW TABLES"); my($tables_rv)=$tables_sth->execute; @@ -83,3 +92,6 @@ my($dbdef) = new FS::dbdef ( @tables ); #important $dbdef->save($dbdef_file); +sub usage { + die "Usage:\n dbdef-create user\n"; +} diff --git a/bin/fs-setup b/bin/fs-setup index 45332d85c..d21b41d3d 100755 --- a/bin/fs-setup +++ b/bin/fs-setup @@ -1,6 +1,6 @@ #!/usr/bin/perl -Tw # -# create database and necessary tables, etc. DBI version. +# $Id: fs-setup,v 1.17 1999-04-14 07:58:39 ivan Exp $ # # ivan@sisd.com 97-nov-8,9 # @@ -30,6 +30,54 @@ # ivan@sisd.com 98-sep-4 # # fix radius attributes ivan@sisd.com 98-sep-27 +# +# $Log: fs-setup,v $ +# Revision 1.17 1999-04-14 07:58:39 ivan +# export getsecrets from FS::UID instead of calling it explicitly +# +# Revision 1.16 1999/02/28 19:44:16 ivan +# constructors s/create/new/ pointed out by "Bao C. Ha" <bao@hacom.net> +# +# Revision 1.15 1999/02/27 21:06:21 ivan +# cust_main.paydate should be varchar(10), not @date_type ; problem reported +# by Ben Leibig <leibig@colorado.edu> +# +# Revision 1.14 1999/02/07 09:59:14 ivan +# more mod_perl fixes, and bugfixes Peter Wemm sent via email +# +# Revision 1.13 1999/02/04 06:09:23 ivan +# add AU provences +# +# Revision 1.12 1999/02/03 10:42:27 ivan +# *** empty log message *** +# +# Revision 1.11 1999/01/17 03:11:52 ivan +# remove preliminary completehost changes +# +# Revision 1.10 1998/12/16 06:05:38 ivan +# add table cust_main_invoice +# +# Revision 1.9 1998/12/15 04:36:29 ivan +# s/croak/die/; #oops +# +# Revision 1.8 1998/12/15 04:33:27 ivan +# dies if it isn't running as the freeside user +# +# Revision 1.7 1998/11/18 09:01:31 ivan +# i18n! i18n! +# +# Revision 1.6 1998/11/15 13:18:02 ivan +# remove debugging +# +# Revision 1.5 1998/11/15 09:43:03 ivan +# update for new config file syntax, new adminsuidsetup +# +# Revision 1.4 1998/10/22 15:51:23 ivan +# also varchar with no length specified - postgresql fix broke mysql. +# +# Revision 1.3 1998/10/22 15:46:28 ivan +# now smallint is illegal, so remove that too. +# #to delay loading dbdef until we're ready BEGIN { $FS::Record::setup_hack = 1; } @@ -37,12 +85,17 @@ BEGIN { $FS::Record::setup_hack = 1; } use strict; use DBI; use FS::dbdef; -use FS::UID qw(adminsuidsetup datasrc); +use FS::UID qw(adminsuidsetup datasrc checkeuid getsecrets); use FS::Record; use FS::cust_main_county; +die "Not running uid freeside!" unless checkeuid(); + +my $user = shift or die &usage; +getsecrets($user); + #needs to match FS::Record -my($dbdef_file) = "/var/spool/freeside/dbdef.". datasrc; +my($dbdef_file) = "/usr/local/etc/freeside/dbdef.". datasrc; ### @@ -68,7 +121,7 @@ my($char_d) = 80; #default maxlength for text fields #my(@date_type) = ( 'timestamp', '', '' ); my(@date_type) = ( 'int', 'NULL', '' ); -my(@perl_type) = ( 'long varchar', 'NULL', '' ); +my(@perl_type) = ( 'varchar', 'NULL', 255 ); my(@money_type); if (datasrc =~ m/Pg/) { #Pg can't do decimal(10,2) @money_type = ( 'money', '', '' ); @@ -143,13 +196,13 @@ foreach (qw(svc_acct svc_acct_sm svc_domain)) { #important $dbdef->save($dbdef_file); -FS::Record::reload_dbdef; +&FS::Record::reload_dbdef($dbdef_file); ### # create 'em ### -my($dbh)=adminsuidsetup; +my($dbh)=adminsuidsetup $user; #create tables $|=1; @@ -174,14 +227,53 @@ foreach ($dbdef->tables) { #not really sample data (and shouldn't default to US) #cust_main_county + +#USPS state codes foreach ( qw( AL AK AS AZ AR CA CO CT DC DE FM FL GA GU HI ID IL IN IA KS KY LA ME MH MD MA MI MN MS MO MT NC ND NE NH NJ NM NV NY MP OH OK OR PA PW PR RI SC SD TN TX TT UT VT VI VA WA WV WI WY AE AA AP ) ) { - my($cust_main_county)=create FS::cust_main_county({ + my($cust_main_county)=new FS::cust_main_county({ 'state' => $_, 'tax' => 0, + 'country' => 'US', + }); + my($error); + $error=$cust_main_county->insert; + die $error if $error; +} + +#AU "offical" state codes ala mark.williamson@ebbs.com.au (Mark Williamson) +foreach ( qw( +VIC NSW NT QLD TAS ACT WA SA +) ) { + my($cust_main_county)=new FS::cust_main_county({ + 'state' => $_, + 'tax' => 0, + 'country' => 'AU', + }); + my($error); + $error=$cust_main_county->insert; + die $error if $error; +} + +#ISO 2-letter country codes (same as country TLDs) except US and AU +foreach ( qw( +AF AL DZ AS AD AO AI AQ AG AR AM AW AT AZ BS BH BD BB BY BE BZ BJ BM BT BO +BA BW BV BR IO BN BG BF BI KH CM CA CV KY CF TD CL CN CX CC CO KM CG CK CR CI +HR CU CY CZ DK DJ DM DO TP EC EG SV GQ ER EE ET FK FO FJ FI FR FX GF PF TF GA +GM GE DE GH GI GR GL GD GP GU GT GN GW GY HT HM HN HK HU IS IN ID IR IQ IE IL +IT JM JP JO KZ KE KI KP KR KW KG LA LV LB LS LR LY LI LT LU MO MK MG MW MY MV +ML MT MH MQ MR MU YT MX FM MD MC MN MS MA MZ MM NA NR NP NL AN NC NZ NI NE NG +NU NF MP NO OM PK PW PA PG PY PE PH PN PL PT PR QA RE RO RU RW KN LC VC WS SM +ST SA SN SC SL SG SK SI SB SO ZA GS ES LK SH PM SD SR SJ SZ SE CH SY TW TJ TZ +TH TG TK TO TT TN TR TM TC TV UG UA AE GB UM UY UZ VU VA VE VN VG VI WF EH +YE YU ZR ZM ZW +) ) { + my($cust_main_county)=new FS::cust_main_county({ + 'tax' => 0, + 'country' => $_, }); my($error); $error=$cust_main_county->insert; @@ -190,6 +282,10 @@ SC SD TN TX TT UT VT VI VA WA WV WI WY AE AA AP $dbh->disconnect or die $dbh->errstr; +sub usage { + die "Usage:\n fs-setup user\n"; +} + ### # Now it becomes an object. much better. ### @@ -206,7 +302,7 @@ sub tables_hash_hack { 'agentnum', 'int', '', '', 'agent', 'varchar', '', $char_d, 'typenum', 'int', '', '', - 'freq', 'smallint', 'NULL', '', + 'freq', 'int', 'NULL', '', 'prog', @perl_type, ], 'primary_key' => 'agentnum', @@ -281,7 +377,9 @@ sub tables_hash_hack { 'columns' => [ 'custnum', 'int', '', '', 'agentnum', 'int', '', '', +# 'titlenum', 'int', 'NULL', '', 'last', 'varchar', '', $char_d, +# 'middle', 'varchar', 'NULL', $char_d, 'first', 'varchar', '', $char_d, 'ss', 'char', 'NULL', 11, 'company', 'varchar', 'NULL', $char_d, @@ -289,7 +387,7 @@ sub tables_hash_hack { 'address2', 'varchar', 'NULL', $char_d, 'city', 'varchar', '', $char_d, 'county', 'varchar', 'NULL', $char_d, - 'state', 'char', '', 2, + 'state', 'varchar', 'NULL', $char_d, 'zip', 'varchar', '', 10, 'country', 'char', '', 2, 'daytime', 'varchar', 'NULL', 20, @@ -297,7 +395,8 @@ sub tables_hash_hack { 'fax', 'varchar', 'NULL', 12, 'payby', 'char', '', 4, 'payinfo', 'varchar', 'NULL', 16, - 'paydate', @date_type, + #'paydate', @date_type, + 'paydate', 'varchar', 'NULL', 10, 'payname', 'varchar', 'NULL', $char_d, 'tax', 'char', 'NULL', 1, 'otaker', 'varchar', '', 8, @@ -309,13 +408,25 @@ sub tables_hash_hack { 'index' => [ ['last'], ], }, - 'cust_main_county' => { #county+state are checked off the cust_main_county - #table for validation and to provide a tax rate. - #add country? + 'cust_main_invoice' => { + 'columns' => [ + 'destnum', 'int', '', '', + 'custnum', 'int', '', '', + 'dest', 'varchar', '', $char_d, + ], + 'primary_key' => 'destnum', + 'unique' => [ [] ], + 'index' => [ ['custnum'], ], + }, + + 'cust_main_county' => { #county+state+country are checked off the + #cust_main_county for validation and to provide + # a tax rate. 'columns' => [ 'taxnum', 'int', '', '', - 'state', 'char', '', 2, #two letters max in US... elsewhere? - 'county', 'varchar', '', $char_d, + 'state', 'varchar', 'NULL', $char_d, + 'county', 'varchar', 'NULL', $char_d, + 'country', 'char', '', 2, 'tax', 'real', '', '', #tax % ], 'primary_key' => 'taxnum', @@ -350,10 +461,10 @@ sub tables_hash_hack { 'address1', 'varchar', '', $char_d, 'address2', 'varchar', 'NULL', $char_d, 'city', 'varchar', '', $char_d, - 'state', 'char', '', 2, + 'state', 'varchar', '', $char_d, 'zip', 'varchar', '', 10, 'country', 'char', '', 2, - 'trancode', 'TINYINT', '', '', + 'trancode', 'int', '', '', 'cardnum', 'varchar', '', 16, 'exp', @date_type, 'payname', 'varchar', 'NULL', $char_d, @@ -415,7 +526,7 @@ sub tables_hash_hack { 'pkg', 'varchar', '', $char_d, 'comment', 'varchar', '', $char_d, 'setup', @perl_type, - 'freq', 'smallint', '', '', #billing frequency (months) + 'freq', 'int', '', '', #billing frequency (months) 'recur', @perl_type, ], 'primary_key' => 'pkgpart', @@ -423,6 +534,16 @@ sub tables_hash_hack { 'index' => [ [] ], }, +# 'part_title' => { +# 'columns' => [ +# 'titlenum', 'int', '', '', +# 'title', 'varchar', '', $char_d, +# ], +# 'primary_key' => 'titlenum', +# 'unique' => [ [] ], +# 'index' => [ [] ], +# }, + 'pkg_svc' => { 'columns' => [ 'pkgpart', 'int', '', '', @@ -460,7 +581,7 @@ sub tables_hash_hack { 'columns' => [ 'popnum', 'int', '', '', 'city', 'varchar', '', $char_d, - 'state', 'char', '', 2, + 'state', 'varchar', '', $char_d, 'ac', 'char', '', 3, 'exch', 'char', '', 3, #rest o' number? @@ -476,8 +597,8 @@ sub tables_hash_hack { 'username', 'varchar', '', $username_len, #unique (& remove dup code) '_password', 'varchar', '', 25, #13 for encryped pw's plus ' *SUSPENDED* 'popnum', 'int', 'NULL', '', - 'uid', 'bigint', 'NULL', '', - 'gid', 'bigint', 'NULL', '', + 'uid', 'int', 'NULL', '', + 'gid', 'int', 'NULL', '', 'finger', 'varchar', 'NULL', $char_d, 'dir', 'varchar', 'NULL', $char_d, 'shell', 'varchar', 'NULL', $char_d, @@ -493,7 +614,7 @@ sub tables_hash_hack { 'columns' => [ 'svcnum', 'int', '', '', 'domsvc', 'int', '', '', - 'domuid', 'bigint', '', '', + 'domuid', 'int', '', '', 'domuser', 'varchar', '', $char_d, ], 'primary_key' => 'svcnum', diff --git a/bin/svc_acct.export b/bin/svc_acct.export index 3f65a08ba..d4ebe6bdc 100755 --- a/bin/svc_acct.export +++ b/bin/svc_acct.export @@ -1,5 +1,7 @@ #!/usr/bin/perl -Tw # +# $Id: svc_acct.export,v 1.2 1998-12-10 07:23:15 ivan Exp $ +# # Create and export password files: passwd, passwd.adjunct, shadow, # acp_passwd, acp_userinfo, acp_dialup, users # @@ -34,75 +36,46 @@ # # OOPS! added arbitrary radius fields (pry 98-aug-16) but forgot to say so. # ivan@sisd.com 98-sep-18 +# +# $Log: svc_acct.export,v $ +# Revision 1.2 1998-12-10 07:23:15 ivan +# use FS::Conf, need user (for datasrc) +# use strict; +use vars qw($conf); use Fcntl qw(:flock); +use FS::Conf; use FS::SSH qw(scp ssh); -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup datasrc); use FS::Record qw(qsearch fields); +use FS::svc_acct; -my($fshellmachines)="/var/spool/freeside/conf/shellmachines"; -my(@shellmachines); -if ( -e $fshellmachines ) { - open(SHELLMACHINES,$fshellmachines); - @shellmachines=map { - /^(.*)$/ or die "Illegal line in conf/shellmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <SHELLMACHINES>; - close SHELLMACHINES; -} +my $user = shift or die &usage; +adminsuidsetup $user; -my($fbsdshellmachines)="/var/spool/freeside/conf/bsdshellmachines"; -my(@bsdshellmachines); -if ( -e $fbsdshellmachines ) { - open(BSDSHELLMACHINES,$fbsdshellmachines); - @bsdshellmachines=map { - /^(.*)$/ or die "Illegal line in conf/bsdshellmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <BSDSHELLMACHINES>; - close BSDSHELLMACHINES; -} +$conf = new FS::Conf; -my($fnismachines)="/var/spool/freeside/conf/nismachines"; -my(@nismachines); -if ( -e $fnismachines ) { - open(NISMACHINES,$fnismachines); - @nismachines=map { - /^(.*)$/ or die "Illegal line in conf/nismachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <NISMACHINES>; - close NISMACHINES; -} +my @shellmachines = $conf->config('shellmachines') + if $conf->exists('shellmachines'); -my($ferpcdmachines)="/var/spool/freeside/conf/erpcdmachines"; -my(@erpcdmachines); -if ( -e $ferpcdmachines ) { - open(ERPCDMACHINES,$ferpcdmachines); - @erpcdmachines=map { - /^(.*)$/ or die "Illegal line in conf/erpcdmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <ERPCDMACHINES>; - close ERPCDMACHINES; -} +my @bsdshellmachines = $conf->config('bsdshellmachines') + if $conf->exists('bsdshellmachines'); -my($fradiusmachines)="/var/spool/freeside/conf/radiusmachines"; -my(@radiusmachines); -if ( -e $fradiusmachines ) { - open(RADIUSMACHINES,$fradiusmachines); - @radiusmachines=map { - /^(.*)$/ or die "Illegal line in conf/radiusmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <RADIUSMACHINES>; - close RADIUSMACHINES; -} +my @nismachines = $conf->config('nismachines') + if $conf->exists('nismachines'); -my($spooldir)="/var/spool/freeside/export"; -my($spoollock)="/var/spool/freeside/svc_acct.export.lock"; +my @erpcdmachines = $conf->config('erpcdmachines') + if $conf->exists('erpcdmachines'); -adminsuidsetup; +my @radiusmachines = $conf->config('radiusmachines') + if $conf->exists('radiusmachines'); my(@saltset)= ( 'a'..'z' , 'A'..'Z' , '0'..'9' , '.' , '/' ); -srand(time|$$); +require 5.004; #srand(time|$$); + +my $spooldir = "/usr/local/etc/freeside/export.". datasrc; +my $spoollock = "/usr/local/etc/freeside/svc_acct.export.lock.". datasrc; open(EXPORT,"+>>$spoollock") or die "Can't open $spoollock: $!"; select(EXPORT); $|=1; select(STDOUT); @@ -349,3 +322,9 @@ unlink $spoollock; flock(EXPORT,LOCK_UN); close EXPORT; +# + +sub usage { + die "Usage:\n\n svc_acct.export user\n"; +} + diff --git a/bin/svc_acct.import b/bin/svc_acct.import index c4b8c5ec5..512572251 100755 --- a/bin/svc_acct.import +++ b/bin/svc_acct.import @@ -1,5 +1,7 @@ #!/usr/bin/perl -Tw # +# $Id: svc_acct.import,v 1.5 1999-03-25 08:42:19 ivan Exp $ +# # ivan@sisd.com 98-mar-9 # # changed 'password' field to '_password' because PgSQL 6.3 reserves this word @@ -13,19 +15,35 @@ # arbitrary radius attributes ivan@sisd.com 98-aug-9 # # don't import /var/spool/freeside/conf/shells! ivan@sisd.com 98-aug-13 +# +# $Log: svc_acct.import,v $ +# Revision 1.5 1999-03-25 08:42:19 ivan +# import stuff uses Term::Query and spits out (some kinds of) nonsensical input +# +# Revision 1.4 1999/03/24 00:43:38 ivan +# die if no relevant services +# +# Revision 1.3 1998/12/10 07:23:16 ivan +# use FS::Conf, need user (for datasrc) +# +# Revision 1.2 1998/10/13 12:07:51 ivan +# Assigns password from the shadow file for RADIUS password "UNIX" +# use strict; use vars qw(%part_svc); use Date::Parse; +use Term::Query qw(query); use FS::SSH qw(iscp); -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup datasrc); use FS::Record qw(qsearch); use FS::svc_acct; +use FS::part_svc; -adminsuidsetup; +my $user = shift or die &usage; +adminsuidsetup $user; -#my($spooldir)="/var/spool/freeside/export"; -my($spooldir)="unix/"; +my($spooldir)="/usr/local/etc/freeside/export.". datasrc; $FS::svc_acct::nossh_hack = 1; @@ -33,6 +51,8 @@ $FS::svc_acct::nossh_hack = 1; %part_svc=map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct'}); +die "No services with svcdb svc_acct!\n" unless %part_svc; + print "\n\n", &menu_svc, "\n", <<END; Most accounts probably have entries in passwd and users (with Port-Limit nonexistant or 1). @@ -58,8 +78,7 @@ my($oisdn_svcpart)=&getpart; print "\n\n", &menu_svc, "\n", <<END; POP mail accounts have entries in passwd only, and have a particular shell. END -print "Enter that shell: "; -my($pop_shell)=&getvalue; +my($pop_shell)=&getvalue("Enter that shell:"); my($popmail_svcpart)=&getpart; print "\n\n", &menu_svc, "\n", <<END; @@ -71,37 +90,36 @@ print "\n\n", <<END; Enter the location and name of your _user_ passwd file, for example "mail.isp.com:/etc/passwd" or "nis.isp.com:/etc/global/passwd" END -print ":"; -my($loc_passwd)=&getvalue; +my($loc_passwd)=&getvalue(":"); iscp("root\@$loc_passwd", "$spooldir/passwd.import"); print "\n\n", <<END; Enter the location and name of your _user_ shadow file, for example "mail.isp.com:/etc/shadow" or "bsd.isp.com:/etc/master.passwd" END -print ":"; -my($loc_shadow)=&getvalue; +my($loc_shadow)=&getvalue(":"); iscp("root\@$loc_shadow", "$spooldir/shadow.import"); print "\n\n", <<END; Enter the location and name of your radius "users" file, for example "radius.isp.com:/etc/raddb/users" END -print ":"; -my($loc_users)=&getvalue; +my($loc_users)=&getvalue(":"); iscp("root\@$loc_users", "$spooldir/users.import"); sub menu_svc { ( join "\n", map "$_: ".$part_svc{$_}->svc, sort keys %part_svc ). "\n"; } sub getpart { - print "Enter part number, or 0 for none: "; - &getvalue; + $^W=0; # Term::Query isn't -w-safe + query "Enter part number:", 'irk', [ keys %part_svc ]; + $^W=1; } sub getvalue { - my($x)=scalar(<STDIN>); - chop $x; - $x; + my $prompt = shift; + $^W=0; # Term::Query isn't -w-safe + query $prompt, ''; + $^W=1; } print "\n\n"; @@ -122,6 +140,7 @@ while (<USERS>) { or die "1Unexpected line in users.import: $_"; my($password,$expiration); ($username,$password,$expiration)=(lc($1),$2,$4); + $password = '' if $password eq 'UNIX'; $upassword{$username}=$password; undef %param; } else { @@ -176,7 +195,7 @@ while (<PASSWD>) { $svcpart = $shell_svcpart; } - my($svc_acct) = create FS::svc_acct ({ + my($svc_acct) = new FS::svc_acct ({ 'svcpart' => $svcpart, 'username' => $username, 'password' => $password, @@ -210,7 +229,7 @@ foreach $username ( keys %upassword ) { die "Illegal Port-Limit in users!\n"; } - my($svc_acct) = create FS::svc_acct ({ + my($svc_acct) = new FS::svc_acct ({ 'svcpart' => $svcpart, 'username' => $username, 'password' => $password, @@ -225,3 +244,9 @@ foreach $username ( keys %upassword ) { delete $upassword{$username}; } +# + +sub usage { + die "Usage:\n\n svc_acct.export user\n"; +} + diff --git a/bin/svc_acct_sm.export b/bin/svc_acct_sm.export index c2ec1e53f..ce4900733 100755 --- a/bin/svc_acct_sm.export +++ b/bin/svc_acct_sm.export @@ -1,6 +1,10 @@ #!/usr/bin/perl -Tw # -# Create and export VoiceNet_quasar.m4 +# $Id: svc_acct_sm.export,v 1.2 1998-12-10 07:23:17 ivan Exp $ +# +# Create and export config files for sendmail, qmail +# +# (used to) Create and export VoiceNet_quasar.m4 # # ivan@voicenet.com late oct 96 # @@ -36,53 +40,42 @@ # put example $my_domain declaration in ivan@sisd.com 98-mar-23 # # /var/spool/freeside/conf and sendmail updates ivan@sisd.com 98-aug-14 +# +# $Log: svc_acct_sm.export,v $ +# Revision 1.2 1998-12-10 07:23:17 ivan +# use FS::Conf, need user (for datasrc) +# use strict; +use vars qw($conf); use Fcntl qw(:flock); use FS::SSH qw(ssh scp); -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup datasrc); use FS::Record qw(qsearch qsearchs); +use FS::svc_acct; +use FS::svc_acct_sm; +use FS::svc_domain; + +my $user = shift or die &usage; +adminsuidsetup $user; + +$conf = new FS::Conf; -my($conf_shellm)="/var/spool/freeside/conf/shellmachine"; -my($fqmailmachines)="/var/spool/freeside/conf/qmailmachines"; my($shellmachine); my(@qmailmachines); -if ( -e $fqmailmachines ) { - open(SHELLMACHINE,$conf_shellm) or die "Can't open $conf_shellm: $!"; - <SHELLMACHINE> =~ /^([\w\.\-]+)$/ or die "Illegal $conf_shellm"; - $shellmachine = $1; - close SHELLMACHINE; - open(QMAILMACHINES,$fqmailmachines); - @qmailmachines=map { - /^(.*)$/ or die "Illegal line in conf/qmailmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <QMAILMACHINES>; - close QMAILMACHINES; +if ( $conf->exists('qmailmachines') ) { + $shellmachine = $conf->config('shellmachine'); + @qmailmachines = $conf->config('qmailmachines'); } -my($fsendmailmachines)="/var/spool/freeside/conf/sendmailmachines"; -my(@sendmailmachines); -if ( -e $fsendmailmachines ) { - open(SENDMAILMACHINES,$fsendmailmachines); - @sendmailmachines=map { - /^(.*)$/ or die "Illegal line in conf/sendmailmachines"; #we trust the file - $1; - } grep $_ !~ /^(#|$)/, <SENDMAILMACHINES>; - close SENDMAILMACHINES; -} +my @sendmailmachines = $conf->config('sendmailmachines') + if $conf->exists('sendmailmachines'); -my($conf_domain)="/var/spool/freeside/conf/domain"; -open(DOMAIN,$conf_domain) or die "Can't open $conf_domain: $!"; -my($mydomain)=map { - /^(.*)$/ or die "Illegal line in $conf_domain!"; #yes, we trust the file - $1 -} grep $_ !~ /^(#|$)/, <DOMAIN>; -close DOMAIN; +my $mydomain = $conf->config('domain'); -my($spooldir)="/var/spool/freeside/export"; -my($spoollock)="/var/spool/freeside/svc_acct_sm.export.lock"; +my $spooldir = "/usr/local/etc/freeside/export.". datasrc; +my $spoollock = "/usr/local/etc/freeside/svc_acct_sm.export.lock.". datasrc; -adminsuidsetup; umask 066; open(EXPORT,"+>>$spoollock") or die "Can't open $spoollock: $!"; @@ -219,3 +212,9 @@ unlink $spoollock; flock(EXPORT,LOCK_UN); close EXPORT; +# + +sub usage { + die "Usage:\n\n svc_acct.export user\n"; +} + diff --git a/bin/svc_acct_sm.import b/bin/svc_acct_sm.import index 10d7e4c20..bda9762e1 100755 --- a/bin/svc_acct_sm.import +++ b/bin/svc_acct_sm.import @@ -1,5 +1,7 @@ #!/usr/bin/perl -Tw # +# $Id: svc_acct_sm.import,v 1.4 1999-03-25 08:42:20 ivan Exp $ +# # ivan@sisd.com 98-mar-9 # # generalized svcparts ivan@sisd.com 98-mar-23 @@ -12,19 +14,33 @@ # has an (untested) section for sendmail, s/warn/die/g and generates a program # to run on your mail machine _later_ instead of ssh'ing for each user # ivan@sisd.com 98-jul-13 +# +# $Log: svc_acct_sm.import,v $ +# Revision 1.4 1999-03-25 08:42:20 ivan +# import stuff uses Term::Query and spits out (some kinds of) nonsensical input +# +# Revision 1.3 1999/03/24 00:51:55 ivan +# die if no relevant services... cvspain +# +# Revision 1.2 1998/12/10 07:23:18 ivan +# use FS::Conf, need user (for datasrc) +# use strict; use vars qw(%d_part_svc %m_part_svc); +use Term::Query qw(query); use FS::SSH qw(iscp); -use FS::UID qw(adminsuidsetup); +use FS::UID qw(adminsuidsetup datasrc); use FS::Record qw(qsearch qsearchs); use FS::svc_acct_sm; use FS::svc_domain; +use FS::svc_acct; +use FS::part_svc; -adminsuidsetup; +my $user = shift or die &usage; +adminsuidsetup $user; -#my($spooldir)="/var/spool/freeside/export"; -my($spooldir)="unix"; +my($spooldir)="/usr/local/etc/freeside/export.". datasrc; my(%mta) = ( 1 => "qmail", @@ -38,22 +54,33 @@ my(%mta) = ( %m_part_svc = map { $_->svcpart, $_ } qsearch('part_svc',{'svcdb'=>'svc_acct_sm'}); +die "No services with svcdb svc_domain!\n" unless %d_part_svc; +die "No services with svcdb svc_svc_acct_sm!\n" unless %m_part_svc; + print "\n\n", ( join "\n", map "$_: ".$d_part_svc{$_}->svc, sort keys %d_part_svc ), - "\n\nEnter part number for domains: "; -my($domain_svcpart)=&getvalue; + "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $domain_svcpart = + query "Enter part number for domains: ", 'irk', [ keys %d_part_svc ]; +$^W=1; print "\n\n", ( join "\n", map "$_: ".$m_part_svc{$_}->svc, sort keys %m_part_svc ), - "\n\nEnter part number for mail aliases: "; -my($mailalias_svcpart)=&getvalue; + "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $mailalias_svcpart = + query "Enter part number for mail aliases: ", 'irk', [ keys %m_part_svc ]; +$^W=1; print "\n\n", <<END; Select your MTA from the following list. END print join "\n", map "$_: $mta{$_}", sort keys %mta; -print "\n\n:"; -my($mta)=&getvalue; +print "\n\n"; +$^W=0; #Term::Query isn't -w-safe +my $mta = query ":", 'irk', [ keys %mta ]; +$^W=1; if ( $mta{$mta} eq "qmail" ) { @@ -61,8 +88,7 @@ if ( $mta{$mta} eq "qmail" ) { Enter the location and name of your qmail control directory, for example "mail.isp.com:/var/qmail/control" END - print ":"; - my($control)=&getvalue; + my($control)=&getvalue(":"); iscp("root\@$control/rcpthosts","$spooldir/rcpthosts.import"); # iscp("root\@$control/recipientmap","$spooldir/recipientmap.import"); iscp("root\@$control/virtualdomains","$spooldir/virtualdomains.import"); @@ -80,16 +106,14 @@ END Enter the location and name of your sendmail virtual user table, for example "mail.isp.com:/etc/virtusertable" END - print ":"; - my($virtusertable)=&getvalue; + my($virtusertable)=&getvalue(":"); iscp("root\@$virtusertable","$spooldir/virtusertable.import"); print "\n\n", <<END; Enter the location and name of your sendmail.cw file, for example "mail.isp.com:/etc/sendmail.cw" END - print ":"; - my($sendmail_cw)=&getvalue; + my($sendmail_cw)=&getvalue(":"); iscp("root\@$sendmail_cw","$spooldir/sendmail.cw.import"); } else { @@ -97,9 +121,10 @@ END } sub getvalue { - my($x)=scalar(<STDIN>); - chop $x; - $x; + my $prompt = shift; + $^W=0; #Term::Query isn't -w-safe + query $prompt, ''; + $^W=1; } print "\n\n"; @@ -129,7 +154,7 @@ while (<RCPTHOSTS>) { my $domain = $1; my($svc_domain); unless ( $svc_domain = qsearchs('svc_domain', {'domain'=>$domain} ) ) { - $svc_domain = create FS::svc_domain ({ + $svc_domain = new FS::svc_domain ({ 'domain' => $domain, 'svcpart' => $domain_svcpart, 'action' => 'N', @@ -184,7 +209,7 @@ END } unless ( exists $svcnum{$domain} ) { - my($svc_domain) = create FS::svc_domain ({ + my($svc_domain) = new FS::svc_domain ({ 'domain' => $domain, 'svcpart' => $domain_svcpart, 'action' => 'N', @@ -195,7 +220,7 @@ END $svcnum{$domain}=$svc_domain->svcnum; } - my($svc_acct_sm)=create FS::svc_acct_sm ({ + my($svc_acct_sm)=new FS::svc_acct_sm ({ 'domsvc' => $svcnum{$domain}, 'domuid' => $svc_acct->uid, 'domuser' => '*', @@ -225,7 +250,7 @@ END die "Unknown user $username in virtusertable"; next; } - my($svc_acct_sm)=create FS::svc_acct_sm ({ + my($svc_acct_sm)=new FS::svc_acct_sm ({ 'domsvc' => $svcnum{$domain}, 'domuid' => $svc_acct->uid, 'domuser' => $domuser || '*', @@ -250,3 +275,9 @@ Don\'t forget to run $spooldir/virtualdomains.FIX before using $spooldir/virtualdomains ! END +# + +sub usage { + die "Usage:\n\n svc_acct_sm.export user\n"; +} + |