1 package FS::svc_acct_sm;
4 use vars qw( @ISA $nossh_hack $conf $shellmachine @qmailmachines );
5 use FS::Record qw( fields qsearch qsearchs );
11 @ISA = qw( FS::svc_Common );
13 #ask FS::UID to run this stuff for us later
14 $FS::UID::callback{'FS::svc_acct_sm'} = sub {
16 $shellmachine = $conf->exists('qmailmachines')
17 ? $conf->config('shellmachine')
23 FS::svc_acct_sm - Object methods for svc_acct_sm records
29 $record = new FS::svc_acct_sm \%hash;
30 $record = new FS::svc_acct_sm { 'column' => 'value' };
32 $error = $record->insert;
34 $error = $new_record->replace($old_record);
36 $error = $record->delete;
38 $error = $record->check;
40 $error = $record->suspend;
42 $error = $record->unsuspend;
44 $error = $record->cancel;
48 An FS::svc_acct object represents a virtual mail alias. FS::svc_acct inherits
49 from FS::Record. The following fields are currently supported:
53 =item svcnum - primary key (assigned automatcially for new accounts)
55 =item domsvc - svcnum of the virtual domain (see L<FS::svc_domain>)
57 =item domuid - uid of the target account (see L<FS::svc_acct>)
59 =item domuser - virtual username
69 Creates a new virtual mail alias. To add the virtual mail alias to the
70 database, see L<"insert">.
74 sub table { 'svc_acct_sm'; }
78 Adds this virtual mail alias to the database. If there is an error, returns
79 the error, otherwise returns false.
81 The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
82 defined. An FS::cust_svc record will be created and inserted.
84 If the configuration values (see L<FS::Conf>) shellmachine and qmailmachines
85 exist, and domuser is `*' (meaning a catch-all mailbox), the command:
87 [ -e $dir/.qmail-$qdomain-default ] || {
88 touch $dir/.qmail-$qdomain-default;
89 chown $uid:$gid $dir/.qmail-$qdomain-default;
92 is executed on shellmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
93 This behaviour can be surpressed by setting $FS::svc_acct_sm::nossh_hack true.
101 local $SIG{HUP} = 'IGNORE';
102 local $SIG{INT} = 'IGNORE';
103 local $SIG{QUIT} = 'IGNORE';
104 local $SIG{TERM} = 'IGNORE';
105 local $SIG{TSTP} = 'IGNORE';
108 return $error if $error;
110 return "Domain username (domuser) in use for this domain (domsvc)"
111 if qsearchs('svc_acct_sm',{ 'domuser'=> $self->domuser,
112 'domsvc' => $self->domsvc,
115 return "First domain username (domuser) for domain (domsvc) must be " .
117 if $self->domuser ne '*' &&
118 ! qsearch('svc_acct_sm',{ 'domsvc' => $self->domsvc } );
120 $error = $self->SUPER::insert;
121 return $error if $error;
123 my $svc_domain = qsearchs( 'svc_domain', { 'svcnum' => $self->domsvc } );
124 my $svc_acct = qsearchs( 'svc_acct', { 'uid' => $self->domuid } );
125 my ( $uid, $gid, $dir, $domain ) = (
131 my $qdomain = $domain;
132 $qdomain =~ s/\./:/g; #see manpage for 'dot-qmail': EXTENSION ADDRESSES
133 ssh("root\@$shellmachine","[ -e $dir/.qmail-$qdomain-default ] || { touch $dir/.qmail-$qdomain-default; chown $uid:$gid $dir/.qmail-$qdomain-default; }")
134 if ( ! $nossh_hack && $shellmachine && $dir && $self->domuser eq '*' );
142 Deletes this virtual mail alias from the database. If there is an error,
143 returns the error, otherwise returns false.
145 The corresponding FS::cust_svc record will be deleted as well.
147 =item replace OLD_RECORD
149 Replaces OLD_RECORD with this one in the database. If there is an error,
150 returns the error, otherwise returns false.
155 my ( $new, $old ) = ( shift, shift );
158 return "Domain username (domuser) in use for this domain (domsvc)"
159 if ( $old->domuser ne $new->domuser
160 || $old->domsvc != $new->domsvc
161 ) && qsearchs('svc_acct_sm',{
162 'domuser'=> $new->domuser,
163 'domsvc' => $new->domsvc,
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 virtual mail alias. If there is
192 an error, returns the error, otherwise returns false. Called by the insert and
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->{domuser} =~ /^(\*|[a-z0-9_\-]{2,32})$/
210 or return "Illegal domain username (domuser)";
211 $recref->{domuser} = $1;
213 $recref->{domsvc} =~ /^(\d+)$/ or return "Illegal domsvc";
214 $recref->{domsvc} = $1;
216 return "Unknown domsvc" unless
217 $svc_domain=qsearchs('svc_domain',{'svcnum'=> $recref->{domsvc} } );
219 $recref->{domuid} =~ /^(\d+)$/ or return "Illegal uid";
220 $recref->{domuid} = $1;
222 return "Unknown uid" unless
223 $svc_acct=qsearchs('svc_acct',{'uid'=> $recref->{domuid} } );
232 $Id: svc_acct_sm.pm,v 1.5 1999-01-18 21:58:10 ivan Exp $
236 The remote commands should be configurable.
238 The $recref stuff in sub check should be cleaned up.
242 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
243 L<FS::svc_acct>, L<FS::svc_domain>, L<FS::SSH>, L<ssh>, L<dot-qmail>,
244 schema.html from the base documentation.
248 ivan@voicenet.com 97-jul-16 - 21
250 rewrite ivan@sisd.com 98-mar-10
252 s/qsearchs/qsearch/ to eliminate warning ivan@sisd.com 98-apr-19
254 uses conf/shellmachine and has an nossh_hack ivan@sisd.com 98-jul-14
256 s/\./:/g in .qmail-domain:com ivan@sisd.com 98-aug-13
258 pod, FS::Conf, moved .qmail file from check to insert 98-sep-23