1 package FS::svc_acct_sm;
4 use vars qw( @ISA $nossh_hack $conf $shellmachine @qmailmachines );
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_acct_sm'} = sub {
18 $shellmachine = $conf->exists('qmailmachines')
19 ? $conf->config('shellmachine')
25 FS::svc_acct_sm - Object methods for svc_acct_sm records
31 $record = new FS::svc_acct_sm \%hash;
32 $record = new FS::svc_acct_sm { 'column' => 'value' };
34 $error = $record->insert;
36 $error = $new_record->replace($old_record);
38 $error = $record->delete;
40 $error = $record->check;
42 $error = $record->suspend;
44 $error = $record->unsuspend;
46 $error = $record->cancel;
50 An FS::svc_acct object represents a virtual mail alias. FS::svc_acct inherits
51 from FS::Record. The following fields are currently supported:
55 =item svcnum - primary key (assigned automatcially for new accounts)
57 =item domsvc - svcnum of the virtual domain (see L<FS::svc_domain>)
59 =item domuid - uid of the target account (see L<FS::svc_acct>)
61 =item domuser - virtual username
71 Creates a new virtual mail alias. To add the virtual mail alias to the
72 database, see L<"insert">.
76 sub table { 'svc_acct_sm'; }
80 Adds this virtual mail alias to the database. If there is an error, returns
81 the error, otherwise returns false.
83 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
84 defined. An FS::cust_svc record will be created and inserted.
86 If the configuration values (see L<FS::Conf>) shellmachine and qmailmachines
87 exist, and domuser is `*' (meaning a catch-all mailbox), the command:
89 [ -e $dir/.qmail-$qdomain-default ] || {
90 touch $dir/.qmail-$qdomain-default;
91 chown $uid:$gid $dir/.qmail-$qdomain-default;
94 is executed on shellmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
95 This behaviour can be surpressed by setting $FS::svc_acct_sm::nossh_hack true.
103 local $SIG{HUP} = 'IGNORE';
104 local $SIG{INT} = 'IGNORE';
105 local $SIG{QUIT} = 'IGNORE';
106 local $SIG{TERM} = 'IGNORE';
107 local $SIG{TSTP} = 'IGNORE';
108 local $SIG{PIPE} = 'IGNORE';
111 return $error if $error;
113 return "Domain username (domuser) in use for this domain (domsvc)"
114 if qsearchs('svc_acct_sm',{ 'domuser'=> $self->domuser,
115 'domsvc' => $self->domsvc,
118 return "First domain username (domuser) for domain (domsvc) must be " .
120 if $self->domuser ne '*' &&
121 ! qsearch('svc_acct_sm',{ 'domsvc' => $self->domsvc } );
123 $error = $self->SUPER::insert;
124 return $error if $error;
126 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
127 my $svc_acct = qsearchs( 'svc_acct', { 'uid' => $self->domuid } );
128 my ( $uid, $gid, $dir, $domain ) = (
134 my $qdomain = $domain;
135 $qdomain =~ s/\./:/g; #see manpage for 'dot-qmail': EXTENSION ADDRESSES
136 ssh("root\@$shellmachine","[ -e $dir/.qmail-$qdomain-default ] || { touch $dir/.qmail-$qdomain-default; chown $uid:$gid $dir/.qmail-$qdomain-default; }")
137 if ( ! $nossh_hack && $shellmachine && $dir && $self->domuser eq '*' );
145 Deletes this virtual mail alias from the database. If there is an error,
146 returns the error, otherwise returns false.
148 The corresponding FS::cust_svc record will be deleted as well.
150 =item replace OLD_RECORD
152 Replaces OLD_RECORD with this one in the database. If there is an error,
153 returns the error, otherwise returns false.
158 my ( $new, $old ) = ( shift, shift );
161 return "Domain username (domuser) in use for this domain (domsvc)"
162 if ( $old->domuser ne $new->domuser
163 || $old->domsvc != $new->domsvc
164 ) && qsearchs('svc_acct_sm',{
165 'domuser'=> $new->domuser,
166 'domsvc' => $new->domsvc,
170 $new->SUPER::replace($old);
176 Just returns false (no error) for now.
178 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
182 Just returns false (no error) for now.
184 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
188 Just returns false (no error) for now.
190 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
194 Checks all fields to make sure this is a valid virtual mail alias. If there is
195 an error, returns the error, otherwise returns false. Called by the insert and
198 Sets any fixed values; see L<FS::part_svc>.
206 my $x = $self->setfixed;
207 return $x unless ref($x);
210 my($recref) = $self->hashref;
212 $recref->{domuser} =~ /^(\*|[a-z0-9_\-]{2,32})$/
213 or return "Illegal domain username (domuser)";
214 $recref->{domuser} = $1;
216 $recref->{domsvc} =~ /^(\d+)$/ or return "Illegal domsvc";
217 $recref->{domsvc} = $1;
219 return "Unknown domsvc" unless
220 $svc_domain=qsearchs('svc_domain',{'svcnum'=> $recref->{domsvc} } );
222 $recref->{domuid} =~ /^(\d+)$/ or return "Illegal uid";
223 $recref->{domuid} = $1;
225 return "Unknown uid" unless
226 $svc_acct=qsearchs('svc_acct',{'uid'=> $recref->{domuid} } );
235 $Id: svc_acct_sm.pm,v 1.1 1999-08-04 09:03:53 ivan Exp $
239 The remote commands should be configurable.
241 The $recref stuff in sub check should be cleaned up.
245 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
246 L<FS::svc_acct>, L<FS::svc_domain>, L<FS::SSH>, L<ssh>, L<dot-qmail>,
247 schema.html from the base documentation.