1 package FS::svc_domain;
4 use vars qw( @ISA $whois_hack $conf $smtpmachine
5 @mxmachines @nsmachines $soadefaultttl $soaemail $soaexpire $soamachine
6 $soarefresh $soaretry $qshellmachine $nossh_hack
14 use FS::Record qw(fields qsearch qsearchs dbh);
21 use FS::domain_record;
23 @ISA = qw( FS::svc_Common );
25 #ask FS::UID to run this stuff for us later
26 $FS::UID::callback{'FS::domain'} = sub {
29 $smtpmachine = $conf->config('smtpmachine');
31 @mxmachines = $conf->config('mxmachines');
32 @nsmachines = $conf->config('nsmachines');
33 $soadefaultttl = $conf->config('soadefaultttl');
34 $soaemail = $conf->config('soaemail');
35 $soaexpire = $conf->config('soaexpire');
36 $soamachine = $conf->config('soamachine');
37 $soarefresh = $conf->config('soarefresh');
38 $soaretry = $conf->config('soaretry');
40 $qshellmachine = $conf->exists('qmailmachines')
41 ? $conf->config('shellmachine')
47 FS::svc_domain - Object methods for svc_domain records
53 $record = new FS::svc_domain \%hash;
54 $record = new FS::svc_domain { 'column' => 'value' };
56 $error = $record->insert;
58 $error = $new_record->replace($old_record);
60 $error = $record->delete;
62 $error = $record->check;
64 $error = $record->suspend;
66 $error = $record->unsuspend;
68 $error = $record->cancel;
72 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
73 FS::svc_Common. The following fields are currently supported:
77 =item svcnum - primary key (assigned automatically for new accounts)
81 =item catchall - optional svcnum of an svc_acct record, designating an email catchall account.
91 Creates a new domain. To add the domain to the database, see L<"insert">.
95 sub table { 'svc_domain'; }
99 Adds this domain to the database. If there is an error, returns the error,
100 otherwise returns false.
102 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
103 defined. An FS::cust_svc record will be created and inserted.
105 The additional field I<action> should be set to I<N> for new domains or I<M>
108 A registration or transfer email will be submitted unless
109 $FS::svc_domain::whois_hack is true.
111 The additional field I<email> can be used to manually set the admin contact
112 email address on this email. Otherwise, the svc_acct records for this package
113 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
114 in the same package, it is automatically used. Otherwise an error is returned.
116 If any I<soamachine> configuration file exists, an SOA record is added to
117 the domain_record table (see <FS::domain_record>).
119 If any machines are defined in the I<nsmachines> configuration file, NS
120 records are added to the domain_record table (see L<FS::domain_record>).
122 If any machines are defined in the I<mxmachines> configuration file, MX
123 records are added to the domain_record table (see L<FS::domain_record>).
125 If a machine is defined in the I<shellmachine> configuration value, the
126 I<qmailmachines> configuration file exists, and the I<catchall> field points
127 to an an account with a home directory (see L<FS::svc_acct>), the command:
129 [ -e $dir/.qmail-$qdomain-defualt ] || {
130 touch $dir/.qmail-$qdomain-default;
131 chown $uid:$gid $dir/.qmail-$qdomain-default;
134 is executed on shellmachine via ssh (see L<dot-qmail/"EXTENSION ADDRESSES">).
135 This behaviour can be supressed by setting $FS::svc_domain::nossh_hack true.
146 local $SIG{HUP} = 'IGNORE';
147 local $SIG{INT} = 'IGNORE';
148 local $SIG{QUIT} = 'IGNORE';
149 local $SIG{TERM} = 'IGNORE';
150 local $SIG{TSTP} = 'IGNORE';
151 local $SIG{PIPE} = 'IGNORE';
153 my $oldAutoCommit = $FS::UID::AutoCommit;
154 local $FS::UID::AutoCommit = 0;
157 $error = $self->check;
158 return $error if $error;
160 return "Domain in use (here)"
161 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
163 my $whois = $self->whois;
164 if ( $self->action eq "N" && ! $whois_hack && $whois ) {
165 $dbh->rollback if $oldAutoCommit;
166 return "Domain in use (see whois)";
168 if ( $self->action eq "M" && ! $whois ) {
169 $dbh->rollback if $oldAutoCommit;
170 return "Domain not found (see whois)";
173 $error = $self->SUPER::insert;
175 $dbh->rollback if $oldAutoCommit;
179 $self->submit_internic unless $whois_hack;
182 my $soa = new FS::domain_record {
183 'svcnum' => $self->svcnum,
187 'recdata' => "$soamachine $soaemail ( ". time2str("%Y%m%d", time). "00 ".
188 "$soarefresh $soaretry $soaexpire $soadefaultttl )"
190 $error = $soa->insert;
192 $dbh->rollback if $oldAutoCommit;
193 return "couldn't insert SOA record for new domain: $error";
196 foreach my $nsmachine ( @nsmachines ) {
197 my $ns = new FS::domain_record {
198 'svcnum' => $self->svcnum,
202 'recdata' => $nsmachine,
204 my $error = $ns->insert;
206 $dbh->rollback if $oldAutoCommit;
207 return "couldn't insert NS record for new domain: $error";
211 foreach my $mxmachine ( @mxmachines ) {
212 my $mx = new FS::domain_record {
213 'svcnum' => $self->svcnum,
217 'recdata' => $mxmachine,
219 my $error = $mx->insert;
221 $dbh->rollback if $oldAutoCommit;
222 return "couldn't insert MX record for new domain: $error";
228 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
230 if ( $qshellmachine && $self->catchall && ! $nossh_hack ) {
231 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $self->catchall } )
232 or warn "WARNING: inserted unknown catchall: ". $self->catchall;
233 if ( $svc_acct && $svc_acct->dir ) {
234 my $qdomain = $self->domain;
235 $qdomain =~ s/\./:/g; #see manpage for 'dot-qmail': EXTENSION ADDRESSES
236 my ( $uid, $gid, $dir ) = (
241 ssh("root\@$qshellmachine", "[ -e $dir/.qmail-$qdomain-default ] || { touch $dir/.qmail-$qdomain-default; chown $uid:$gid $dir/.qmail-$qdomain-default; }");
250 Deletes this domain from the database. If there is an error, returns the
251 error, otherwise returns false.
253 The corresponding FS::cust_svc record will be deleted as well.
260 return "Can't delete a domain which has accounts!"
261 if qsearch( 'svc_acct', { 'domsvc' => $self->svcnum } );
263 return "Can't delete a domain with (svc_acct_sm) mail aliases!"
264 if defined( $FS::Record::dbdef->table('svc_acct_sm') )
265 && qsearch('svc_acct_sm', { 'domsvc' => $self->svcnum } );
267 return "Can't delete a domain with (domain_record) zone entries!"
268 if qsearch('domain_record', { 'svcnum' => $self->svcnum } );
270 $self->SUPER::delete;
273 =item replace OLD_RECORD
275 Replaces OLD_RECORD with this one in the database. If there is an error,
276 returns the error, otherwise returns false.
281 my ( $new, $old ) = ( shift, shift );
284 return "Can't change domain - reorder."
285 if $old->getfield('domain') ne $new->getfield('domain');
287 $new->SUPER::replace($old);
293 Just returns false (no error) for now.
295 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
299 Just returns false (no error) for now.
301 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
305 Just returns false (no error) for now.
307 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
311 Checks all fields to make sure this is a valid domain. If there is an error,
312 returns the error, otherwise returns false. Called by the insert and replace
315 Sets any fixed values; see L<FS::part_svc>.
322 my $x = $self->setfixed;
323 return $x unless ref($x);
326 my $error = $self->ut_numbern('svcnum')
327 || $self->ut_numbern('catchall')
329 return $error if $error;
333 if ( $self->svcnum ) {
334 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
335 $pkgnum = $cust_svc->pkgnum;
337 $pkgnum = $self->pkgnum;
340 my($recref) = $self->hashref;
342 unless ( $whois_hack ) {
343 unless ( $self->email ) { #find out an email address
345 foreach ( qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } ) ) {
346 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $_->svcnum } );
347 push @svc_acct, $svc_acct if $svc_acct;
350 if ( scalar(@svc_acct) == 0 ) {
351 return "Must order an account in package ". $pkgnum. " first";
352 } elsif ( scalar(@svc_acct) > 1 ) {
353 return "More than one account in package ". $pkgnum. ": specify admin contact email";
355 $self->email($svc_acct[0]->email );
360 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
361 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
362 $recref->{domain} = "$1.$2";
364 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
365 $recref->{domain} = $1;
367 return "Illegal domain ". $recref->{domain}.
368 " (or unknown registry - try \$whois_hack)";
371 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
372 $recref->{action} = $1;
374 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $recref->{catchall} } );
375 return "Unknown catchall" unless $svc_acct || ! $recref->{catchall};
377 $self->ut_textn('purpose');
383 Returns the Net::Whois::Domain object (see L<Net::Whois>) for this domain, or
384 undef if the domain is not found in whois.
386 (If $FS::svc_domain::whois_hack is true, returns that in all cases instead.)
391 $whois_hack or new Net::Whois::Domain $_[0]->domain;
401 die "_whois depriciated";
404 =item submit_internic
406 Submits a registration email for this domain.
410 sub submit_internic {
412 carp "submit_internic depreciated";
419 $Id: svc_domain.pm,v 1.22 2001-10-24 15:29:30 ivan Exp $
423 All BIND/DNS fields should be included (and exported).
425 Delete doesn't send a registration template.
427 All registries should be supported.
429 Should change action to a real field.
431 The $recref stuff in sub check should be cleaned up.
435 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
436 L<FS::part_svc>, L<FS::cust_pkg>, L<Net::Whois>, L<ssh>,
437 L<dot-qmail>, schema.html from the base documentation, config.html from the