diff options
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/svc_acct.pm | 12 | ||||
-rw-r--r-- | FS/FS/svc_domain.pm | 5 | ||||
-rw-r--r-- | FS/FS/svc_forward.pm | 255 |
3 files changed, 269 insertions, 3 deletions
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index 0e0c88541..68869c1a5 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -82,6 +82,10 @@ FS::svc_acct - Object methods for svc_acct records %hash = $record->radius; + %hash = $record->radius_reply; + + %hash = $record->radius_check; + =head1 DESCRIPTION An FS::svc_acct object represents an account. FS::svc_acct inherits from @@ -113,6 +117,8 @@ FS::svc_Common. The following fields are currently supported: =item radius_I<Radius_Attribute> - I<Radius-Attribute> +=item domsvc - service number of svc_domain with which to associate + =back =head1 METHODS @@ -169,7 +175,9 @@ sub insert { return $error if $error; return "Username ". $self->username. " in use" - if qsearchs( 'svc_acct', { 'username' => $self->username } ); + if qsearchs( 'svc_acct', { 'username' => $self->username, + 'domsvc' => $self->domsvc, + } ); my $part_svc = qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); return "Unknown svcpart" unless $part_svc; @@ -542,7 +550,7 @@ sub radius_check { =head1 VERSION -$Id: svc_acct.pm,v 1.17 2001-06-03 12:36:10 ivan Exp $ +$Id: svc_acct.pm,v 1.17.2.1 2001-08-08 17:45:34 jeff Exp $ =head1 BUGS diff --git a/FS/FS/svc_domain.pm b/FS/FS/svc_domain.pm index 01aa21a6c..d74049b9d 100644 --- a/FS/FS/svc_domain.pm +++ b/FS/FS/svc_domain.pm @@ -336,6 +336,9 @@ sub check { $recref->{action} =~ /^(M|N)$/ or return "Illegal action"; $recref->{action} = $1; + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $recref->{catchall} } ); + return "Unknown catchall" unless $svc_acct || ! $recref->{catchall}; + $self->ut_textn('purpose'); } @@ -478,7 +481,7 @@ sub submit_internic { =head1 VERSION -$Id: svc_domain.pm,v 1.12 2001-06-03 17:22:52 ivan Exp $ +$Id: svc_domain.pm,v 1.12.2.1 2001-08-08 17:45:35 jeff Exp $ =head1 BUGS diff --git a/FS/FS/svc_forward.pm b/FS/FS/svc_forward.pm new file mode 100644 index 000000000..5e496b120 --- /dev/null +++ b/FS/FS/svc_forward.pm @@ -0,0 +1,255 @@ +package FS::svc_forward; + +use strict; +use vars qw( @ISA $nossh_hack $conf $shellmachine @qmailmachines @vpopmailmachines); +use FS::Record qw( fields qsearch qsearchs ); +use FS::svc_Common; +use FS::cust_svc; +use Net::SSH qw(ssh); +use FS::Conf; +use FS::svc_acct; +use FS::svc_domain; + +@ISA = qw( FS::svc_Common ); + +#ask FS::UID to run this stuff for us later +$FS::UID::callback{'FS::svc_forward'} = sub { + $conf = new FS::Conf; + $shellmachine = $conf->exists('qmailmachines') + ? $conf->config('shellmachine') + : ''; + if ( $conf->exists('vpopmailmachines') ) { + @vpopmailmachines = $conf->config('vpopmailmachines'); + } +}; + +=head1 NAME + +FS::svc_forward - Object methods for svc_forward records + +=head1 SYNOPSIS + + use FS::svc_forward; + + $record = new FS::svc_forward \%hash; + $record = new FS::svc_forward { 'column' => 'value' }; + + $error = $record->insert; + + $error = $new_record->replace($old_record); + + $error = $record->delete; + + $error = $record->check; + + $error = $record->suspend; + + $error = $record->unsuspend; + + $error = $record->cancel; + +=head1 DESCRIPTION + +An FS::svc_forward object represents a mail forwarding alias. FS::svc_forward +inherits from FS::Record. The following fields are currently supported: + +=over 4 + +=item svcnum - primary key (assigned automatcially for new accounts) + +=item srcsvc - svcnum of the source of the forward (see L<FS::svc_acct>) + +=item dstsvc - svcnum of the destination of the forward (see L<FS::svc_acct>) + +=item dst - foreign destination (email address) - forward not local to freeside + +=back + +=head1 METHODS + +=over 4 + +=item new HASHREF + +Creates a new mail forwarding alias. To add the mail forwarding alias to the +database, see L<"insert">. + +=cut + +sub table { 'svc_forward'; } + +=item insert + +Adds this mail forwarding alias to the database. If there is an error, returns +the error, otherwise returns false. + +The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be +defined. An FS::cust_svc record will be created and inserted. + +If the configuration values (see L<FS::Conf>) vpopmailmachines exist, then +the command: + + [ -d /home/vpopmail/$vdomain/$source ] || { + echo "$destination" >> /home/vpopmail/$vdomain/$source/.$qmail + chown $vpopuid:$vpopgid /home/vpopmail/$vdomain/$source/.$qmail + } + +is executed on each vpopmailmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">). +This behaviour can be surpressed by setting $FS::svc_forward::nossh_hack true. + +=cut + +sub insert { + my $self = shift; + my $error; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + $error=$self->check; + return $error if $error; + + $error = $self->SUPER::insert; + return $error if $error; + + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->srcsvc } ); + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } ); + my $source = $svc_acct->username . $svc_domain->domain; + my $destination; + if ($self->dstdvc) { + my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->dstsvc } ); + my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } ); + $destination = $svc_acct->username . $svc_domain->domain; + } else { + $destination = $self->dst; + } + + my $vdomain = $svc_acct->domain; + + foreach my $vpopmailmachine ( @vpopmailmachines ) { + my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachine); + + ssh("root\@$machine","[ -d $vpopdir/$vdomain/$source ] || { echo $destination >> $vpopdir/$vdomain/$source/.qmail; chown $vpopuid:$vpopgid $vpopdir/$vdomain/$source/.qmail; }") + if ( ! $nossh_hack && $machine); + } + + ''; #no error + +} + +=item delete + +Deletes this mail forwarding alias from the database. If there is an error, +returns the error, otherwise returns false. + +The corresponding FS::cust_svc record will be deleted as well. + +=item replace OLD_RECORD + +Replaces OLD_RECORD with this one in the database. If there is an error, +returns the error, otherwise returns false. + +=cut + +sub replace { + my ( $new, $old ) = ( shift, shift ); + my $error; + + $new->SUPER::replace($old); + +} + +=item suspend + +Just returns false (no error) for now. + +Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>). + +=item unsuspend + +Just returns false (no error) for now. + +Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>). + +=item cancel + +Just returns false (no error) for now. + +Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>). + +=item check + +Checks all fields to make sure this is a valid mail forwarding alias. If there +is an error, returns the error, otherwise returns false. Called by the insert +and replace methods. + +Sets any fixed values; see L<FS::part_svc>. + +=cut + +sub check { + my $self = shift; + my $error; + + my $x = $self->setfixed; + return $x unless ref($x); + my $part_svc = $x; + + my($recref) = $self->hashref; + + $recref->{srcsvc} =~ /^(\d+)$/ or return "Illegal srcsvc"; + $recref->{srcsvc} = $1; + my($svc_acct); + return "Unknown srcsvc" unless + $svc_acct=qsearchs('svc_acct',{'svcnum'=> $recref->{srcsvc} } ); + + return "Illegal use of dstsvc and dst" if + ($recref->{dstsvc} && $recref->{dst}); + + return "Illegal use of dstsvc and dst" if + (! $recref->{dstsvc} && ! $recref->{dst}); + + $recref->{dstsvc} =~ /^(\d+)$/ or return "Illegal dstsvc"; + $recref->{dstsvc} = $1; + + if ($recref->{dstsvc}) { + my($svc_acct); + return "Unknown dstsvc" unless + my $svc_domain=qsearchs('svc_acct',{'svcnum'=> $recref->{dstsvc} } ); + } + + if ($recref->{dst}) { + $recref->{dst} =~ /^(\w\.\-]+)\@(([\w\.\-]+\.)+\w+)$/ + or return "Illegal dst"; + $recref->{dst} = $1; + } + + ''; #no error +} + +=back + +=head1 VERSION + +$Id: svc_forward.pm,v 1.1.2.1 2001-08-08 17:45:35 jeff Exp $ + +=head1 BUGS + +The remote commands should be configurable. + +The $recref stuff in sub check should be cleaned up. + +=head1 SEE ALSO + +L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>, +L<FS::svc_acct>, L<FS::svc_domain>, L<Net::SSH>, L<ssh>, L<dot-qmail>, +schema.html from the base documentation. + +=cut + +1; + |