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,
137 'domain' => 'Domain',
139 label => 'Parent domain / Communigate administrator domain',
141 select_table => 'svc_domain',
142 select_key => 'svcnum',
143 select_label => 'domain',
144 disable_inventory => 1,
147 'au_registrant_name' => { label => 'AU Registrant Name',
148 disable_inventory => 1,
151 'au_eligibility_type' => { label => 'AU Eligibility Type',
153 select_list => __PACKAGE__->au_eligibility_type_values,
154 disable_inventory => 1,
157 'max_accounts' => { label => 'Maximum number of accounts',
158 'disable_inventory' => 1,
161 label => 'Quota', #storage limit
163 disable_inventory => 1,
166 label => 'Communigate aliases',
168 disable_inventory => 1,
171 'cgp_accessmodes' => {
172 label => 'Communigate enabled services',
173 type => 'communigate_pro-accessmodes',
174 disable_inventory => 1,
177 'cgp_certificatetype' => {
178 label => 'Communigate PKI services',
180 select_list => __PACKAGE__->cgp_certificatetype_values,
181 disable_inventory => 1,
185 'acct_def_cgp_accessmodes' => {
186 label => 'Acct. default Communigate enabled services',
187 type => 'communigate_pro-accessmodes',
188 disable_inventory => 1,
191 'acct_def_password_selfchange' => { label => 'Acct. default Password modification',
193 disable_inventory => 1,
196 'acct_def_password_recover' => { label => 'Acct. default Password recovery',
198 disable_inventory => 1,
201 'acct_def_cgp_deletemode' => {
202 label => 'Acct. default Communigate message delete method',
204 select_list => [ 'Move To Trash', 'Immediately', 'Mark' ],
205 disable_inventory => 1,
208 'acct_def_cgp_emptytrash' => {
209 label => 'Acct. default Communigate on logout remove trash',
211 select_list => __PACKAGE__->cgp_emptytrash_values,
212 disable_inventory => 1,
215 'acct_def_quota' => {
216 label => 'Acct. default Quota', #Mail storage limit
218 disable_inventory => 1,
221 'acct_def_file_quota'=> {
222 label => 'Acct. default File storage limit',
224 disable_inventory => 1,
227 'acct_def_file_maxnum'=> {
228 label => 'Acct. default Number of files limit',
230 disable_inventory => 1,
233 'acct_def_file_maxsize'=> {
234 label => 'Acct. default File size limit',
236 disable_inventory => 1,
239 'acct_def_cgp_rulesallowed' => {
240 label => 'Acct. default Allowed mail rules',
242 select_list => [ '', 'No', 'Filter Only', 'All But Exec', 'Any' ],
243 disable_inventory => 1,
246 'acct_def_cgp_rpopallowed' => {
247 label => 'Acct. default RPOP modifications',
250 'acct_def_cgp_mailtoall' => {
251 label => 'Acct. default Accepts mail to "all"',
254 'acct_def_cgp_addmailtrailer' => {
255 label => 'Acct. default Add trailer to sent mail',
258 'acct_def_cgp_archiveafter' => {
259 label => 'Archive messages after',
262 -2 => 'default(730 days)',
269 1209600 => '2 weeks',
270 2592000 => '30 days',
271 7776000 => '90 days',
272 15552000 => '180 days',
273 31536000 => '365 days',
274 63072000 => '730 days',
276 disable_inventory => 1,
280 label => 'Mail trailer',
282 disable_inventory => 1,
285 'acct_def_cgp_language' => {
286 label => 'Acct. default language',
288 select_list => [ '', qw( English Arabic Chinese Dutch French German Hebrew Italian Japanese Portuguese Russian Slovak Spanish Thai ) ],
289 disable_inventory => 1,
292 'acct_def_cgp_timezone' => {
293 label => 'Acct. default time zone',
295 select_list => __PACKAGE__->cgp_timezone_values,
296 disable_inventory => 1,
299 'acct_def_cgp_skinname' => {
300 label => 'Acct. default layout',
302 select_list => [ '', '***', 'GoldFleece', 'Skin2' ],
303 disable_inventory => 1,
306 'acct_def_cgp_prontoskinname' => {
307 label => 'Acct. default Pronto style',
309 select_list => [ '', 'Pronto', 'Pronto-darkflame', 'Pronto-steel', 'Pronto-twilight', ],
310 disable_inventory => 1,
313 'acct_def_cgp_sendmdnmode' => {
314 label => 'Acct. default send read receipts',
316 select_list => [ '', 'Never', 'Manually', 'Automatically' ],
317 disable_inventory => 1,
324 sub table { 'svc_domain'; }
327 my($class, $string) = @_;
328 $class->search_sql_field('domain', $string);
331 =item au_eligibility_type_values
335 sub au_eligibility_type_values {
342 'Commercial Statutory Body',
345 'Higher Education Institution',
346 'Incorporated Association',
349 'Non-Government School',
350 'Non-profit Organisation',
356 'Registered Business',
357 'Religious/Church Group',
358 'Research Organisation',
362 'Training Organisation',
378 =item insert [ , OPTION => VALUE ... ]
380 Adds this domain to the database. If there is an error, returns the error,
381 otherwise returns false.
383 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
384 defined. An FS::cust_svc record will be created and inserted.
386 The additional field I<action> should be set to I<N> for new domains, I<M>
387 for transfers, or I<I> for no action (registered elsewhere).
389 The additional field I<email> can be used to manually set the admin contact
390 email address on this email. Otherwise, the svc_acct records for this package
391 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
392 in the same package, it is automatically used. Otherwise an error is returned.
394 If any I<soamachine> configuration file exists, an SOA record is added to
395 the domain_record table (see <FS::domain_record>).
397 If any records are defined in the I<defaultrecords> configuration file,
398 appropriate records are added to the domain_record table (see
399 L<FS::domain_record>).
401 Currently available options are: I<depend_jobnum>
403 If I<depend_jobnum> is set (to a scalar jobnum or an array reference of
404 jobnums), all provisioning jobs will have a dependancy on the supplied
405 jobnum(s) (they will not run until the specific job(s) complete(s)).
413 local $SIG{HUP} = 'IGNORE';
414 local $SIG{INT} = 'IGNORE';
415 local $SIG{QUIT} = 'IGNORE';
416 local $SIG{TERM} = 'IGNORE';
417 local $SIG{TSTP} = 'IGNORE';
418 local $SIG{PIPE} = 'IGNORE';
420 my $oldAutoCommit = $FS::UID::AutoCommit;
421 local $FS::UID::AutoCommit = 0;
424 $error = $self->SUPER::insert(@_)
425 || $self->insert_defaultrecords;
427 $dbh->rollback if $oldAutoCommit;
431 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
436 =item insert_defaultrecords
440 sub insert_defaultrecords {
443 local $SIG{HUP} = 'IGNORE';
444 local $SIG{INT} = 'IGNORE';
445 local $SIG{QUIT} = 'IGNORE';
446 local $SIG{TERM} = 'IGNORE';
447 local $SIG{TSTP} = 'IGNORE';
448 local $SIG{PIPE} = 'IGNORE';
450 my $oldAutoCommit = $FS::UID::AutoCommit;
451 local $FS::UID::AutoCommit = 0;
455 my $soa = new FS::domain_record {
456 'svcnum' => $self->svcnum,
460 'recdata' => "$soamachine $soaemail ( ". time2str("%Y%m%d", time). "00 ".
461 "$soarefresh $soaretry $soaexpire $soadefaultttl )"
463 my $error = $soa->insert;
465 $dbh->rollback if $oldAutoCommit;
466 return "couldn't insert SOA record: $error";
469 foreach my $record ( @defaultrecords ) {
470 my($zone,$af,$type,$data) = split(/\s+/,$record,4);
471 my $domain_record = new FS::domain_record {
472 'svcnum' => $self->svcnum,
478 my $error = $domain_record->insert;
480 $dbh->rollback if $oldAutoCommit;
481 return "couldn't insert record: $error";
487 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
494 Deletes this domain from the database. If there is an error, returns the
495 error, otherwise returns false.
497 The corresponding FS::cust_svc record will be deleted as well.
504 return "Can't delete a domain which has accounts!"
505 if qsearch( 'svc_acct', { 'domsvc' => $self->svcnum } );
507 #return "Can't delete a domain with (domain_record) zone entries!"
508 # if qsearch('domain_record', { 'svcnum' => $self->svcnum } );
510 local $SIG{HUP} = 'IGNORE';
511 local $SIG{INT} = 'IGNORE';
512 local $SIG{QUIT} = 'IGNORE';
513 local $SIG{TERM} = 'IGNORE';
514 local $SIG{TSTP} = 'IGNORE';
515 local $SIG{PIPE} = 'IGNORE';
517 my $oldAutoCommit = $FS::UID::AutoCommit;
518 local $FS::UID::AutoCommit = 0;
521 foreach my $domain_record ( reverse $self->domain_record ) {
522 my $error = $domain_record->delete;
524 $dbh->rollback if $oldAutoCommit;
525 return "can't delete DNS entry: ".
526 join(' ', map $domain_record->$_(),
527 qw( reczone recaf rectype recdata )
533 my $error = $self->SUPER::delete(@_);
535 $dbh->rollback if $oldAutoCommit;
539 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
542 =item replace OLD_RECORD
544 Replaces OLD_RECORD with this one in the database. If there is an error,
545 returns the error, otherwise returns false.
552 my $old = ( blessed($_[0]) && $_[0]->isa('FS::Record') )
556 return "Can't change domain - reorder."
557 if $old->getfield('domain') ne $new->getfield('domain')
558 && ! $conf->exists('svc_domain-edit_domain');
560 # Better to do it here than to force the caller to remember that svc_domain is weird.
561 $new->setfield(action => 'I');
562 my $error = $new->SUPER::replace($old, @_);
563 return $error if $error;
568 Just returns false (no error) for now.
570 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
574 Just returns false (no error) for now.
576 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
580 Just returns false (no error) for now.
582 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
586 Checks all fields to make sure this is a valid domain. If there is an error,
587 returns the error, otherwise returns false. Called by the insert and replace
590 Sets any fixed values; see L<FS::part_svc>.
597 my $x = $self->setfixed;
598 return $x unless ref($x);
601 my $error = $self->ut_numbern('svcnum')
602 || $self->ut_textn('au_eligibility_type')
603 || $self->ut_textn('au_registrant_name')
604 || $self->ut_numbern('catchall')
605 || $self->ut_numbern('max_accounts')
606 || $self->ut_alphan('quota')
607 || $self->ut_anything('trailer') #well
608 || $self->ut_textn('cgp_aliases') #well
609 || $self->ut_enum('acct_def_password_selfchange', [ '', 'Y' ])
610 || $self->ut_enum('acct_def_password_recover', [ '', 'Y' ])
611 || $self->ut_textn('acct_def_cgp_accessmodes')
612 || $self->ut_alphan('acct_def_quota')
613 || $self->ut_alphan('acct_def_file_quota')
614 || $self->ut_alphan('acct_def_maxnum')
615 || $self->ut_alphan('acct_def_maxsize')
617 || $self->ut_alphasn('acct_def_cgp_rulesallowed')
618 || $self->ut_enum('acct_def_cgp_rpopallowed', [ '', 'Y' ])
619 || $self->ut_enum('acct_def_cgp_mailtoall', [ '', 'Y' ])
620 || $self->ut_enum('acct_def_cgp_addmailtrailer', [ '', 'Y' ])
621 || $self->ut_snumbern('acct_def_cgp_archiveafter')
623 || $self->ut_alphasn('acct_def_cgp_deletemode')
624 || $self->ut_enum('acct_def_cgp_emptytrash',
625 $self->cgp_emptytrash_values )
626 || $self->ut_alphan('acct_def_cgp_language')
627 || $self->ut_textn('acct_def_cgp_timezone')
628 || $self->ut_textn('acct_def_cgp_skinname')
629 || $self->ut_textn('acct_def_cgp_prontoskinname')
630 || $self->ut_alphan('acct_def_cgp_sendmdnmode')
633 return $error if $error;
637 if ( $self->svcnum ) {
638 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
639 $pkgnum = $cust_svc->pkgnum;
641 $pkgnum = $self->pkgnum;
644 my($recref) = $self->hashref;
646 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
647 if ( $recref->{domain} =~ /^([\w\-]{1,63})\.(com|net|org|edu|tv|info|biz)$/ ) {
648 $recref->{domain} = "$1.$2";
649 $recref->{suffix} ||= $2;
651 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.\/]+)\.(\w+)$/ ) {
652 $recref->{domain} = "$1.$2";
653 # need to match a list of suffixes - no guarantee they're top-level..
654 # http://wiki.mozilla.org/TLD_List
655 # but this will have to do for now...
656 $recref->{suffix} ||= $2;
658 return "Illegal domain ". $recref->{domain}.
659 " (or unknown registry - try \$whois_hack)";
662 $self->suffix =~ /(^|\.)(\w+)$/
663 or return "can't parse suffix for TLD: ". $self->suffix;
665 return "No such TLD: .$tld" unless tld_exists($tld);
667 if ( $recref->{catchall} ne '' ) {
668 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $recref->{catchall} } );
669 return "Unknown catchall" unless $svc_acct;
672 $self->ut_alphan('suffix')
673 or $self->ut_foreign_keyn('registrarnum', 'registrar', 'registrarnum')
674 or $self->ut_textn('registrarkey')
675 or $self->ut_numbern('setup_date')
676 or $self->ut_numbern('renewal_interval')
677 or $self->ut_numbern('expiration_date')
678 or $self->SUPER::check;
682 sub _check_duplicate {
687 if ( qsearchs( 'svc_domain', { 'domain' => $self->domain } ) ) {
688 return "Domain in use (here)";
713 #'SOA' => sub { $_[0]->recdata cmp $_[1]->recdata }, #sure hope not though
714 # 'SOA' => sub { 0; },
715 # 'NS' => sub { 0; },
716 'MX' => sub { my( $a_weight, $a_name ) = split(/\s+/, $_[0]->recdata);
717 my( $b_weight, $b_name ) = split(/\s+/, $_[1]->recdata);
718 $a_weight <=> $b_weight or $a_name cmp $b_name;
720 'CNAME' => sub { $_[0]->reczone cmp $_[1]->reczone },
721 'A' => sub { $_[0]->reczone cmp $_[1]->reczone },
723 # 'TXT' => sub { 0; },
724 'PTR' => sub { $_[0]->reczone <=> $_[1]->reczone },
727 map { $_ } #return $self->num_domain_record( PARAMS ) unless wantarray;
728 sort { $order{$a->rectype} <=> $order{$b->rectype}
729 or &{ $sort{$a->rectype} || sub { 0; } }($a, $b)
731 qsearch('domain_record', { svcnum => $self->svcnum } );
735 sub catchall_svc_acct {
737 if ( $self->catchall ) {
738 qsearchs( 'svc_acct', { 'svcnum' => $self->catchall } );
746 # Returns the Net::Whois::Domain object (see L<Net::Whois>) for this domain, or
747 # undef if the domain is not found in whois.
749 (If $FS::svc_domain::whois_hack is true, returns that in all cases instead.)
754 #$whois_hack or new Net::Whois::Domain $_[0]->domain;
755 #$whois_hack or die "whois_hack not set...\n";
762 Delete doesn't send a registration template.
764 All registries should be supported.
766 Should change action to a real field.
768 The $recref stuff in sub check should be cleaned up.
772 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
773 L<FS::part_svc>, L<FS::cust_pkg>, L<Net::Whois>, schema.html from the base
774 documentation, config.html from the base documentation.