1 package FS::svc_forward;
4 use vars qw( @ISA $nossh_hack $conf $shellmachine @qmailmachines @vpopmailmachines);
5 use FS::Record qw( fields qsearch qsearchs );
13 @ISA = qw( FS::svc_Common );
15 #ask FS::UID to run this stuff for us later
16 $FS::UID::callback{'FS::svc_forward'} = sub {
18 $shellmachine = $conf->exists('qmailmachines')
19 ? $conf->config('shellmachine')
21 if ( $conf->exists('vpopmailmachines') ) {
22 @vpopmailmachines = $conf->config('vpopmailmachines');
28 FS::svc_forward - Object methods for svc_forward records
34 $record = new FS::svc_forward \%hash;
35 $record = new FS::svc_forward { 'column' => 'value' };
37 $error = $record->insert;
39 $error = $new_record->replace($old_record);
41 $error = $record->delete;
43 $error = $record->check;
45 $error = $record->suspend;
47 $error = $record->unsuspend;
49 $error = $record->cancel;
53 An FS::svc_forward object represents a mail forwarding alias. FS::svc_forward
54 inherits from FS::Record. The following fields are currently supported:
58 =item svcnum - primary key (assigned automatcially for new accounts)
60 =item srcsvc - svcnum of the source of the forward (see L<FS::svc_acct>)
62 =item dstsvc - svcnum of the destination of the forward (see L<FS::svc_acct>)
64 =item dst - foreign destination (email address) - forward not local to freeside
74 Creates a new mail forwarding alias. To add the mail forwarding alias to the
75 database, see L<"insert">.
79 sub table { 'svc_forward'; }
83 Adds this mail forwarding alias to the database. If there is an error, returns
84 the error, otherwise returns false.
86 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
87 defined. An FS::cust_svc record will be created and inserted.
89 If the configuration values (see L<FS::Conf>) vpopmailmachines exist, then
92 [ -d /home/vpopmail/$vdomain/$source ] || {
93 echo "$destination" >> /home/vpopmail/$vdomain/$source/.$qmail
94 chown $vpopuid:$vpopgid /home/vpopmail/$vdomain/$source/.$qmail
97 is executed on each vpopmailmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
98 This behaviour can be surpressed by setting $FS::svc_forward::nossh_hack true.
106 local $SIG{HUP} = 'IGNORE';
107 local $SIG{INT} = 'IGNORE';
108 local $SIG{QUIT} = 'IGNORE';
109 local $SIG{TERM} = 'IGNORE';
110 local $SIG{TSTP} = 'IGNORE';
111 local $SIG{PIPE} = 'IGNORE';
114 return $error if $error;
116 $error = $self->SUPER::insert;
117 return $error if $error;
119 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->srcsvc } );
120 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } );
121 my $source = $svc_acct->username . $svc_domain->domain;
124 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->dstsvc } );
125 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } );
126 $destination = $svc_acct->username . $svc_domain->domain;
128 $destination = $self->dst;
131 my $vdomain = $svc_acct->domain;
133 foreach my $vpopmailmachine ( @vpopmailmachines ) {
134 my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachine);
136 ssh("root\@$machine","[ -d $vpopdir/$vdomain/$source ] || { echo $destination >> $vpopdir/$vdomain/$source/.qmail; chown $vpopuid:$vpopgid $vpopdir/$vdomain/$source/.qmail; }")
137 if ( ! $nossh_hack && $machine);
146 Deletes this mail forwarding alias from the database. If there is an error,
147 returns the error, otherwise returns false.
149 The corresponding FS::cust_svc record will be deleted as well.
151 =item replace OLD_RECORD
153 Replaces OLD_RECORD with this one in the database. If there is an error,
154 returns the error, otherwise returns false.
159 my ( $new, $old ) = ( shift, shift );
162 $new->SUPER::replace($old);
168 Just returns false (no error) for now.
170 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
174 Just returns false (no error) for now.
176 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
180 Just returns false (no error) for now.
182 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
186 Checks all fields to make sure this is a valid mail forwarding alias. If there
187 is an error, returns the error, otherwise returns false. Called by the insert
190 Sets any fixed values; see L<FS::part_svc>.
198 my $x = $self->setfixed;
199 return $x unless ref($x);
202 my($recref) = $self->hashref;
204 $recref->{srcsvc} =~ /^(\d+)$/ or return "Illegal srcsvc";
205 $recref->{srcsvc} = $1;
207 return "Unknown srcsvc" unless
208 $svc_acct=qsearchs('svc_acct',{'svcnum'=> $recref->{srcsvc} } );
210 return "Illegal use of dstsvc and dst" if
211 ($recref->{dstsvc} && $recref->{dst});
213 return "Illegal use of dstsvc and dst" if
214 (! $recref->{dstsvc} && ! $recref->{dst});
216 $recref->{dstsvc} =~ /^(\d+)$/ or return "Illegal dstsvc";
217 $recref->{dstsvc} = $1;
219 if ($recref->{dstsvc}) {
221 return "Unknown dstsvc" unless
222 my $svc_domain=qsearchs('svc_acct',{'svcnum'=> $recref->{dstsvc} } );
225 if ($recref->{dst}) {
226 $recref->{dst} =~ /^([\w\.\-]+)\@(([\w\.\-]+\.)+\w+)$/
227 or return "Illegal dst";
237 $Id: svc_forward.pm,v 1.3 2001-08-19 15:53:35 jeff Exp $
241 The remote commands should be configurable.
243 The $recref stuff in sub check should be cleaned up.
247 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
248 L<FS::svc_acct>, L<FS::svc_domain>, L<Net::SSH>, L<ssh>, L<dot-qmail>,
249 schema.html from the base documentation.