1 package FS::svc_forward;
4 use vars qw( @ISA $nossh_hack $conf $shellmachine @qmailmachines
8 use FS::Record qw( fields qsearch qsearchs );
14 @ISA = qw( FS::svc_Common );
16 #ask FS::UID to run this stuff for us later
17 $FS::UID::callback{'FS::svc_forward'} = sub {
19 if ( $conf->exists('qmailmachines') ) {
20 $shellmachine = $conf->config('shellmachine')
24 if ( $conf->exists('vpopmailmachines') ) {
25 @vpopmailmachines = $conf->config('vpopmailmachines');
27 @vpopmailmachines = ();
33 FS::svc_forward - Object methods for svc_forward records
39 $record = new FS::svc_forward \%hash;
40 $record = new FS::svc_forward { 'column' => 'value' };
42 $error = $record->insert;
44 $error = $new_record->replace($old_record);
46 $error = $record->delete;
48 $error = $record->check;
50 $error = $record->suspend;
52 $error = $record->unsuspend;
54 $error = $record->cancel;
58 An FS::svc_forward object represents a mail forwarding alias. FS::svc_forward
59 inherits from FS::Record. The following fields are currently supported:
63 =item svcnum - primary key (assigned automatcially for new accounts)
65 =item srcsvc - svcnum of the source of the forward (see L<FS::svc_acct>)
67 =item dstsvc - svcnum of the destination of the forward (see L<FS::svc_acct>)
69 =item dst - foreign destination (email address) - forward not local to freeside
79 Creates a new mail forwarding alias. To add the mail forwarding alias to the
80 database, see L<"insert">.
84 sub table { 'svc_forward'; }
88 Adds this mail forwarding alias to the database. If there is an error, returns
89 the error, otherwise returns false.
91 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
92 defined. An FS::cust_svc record will be created and inserted.
94 If the configuration values (see L<FS::Conf>) vpopmailmachines exist, then
97 [ -d /home/vpopmail/$vdomain/$source ] || {
98 echo "$destination" >> /home/vpopmail/$vdomain/$source/.$qmail
99 chown $vpopuid:$vpopgid /home/vpopmail/$vdomain/$source/.$qmail
102 is executed on each vpopmailmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
103 This behaviour can be surpressed by setting $FS::svc_forward::nossh_hack true.
111 local $SIG{HUP} = 'IGNORE';
112 local $SIG{INT} = 'IGNORE';
113 local $SIG{QUIT} = 'IGNORE';
114 local $SIG{TERM} = 'IGNORE';
115 local $SIG{TSTP} = 'IGNORE';
116 local $SIG{PIPE} = 'IGNORE';
119 return $error if $error;
121 $error = $self->SUPER::insert;
122 return $error if $error;
124 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->srcsvc } );
125 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } );
126 my $source = $svc_acct->username . $svc_domain->domain;
129 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->dstsvc } );
130 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $svc_acct->domsvc } );
131 $destination = $svc_acct->username . $svc_domain->domain;
133 $destination = $self->dst;
136 my $vdomain = $svc_acct->domain;
138 foreach my $vpopmailmachine ( @vpopmailmachines ) {
139 my ($machine, $vpopdir, $vpopuid, $vpopgid) = split (/\s+/, $vpopmailmachine);
141 ssh("root\@$machine","[ -d $vpopdir/$vdomain/$source ] || { echo $destination >> $vpopdir/$vdomain/$source/.qmail; chown $vpopuid:$vpopgid $vpopdir/$vdomain/$source/.qmail; }")
142 if ( ! $nossh_hack && $machine);
151 Deletes this mail forwarding alias from the database. If there is an error,
152 returns the error, otherwise returns false.
154 The corresponding FS::cust_svc record will be deleted as well.
156 =item replace OLD_RECORD
158 Replaces OLD_RECORD with this one in the database. If there is an error,
159 returns the error, otherwise returns false.
164 my ( $new, $old ) = ( shift, shift );
167 $new->SUPER::replace($old);
173 Just returns false (no error) for now.
175 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
179 Just returns false (no error) for now.
181 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
185 Just returns false (no error) for now.
187 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
191 Checks all fields to make sure this is a valid mail forwarding alias. If there
192 is an error, returns the error, otherwise returns false. Called by the insert
195 Sets any fixed values; see L<FS::part_svc>.
203 my $x = $self->setfixed;
204 return $x unless ref($x);
207 my($recref) = $self->hashref;
209 $recref->{srcsvc} =~ /^(\d+)$/ or return "Illegal srcsvc";
210 $recref->{srcsvc} = $1;
212 return "Unknown srcsvc" unless
213 $svc_acct=qsearchs('svc_acct',{'svcnum'=> $recref->{srcsvc} } );
215 return "Illegal use of dstsvc and dst" if
216 ($recref->{dstsvc} && $recref->{dst});
218 return "Illegal use of dstsvc and dst" if
219 (! $recref->{dstsvc} && ! $recref->{dst});
221 $recref->{dstsvc} =~ /^(\d+)$/ or return "Illegal dstsvc";
222 $recref->{dstsvc} = $1;
224 if ($recref->{dstsvc}) {
226 return "Unknown dstsvc" unless
227 my $svc_domain=qsearchs('svc_acct',{'svcnum'=> $recref->{dstsvc} } );
230 if ($recref->{dst}) {
231 $recref->{dst} =~ /^([\w\.\-]+)\@(([\w\.\-]+\.)+\w+)$/
232 or return "Illegal dst";
242 $Id: svc_forward.pm,v 1.4 2001-08-20 09:41:52 ivan Exp $
246 The remote commands should be configurable.
248 The $recref stuff in sub check should be cleaned up.
252 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
253 L<FS::svc_acct>, L<FS::svc_domain>, L<Net::SSH>, L<ssh>, L<dot-qmail>,
254 schema.html from the base documentation.