1 package FS::svc_acct_sm;
4 use vars qw(@ISA @EXPORT_OK $nossh_hack $conf $shellmachine @qmailmachines);
6 use FS::Record qw(fields qsearch qsearchs);
11 @ISA = qw(FS::Record Exporter);
12 @EXPORT_OK = qw(fields);
16 $shellmachine = $conf->exists('qmailmachines')
17 ? $conf->config('shellmachine')
22 FS::svc_acct_sm - Object methods for svc_acct_sm records
28 $record = create FS::svc_acct_sm \%hash;
29 $record = create FS::svc_acct_sm { 'column' => 'value' };
31 $error = $record->insert;
33 $error = $new_record->replace($old_record);
35 $error = $record->delete;
37 $error = $record->check;
39 $error = $record->suspend;
41 $error = $record->unsuspend;
43 $error = $record->cancel;
47 An FS::svc_acct object represents a virtual mail alias. FS::svc_acct inherits
48 from FS::Record. The following fields are currently supported:
52 =item svcnum - primary key (assigned automatcially for new accounts)
54 =item domsvc - svcnum of the virtual domain (see L<FS::svc_domain>)
56 =item domuid - uid of the target account (see L<FS::svc_acct>)
58 =item domuser - virtual username
68 Creates a new virtual mail alias. To add the virtual mail alias to the
69 database, see L<"insert">.
74 my($proto,$hashref)=@_;
76 #now in FS::Record::new
78 #foreach $field (fields('svc_acct_sm')) {
79 # $hashref->{$field}='' unless defined $hashref->{$field};
82 $proto->new('svc_acct_sm',$hashref);
88 Adds this virtual mail 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>) shellmachine and qmailmachines
95 exist, and domuser is `*' (meaning a catch-all mailbox), the command:
97 [ -e $dir/.qmail-$qdomain-default ] || {
98 touch $dir/.qmail-$qdomain-default;
99 chown $uid:$gid $dir/.qmail-$qdomain-default;
102 is executed on shellmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
103 This behaviour can be surpressed by setting $FS::svc_acct_sm::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';
118 return $error if $error;
120 return "Domain username (domuser) in use for this domain (domsvc)"
121 if qsearchs('svc_acct_sm',{ 'domuser'=> $self->domuser,
122 'domsvc' => $self->domsvc,
125 return "First domain username (domuser) for domain (domsvc) must be " .
127 if $self->domuser ne '*' &&
128 ! qsearch('svc_acct_sm',{ 'domsvc' => $self->domsvc } );
130 my($svcnum)=$self->getfield('svcnum');
133 $cust_svc=create FS::cust_svc ( {
135 'pkgnum' => $self->getfield('pkgnum'),
136 'svcpart' => $self->getfield('svcpart'),
138 my($error) = $cust_svc->insert;
139 return $error if $error;
140 $svcnum = $self->setfield('svcnum',$cust_svc->getfield('svcnum'));
145 $cust_svc->del if $cust_svc;
149 my $svc_domain = qsearchs('svc_domain',{'svcnum'=> $self->domsvc } );
150 my $svc_acct = qsearchs('svc_acct',{'uid'=> $self->domuid } );
151 my($uid,$gid,$dir,$domain)=(
152 $svc_acct->getfield('uid'),
153 $svc_acct->getfield('gid'),
154 $svc_acct->getfield('dir'),
155 $svc_domain->getfield('domain')
157 my($qdomain)=$domain;
158 $qdomain =~ s/\./:/g; #see manpage for 'dot-qmail': EXTENSION ADDRESSES
159 ssh("root\@$shellmachine","[ -e $dir/.qmail-$qdomain-default ] || { touch $dir/.qmail-$qdomain-default; chown $uid:$gid $dir/.qmail-$qdomain-default; }")
160 if ( ! $nossh_hack && $shellmachine && $dir && $self->domuser eq '*' );
168 Deletes this virtual mail alias from the database. If there is an error,
169 returns the error, otherwise returns false.
171 The corresponding FS::cust_svc record will be deleted as well.
179 my($svcnum)=$self->getfield('svcnum');
182 return $error if $error;
184 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
185 $error = $cust_svc->del;
186 return $error if $error;
192 =item replace OLD_RECORD
194 Replaces OLD_RECORD with this one in the database. If there is an error,
195 returns the error, otherwise returns false.
203 return "(Old) Not a svc_acct_sm record!" unless $old->table eq "svc_acct_sm";
204 return "Can't change svcnum!"
205 unless $old->getfield('svcnum') eq $new->getfield('svcnum');
207 return "Domain username (domuser) in use for this domain (domsvc)"
208 if ( $old->domuser ne $new->domuser
209 || $old->domsvc ne $new->domsvc
210 ) && qsearchs('svc_acct_sm',{
211 'domuser'=> $new->domuser,
212 'domsvc' => $new->domsvc,
217 return $error if $error;
219 $error = $new->rep($old);
220 return $error if $error;
227 Just returns false (no error) for now.
229 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
239 Just returns false (no error) for now.
241 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
251 Just returns false (no error) for now.
253 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
263 Checks all fields to make sure this is a valid virtual mail alias. If there is
264 an error, returns the error, otherwise returns false. Called by the insert and
267 Sets any fixed values; see L<FS::part_svc>.
273 return "Not a svc_acct_sm record!" unless $self->table eq "svc_acct_sm";
274 my($recref) = $self->hashref;
276 $recref->{svcnum} =~ /^(\d*)$/ or return "Illegal svcnum";
277 $recref->{svcnum} = $1;
281 my($svcnum)=$self->getfield('svcnum');
283 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
284 return "Unknown svcnum" unless $cust_svc;
285 $svcpart=$cust_svc->svcpart;
287 $svcpart=$self->getfield('svcpart');
289 my($part_svc)=qsearchs('part_svc',{'svcpart'=>$svcpart});
290 return "Unkonwn svcpart" unless $part_svc;
292 #set fixed fields from part_svc
294 foreach $field ( fields('svc_acct_sm') ) {
295 if ( $part_svc->getfield('svc_acct_sm__'. $field. '_flag') eq 'F' ) {
296 $self->setfield($field,$part_svc->getfield('svc_acct_sm__'. $field) );
300 $recref->{domuser} =~ /^(\*|[a-z0-9_\-]{2,32})$/
301 or return "Illegal domain username (domuser)";
302 $recref->{domuser} = $1;
304 $recref->{domsvc} =~ /^(\d+)$/ or return "Illegal domsvc";
305 $recref->{domsvc} = $1;
307 return "Unknown domsvc" unless
308 $svc_domain=qsearchs('svc_domain',{'svcnum'=> $recref->{domsvc} } );
310 $recref->{domuid} =~ /^(\d+)$/ or return "Illegal uid";
311 $recref->{domuid} = $1;
313 return "Unknown uid" unless
314 $svc_acct=qsearchs('svc_acct',{'uid'=> $recref->{domuid} } );
323 It doesn't properly override FS::Record yet.
325 The remote commands should be configurable.
329 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
330 L<FS::svc_acct>, L<FS::svc_domain>, L<FS::SSH>, L<ssh>, L<dot-qmail>,
331 schema.html from the base documentation.
335 ivan@voicenet.com 97-jul-16 - 21
337 rewrite ivan@sisd.com 98-mar-10
339 s/qsearchs/qsearch/ to eliminate warning ivan@sisd.com 98-apr-19
341 uses conf/shellmachine and has an nossh_hack ivan@sisd.com 98-jul-14
343 s/\./:/g in .qmail-domain:com ivan@sisd.com 98-aug-13
345 pod, FS::Conf, moved .qmail file from check to insert 98-sep-23