1 package FS::svc_domain;
4 use base qw( FS::svc_Parent_Mixin FS::svc_CGP_Mixin FS::svc_CGPRule_Mixin
6 use vars qw( $whois_hack $conf
7 @defaultrecords $soadefaultttl $soaemail $soaexpire $soamachine
11 use Scalar::Util qw( blessed );
14 use Net::Domain::TLD qw(tld_exists);
15 use FS::Record qw(fields qsearch qsearchs dbh);
21 use FS::domain_record;
24 #ask FS::UID to run this stuff for us later
25 $FS::UID::callback{'FS::domain'} = sub {
28 @defaultrecords = $conf->config('defaultrecords');
29 $soadefaultttl = $conf->config('soadefaultttl');
30 $soaemail = $conf->config('soaemail');
31 $soaexpire = $conf->config('soaexpire');
32 $soamachine = $conf->config('soamachine');
33 $soarefresh = $conf->config('soarefresh');
34 $soaretry = $conf->config('soaretry');
40 FS::svc_domain - Object methods for svc_domain records
46 $record = new FS::svc_domain \%hash;
47 $record = new FS::svc_domain { 'column' => 'value' };
49 $error = $record->insert;
51 $error = $new_record->replace($old_record);
53 $error = $record->delete;
55 $error = $record->check;
57 $error = $record->suspend;
59 $error = $record->unsuspend;
61 $error = $record->cancel;
65 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
66 FS::svc_Common. The following fields are currently supported:
72 primary key (assigned automatically for new accounts)
78 optional svcnum of an svc_acct record, designating an email catchall account.
90 Registrar (see L<FS::registrar>)
94 Registrar key or password for this domain
100 =item renewal_interval
102 Number of days before expiration date to start renewal
104 =item expiration_date
110 =item au_eligibility_type
112 AU-specific field for domain registrations
114 =item au_registrant_name
116 AU-specific field for domain registrations
126 Creates a new domain. To add the domain to the database, see L<"insert">.
134 'display_weight' => 20,
135 'cancel_weight' => 60,
142 label => 'Parent domain / Communigate administrator domain',
144 select_table => 'svc_domain',
145 select_key => 'svcnum',
146 select_label => 'domain',
147 disable_inventory => 1,
150 'au_registrant_name' => { label => 'AU Registrant Name',
151 disable_inventory => 1,
154 'au_eligibility_type' => { label => 'AU Eligibility Type',
156 select_list => __PACKAGE__->au_eligibility_type_values,
157 disable_inventory => 1,
160 'max_accounts' => { label => 'Maximum number of accounts',
161 'disable_inventory' => 1,
164 label => 'Quota', #storage limit
166 disable_inventory => 1,
169 label => 'Communigate aliases',
171 disable_inventory => 1,
174 'cgp_accessmodes' => {
175 label => 'Communigate enabled services',
176 type => 'communigate_pro-accessmodes',
177 disable_inventory => 1,
180 'cgp_certificatetype' => {
181 label => 'Communigate PKI services',
183 select_list => __PACKAGE__->cgp_certificatetype_values,
184 disable_inventory => 1,
188 'acct_def_cgp_accessmodes' => {
189 label => 'Acct. default Communigate enabled services',
190 type => 'communigate_pro-accessmodes',
191 disable_inventory => 1,
194 'acct_def_password_selfchange' => { label => 'Acct. default Password modification',
196 disable_inventory => 1,
199 'acct_def_password_recover' => { label => 'Acct. default Password recovery',
201 disable_inventory => 1,
204 'acct_def_cgp_deletemode' => {
205 label => 'Acct. default Communigate message delete method',
207 select_list => [ 'Move To Trash', 'Immediately', 'Mark' ],
208 disable_inventory => 1,
211 'acct_def_cgp_emptytrash' => {
212 label => 'Acct. default Communigate on logout remove trash',
214 select_list => __PACKAGE__->cgp_emptytrash_values,
215 disable_inventory => 1,
218 'acct_def_quota' => {
219 label => 'Acct. default Quota', #Mail storage limit
221 disable_inventory => 1,
224 'acct_def_file_quota'=> {
225 label => 'Acct. default File storage limit',
227 disable_inventory => 1,
230 'acct_def_file_maxnum'=> {
231 label => 'Acct. default Number of files limit',
233 disable_inventory => 1,
236 'acct_def_file_maxsize'=> {
237 label => 'Acct. default File size limit',
239 disable_inventory => 1,
242 'acct_def_cgp_rulesallowed' => {
243 label => 'Acct. default Allowed mail rules',
245 select_list => [ '', 'No', 'Filter Only', 'All But Exec', 'Any' ],
246 disable_inventory => 1,
249 'acct_def_cgp_rpopallowed' => {
250 label => 'Acct. default RPOP modifications',
253 'acct_def_cgp_mailtoall' => {
254 label => 'Acct. default Accepts mail to "all"',
257 'acct_def_cgp_addmailtrailer' => {
258 label => 'Acct. default Add trailer to sent mail',
261 'acct_def_cgp_archiveafter' => {
262 label => 'Archive messages after',
265 -2 => 'default(730 days)',
272 1209600 => '2 weeks',
273 2592000 => '30 days',
274 7776000 => '90 days',
275 15552000 => '180 days',
276 31536000 => '365 days',
277 63072000 => '730 days',
279 disable_inventory => 1,
283 label => 'Mail trailer',
285 disable_inventory => 1,
288 'acct_def_cgp_language' => {
289 label => 'Acct. default language',
291 select_list => [ '', qw( English Arabic Chinese Dutch French German Hebrew Italian Japanese Portuguese Russian Slovak Spanish Thai ) ],
292 disable_inventory => 1,
295 'acct_def_cgp_timezone' => {
296 label => 'Acct. default time zone',
298 select_list => __PACKAGE__->cgp_timezone_values,
299 disable_inventory => 1,
302 'acct_def_cgp_skinname' => {
303 label => 'Acct. default layout',
305 select_list => [ '', '***', 'GoldFleece', 'Skin2' ],
306 disable_inventory => 1,
309 'acct_def_cgp_prontoskinname' => {
310 label => 'Acct. default Pronto style',
312 select_list => [ '', 'Pronto', 'Pronto-darkflame', 'Pronto-steel', 'Pronto-twilight', ],
313 disable_inventory => 1,
316 'acct_def_cgp_sendmdnmode' => {
317 label => 'Acct. default send read receipts',
319 select_list => [ '', 'Never', 'Manually', 'Automatically' ],
320 disable_inventory => 1,
327 sub table { 'svc_domain'; }
330 my($class, $string) = @_;
331 $class->search_sql_field('domain', $string);
334 =item au_eligibility_type_values
338 sub au_eligibility_type_values {
345 'Commercial Statutory Body',
348 'Higher Education Institution',
349 'Incorporated Association',
352 'Non-Government School',
353 'Non-profit Organisation',
359 'Registered Business',
360 'Religious/Church Group',
361 'Research Organisation',
365 'Training Organisation',
381 =item insert [ , OPTION => VALUE ... ]
383 Adds this domain to the database. If there is an error, returns the error,
384 otherwise returns false.
386 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
387 defined. An FS::cust_svc record will be created and inserted.
389 The additional field I<action> should be set to I<N> for new domains, I<M>
390 for transfers, or I<I> for no action (registered elsewhere).
392 The additional field I<email> can be used to manually set the admin contact
393 email address on this email. Otherwise, the svc_acct records for this package
394 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
395 in the same package, it is automatically used. Otherwise an error is returned.
397 If any I<soamachine> configuration file exists, an SOA record is added to
398 the domain_record table (see <FS::domain_record>).
400 If any records are defined in the I<defaultrecords> configuration file,
401 appropriate records are added to the domain_record table (see
402 L<FS::domain_record>).
404 Currently available options are: I<depend_jobnum>
406 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
407 jobnums), all provisioning jobs will have a dependancy on the supplied
408 jobnum(s) (they will not run until the specific job(s) complete(s)).
416 local $SIG{HUP} = 'IGNORE';
417 local $SIG{INT} = 'IGNORE';
418 local $SIG{QUIT} = 'IGNORE';
419 local $SIG{TERM} = 'IGNORE';
420 local $SIG{TSTP} = 'IGNORE';
421 local $SIG{PIPE} = 'IGNORE';
423 my $oldAutoCommit = $FS::UID::AutoCommit;
424 local $FS::UID::AutoCommit = 0;
427 $error = $self->SUPER::insert(@_)
428 || $self->insert_defaultrecords;
430 $dbh->rollback if $oldAutoCommit;
434 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
439 =item insert_defaultrecords
443 sub insert_defaultrecords {
446 local $SIG{HUP} = 'IGNORE';
447 local $SIG{INT} = 'IGNORE';
448 local $SIG{QUIT} = 'IGNORE';
449 local $SIG{TERM} = 'IGNORE';
450 local $SIG{TSTP} = 'IGNORE';
451 local $SIG{PIPE} = 'IGNORE';
453 my $oldAutoCommit = $FS::UID::AutoCommit;
454 local $FS::UID::AutoCommit = 0;
458 my $soa = new FS::domain_record {
459 'svcnum' => $self->svcnum,
463 'recdata' => "$soamachine $soaemail ( ". time2str("%Y%m%d", time). "00 ".
464 "$soarefresh $soaretry $soaexpire $soadefaultttl )"
466 my $error = $soa->insert;
468 $dbh->rollback if $oldAutoCommit;
469 return "couldn't insert SOA record: $error";
472 foreach my $record ( @defaultrecords ) {
473 my($zone,$af,$type,$data) = split(/\s+/,$record,4);
474 my $domain_record = new FS::domain_record {
475 'svcnum' => $self->svcnum,
481 my $error = $domain_record->insert;
483 $dbh->rollback if $oldAutoCommit;
484 return "couldn't insert record: $error";
490 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
497 Deletes this domain from the database. If there is an error, returns the
498 error, otherwise returns false.
500 The corresponding FS::cust_svc record will be deleted as well.
507 return "Can't delete a domain which has accounts!"
508 if qsearch( 'svc_acct', { 'domsvc' => $self->svcnum } );
510 #return "Can't delete a domain with (domain_record) zone entries!"
511 # if qsearch('domain_record', { 'svcnum' => $self->svcnum } );
513 local $SIG{HUP} = 'IGNORE';
514 local $SIG{INT} = 'IGNORE';
515 local $SIG{QUIT} = 'IGNORE';
516 local $SIG{TERM} = 'IGNORE';
517 local $SIG{TSTP} = 'IGNORE';
518 local $SIG{PIPE} = 'IGNORE';
520 my $oldAutoCommit = $FS::UID::AutoCommit;
521 local $FS::UID::AutoCommit = 0;
524 foreach my $domain_record ( reverse $self->domain_record ) {
525 my $error = $domain_record->delete;
527 $dbh->rollback if $oldAutoCommit;
528 return "can't delete DNS entry: ".
529 join(' ', map $domain_record->$_(),
530 qw( reczone recaf rectype recdata )
536 my $error = $self->SUPER::delete(@_);
538 $dbh->rollback if $oldAutoCommit;
542 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
545 =item replace OLD_RECORD
547 Replaces OLD_RECORD with this one in the database. If there is an error,
548 returns the error, otherwise returns false.
555 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
559 return "Can't change domain - reorder."
560 if $old->getfield('domain') ne $new->getfield('domain')
561 && ! $conf->exists('svc_domain-edit_domain');
563 # Better to do it here than to force the caller to remember that svc_domain is weird.
564 $new->setfield(action => 'I');
565 my $error = $new->SUPER::replace($old, @_);
566 return $error if $error;
571 Just returns false (no error) for now.
573 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
577 Just returns false (no error) for now.
579 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
583 Just returns false (no error) for now.
585 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
589 Checks all fields to make sure this is a valid domain. If there is an error,
590 returns the error, otherwise returns false. Called by the insert and replace
593 Sets any fixed values; see L<FS::part_svc>.
600 my $x = $self->setfixed;
601 return $x unless ref($x);
604 my $error = $self->ut_numbern('svcnum')
605 || $self->ut_textn('au_eligibility_type')
606 || $self->ut_textn('au_registrant_name')
607 || $self->ut_numbern('catchall')
608 || $self->ut_numbern('max_accounts')
609 || $self->ut_alphan('quota')
610 || $self->ut_anything('trailer') #well
611 || $self->ut_textn('cgp_aliases') #well
612 || $self->ut_enum('acct_def_password_selfchange', [ '', 'Y' ])
613 || $self->ut_enum('acct_def_password_recover', [ '', 'Y' ])
614 || $self->ut_textn('acct_def_cgp_accessmodes')
615 || $self->ut_alphan('acct_def_quota')
616 || $self->ut_alphan('acct_def_file_quota')
617 || $self->ut_alphan('acct_def_maxnum')
618 || $self->ut_alphan('acct_def_maxsize')
620 || $self->ut_alphasn('acct_def_cgp_rulesallowed')
621 || $self->ut_enum('acct_def_cgp_rpopallowed', [ '', 'Y' ])
622 || $self->ut_enum('acct_def_cgp_mailtoall', [ '', 'Y' ])
623 || $self->ut_enum('acct_def_cgp_addmailtrailer', [ '', 'Y' ])
624 || $self->ut_snumbern('acct_def_cgp_archiveafter')
626 || $self->ut_alphasn('acct_def_cgp_deletemode')
627 || $self->ut_enum('acct_def_cgp_emptytrash',
628 $self->cgp_emptytrash_values )
629 || $self->ut_alphan('acct_def_cgp_language')
630 || $self->ut_textn('acct_def_cgp_timezone')
631 || $self->ut_textn('acct_def_cgp_skinname')
632 || $self->ut_textn('acct_def_cgp_prontoskinname')
633 || $self->ut_alphan('acct_def_cgp_sendmdnmode')
636 return $error if $error;
640 if ( $self->svcnum ) {
641 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
642 $pkgnum = $cust_svc->pkgnum;
644 $pkgnum = $self->pkgnum;
647 my($recref) = $self->hashref;
649 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
650 if ( $recref->{domain} =~ /^([\w\-]{1,63})\.(com|net|org|edu|tv|info|biz)$/ ) {
651 $recref->{domain} = "$1.$2";
652 $recref->{suffix} ||= $2;
654 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.\/]+)\.(\w+)$/ ) {
655 $recref->{domain} = "$1.$2";
656 # need to match a list of suffixes - no guarantee they're top-level..
657 # http://wiki.mozilla.org/TLD_List
658 # but this will have to do for now...
659 $recref->{suffix} ||= $2;
661 return "Illegal domain ". $recref->{domain}.
662 " (or unknown registry - try \$whois_hack)";
665 $self->suffix =~ /(^|\.)(\w+)$/
666 or return "can't parse suffix for TLD: ". $self->suffix;
668 return "No such TLD: .$tld" unless tld_exists($tld);
670 if ( $recref->{catchall} ne '' ) {
671 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $recref->{catchall} } );
672 return "Unknown catchall" unless $svc_acct;
675 $self->ut_alphan('suffix')
676 or $self->ut_foreign_keyn('registrarnum', 'registrar', 'registrarnum')
677 or $self->ut_textn('registrarkey')
678 or $self->ut_numbern('setup_date')
679 or $self->ut_numbern('renewal_interval')
680 or $self->ut_numbern('expiration_date')
681 or $self->SUPER::check;
685 sub _check_duplicate {
690 if ( qsearchs( 'svc_domain', { 'domain' => $self->domain } ) ) {
691 return "Domain in use (here)";
716 #'SOA' => sub { $_[0]->recdata cmp $_[1]->recdata }, #sure hope not though
717 # 'SOA' => sub { 0; },
718 # 'NS' => sub { 0; },
719 'MX' => sub { my( $a_weight, $a_name ) = split(/\s+/, $_[0]->recdata);
720 my( $b_weight, $b_name ) = split(/\s+/, $_[1]->recdata);
721 $a_weight <=> $b_weight or $a_name cmp $b_name;
723 'CNAME' => sub { $_[0]->reczone cmp $_[1]->reczone },
724 'A' => sub { $_[0]->reczone cmp $_[1]->reczone },
726 # 'TXT' => sub { 0; },
727 'PTR' => sub { $_[0]->reczone <=> $_[1]->reczone },
730 map { $_ } #return $self->num_domain_record( PARAMS ) unless wantarray;
731 sort { $order{$a->rectype} <=> $order{$b->rectype}
732 or &{ $sort{$a->rectype} || sub { 0; } }($a, $b)
734 qsearch('domain_record', { svcnum => $self->svcnum } );
738 sub catchall_svc_acct {
740 if ( $self->catchall ) {
741 qsearchs( 'svc_acct', { 'svcnum' => $self->catchall } );
749 # Returns the Net::Whois::Domain object (see L<Net::Whois>) for this domain, or
750 # undef if the domain is not found in whois.
752 (If $FS::svc_domain::whois_hack is true, returns that in all cases instead.)
757 #$whois_hack or new Net::Whois::Domain $_[0]->domain;
758 #$whois_hack or die "whois_hack not set...\n";
765 Delete doesn't send a registration template.
767 All registries should be supported.
769 Should change action to a real field.
771 The $recref stuff in sub check should be cleaned up.
775 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
776 L<FS::part_svc>, L<FS::cust_pkg>, L<Net::Whois>, schema.html from the base
777 documentation, config.html from the base documentation.