X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=bin%2Fsvc_acct_sm.export;h=bda17e332a1f9b28f32cc415f9951da4f8bcb208;hb=7f07089722bfcabe3bf42619bb2bdb81fd8d44e1;hp=c2ec1e53f61c232e8181ca53415afc1fc21c6ec9;hpb=2b7168658e93060473aab7d36cb2a6ec0abb5fe0;p=freeside.git diff --git a/bin/svc_acct_sm.export b/bin/svc_acct_sm.export index c2ec1e53f..bda17e332 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.8 2000-07-06 03:37:24 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,64 @@ # 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.8 2000-07-06 03:37:24 ivan +# don't error out on invalid svc_acct_sm.domuid's that can't be matched in +# svc_acct.uid - just warn. +# +# Revision 1.7 2000/07/03 09:13:10 ivan +# get rid of double sendmailrestart invocation; no need for multiple sessions +# +# Revision 1.6 2000/07/03 09:09:14 ivan +# typo +# +# Revision 1.5 2000/07/03 09:03:14 ivan +# added sendmailrestart and sendmailconfigpath config files +# +# Revision 1.4 2000/06/29 14:02:29 ivan +# add sendmailrestart configuration file +# +# Revision 1.3 2000/06/12 08:37:56 ivan +# sendmail fix from Jeff Finucane +# +# 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; -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: $!"; - =~ /^([\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 $_ !~ /^(#|$)/, ; - close QMAILMACHINES; +$conf = new FS::Conf; + +my($shellmachine, @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 $_ !~ /^(#|$)/, ; - close SENDMAILMACHINES; +my(@sendmailmachines, $sendmailconfigpath, $sendmailrestart); +if ( $conf->exists('sendmailmachines') ) { + @sendmailmachines = $conf->config('sendmailmachines'); + $sendmailconfigpath = $conf->config('sendmailconfigpath') || '/etc'; + $sendmailrestart = $conf->config('sendmailrestart'); } -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 $_ !~ /^(#|$)/, ; -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: $!"; @@ -97,8 +112,6 @@ unless ( flock(EXPORT,LOCK_EX|LOCK_NB) ) { seek(EXPORT,0,0); print EXPORT $$,"\n"; -my(@svc_acct_sm)=qsearch('svc_acct_sm',{}); - ( open(RCPTHOSTS,">$spooldir/rcpthosts") and flock(RCPTHOSTS,LOCK_EX|LOCK_NB) ) or die "Can't open $spooldir/rcpthosts: $!"; @@ -136,6 +149,11 @@ foreach $svc_acct_sm ( qsearch('svc_acct_sm') ) { ); my($domain)=$domain{$domsvc}; my($svc_acct)=qsearchs('svc_acct',{'uid'=>$domuid}); + unless ( $svc_acct ) { + warn "WARNING: couldn't find svc_acct.uid $domuid (svc_acct_sm.svcnum ". + $svc_acct_sm->svcnum. ") - corruped database?\n"; + next; + } my($username,$dir,$uid,$gid)=( $svc_acct->username, $svc_acct->dir, @@ -160,10 +178,10 @@ foreach $svc_acct_sm ( qsearch('svc_acct_sm') ) { print RECIPIENTMAP "$domuser\@$domain:$username\@$mydomain\n"; } - print VIRTUSERTABLE @sendmail; - } +print VIRTUSERTABLE @sendmail; + chmod 0644, "$spooldir/sendmail.cw", "$spooldir/virtusertable", "$spooldir/rcpthosts", @@ -189,15 +207,15 @@ close VIRTUALDOMAINS; my($sendmailmachine); foreach $sendmailmachine (@sendmailmachines) { - scp("$spooldir/sendmail.cw","root\@$sendmailmachine:/etc/sendmail.cw.new") + scp("$spooldir/sendmail.cw","root\@$sendmailmachine:$sendmailconfigpath/sendmail.cw.new") == 0 or die "scp error: $!"; - scp("$spooldir/virtusertable","root\@$sendmailmachine:/etc/virtusertable.new") + scp("$spooldir/virtusertable","root\@$sendmailmachine:$sendmailconfigpath/virtusertable.new") == 0 or die "scp error: $!"; ssh("root\@$sendmailmachine", "( ". - "mv /etc/sendmail.cw.new /etc/sendmail.cw; ". - "mv /etc/virtusertable.new /etc/virtusertable; ". - #"/etc/init.d/sendmail restart; ". + "mv $sendmailconfigpath/sendmail.cw.new $sendmailconfigpath/sendmail.cw; ". + "mv $sendmailconfigpath/virtusertable.new $sendmailconfigpath/virtusertable; ". + $sendmailrestart. " )" ) == 0 or die "ssh error: $!"; @@ -219,3 +237,9 @@ unlink $spoollock; flock(EXPORT,LOCK_UN); close EXPORT; +# + +sub usage { + die "Usage:\n\n svc_acct.export user\n"; +} +