1 package FS::svc_domain;
4 use vars qw( @ISA $whois_hack $conf $mydomain $smtpmachine
5 $tech_contact $from $to @nameservers @nameserver_ips @template
12 use FS::Record qw(fields qsearch qsearchs);
20 @ISA = qw( FS::svc_Common );
22 #ask FS::UID to run this stuff for us later
23 $FS::UID::callback{'FS::domain'} = sub {
26 $mydomain = $conf->config('domain');
27 $smtpmachine = $conf->config('smtpmachine');
29 my($internic)="/registries/internic";
30 $tech_contact = $conf->config("$internic/tech_contact");
31 $from = $conf->config("$internic/from");
32 $to = $conf->config("$internic/to");
33 my(@ns) = $conf->config("$internic/nameservers");
35 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
36 or die "Illegal line in $internic/nameservers";
40 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
41 or die "Illegal line in $internic/nameservers!";
44 @template = map { $_. "\n" } $conf->config("$internic/template");
50 FS::svc_domain - Object methods for svc_domain records
56 $record = new FS::svc_domain \%hash;
57 $record = new FS::svc_domain { 'column' => 'value' };
59 $error = $record->insert;
61 $error = $new_record->replace($old_record);
63 $error = $record->delete;
65 $error = $record->check;
67 $error = $record->suspend;
69 $error = $record->unsuspend;
71 $error = $record->cancel;
75 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
76 FS::svc_Common. The following fields are currently supported:
80 =item svcnum - primary key (assigned automatically for new accounts)
92 Creates a new domain. To add the domain to the database, see L<"insert">.
96 sub table { 'svc_domain'; }
100 Adds this domain to the database. If there is an error, returns the error,
101 otherwise returns false.
103 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
104 defined. An FS::cust_svc record will be created and inserted.
106 The additional field I<action> should be set to I<N> for new domains or I<M>
109 A registration or transfer email will be submitted unless
110 $FS::svc_domain::whois_hack is true.
112 The additional field I<email> can be used to manually set the admin contact
113 email address on this email. Otherwise, the svc_acct records for this package
114 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
115 in the same package, it is automatically used. Otherwise an error is returned.
123 local $SIG{HUP} = 'IGNORE';
124 local $SIG{INT} = 'IGNORE';
125 local $SIG{QUIT} = 'IGNORE';
126 local $SIG{TERM} = 'IGNORE';
127 local $SIG{TSTP} = 'IGNORE';
128 local $SIG{PIPE} = 'IGNORE';
130 $error = $self->check;
131 return $error if $error;
133 return "Domain in use (here)"
134 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
136 my $whois = $self->whois;
137 return "Domain in use (see whois)"
138 if ( $self->action eq "N" && $whois );
139 return "Domain not found (see whois)"
140 if ( $self->action eq "M" && ! $whois );
142 $error = $self->SUPER::insert;
143 return $error if $error;
145 $self->submit_internic unless $whois_hack;
152 Deletes this domain from the database. If there is an error, returns the
153 error, otherwise returns false.
155 The corresponding FS::cust_svc record will be deleted as well.
157 =item replace OLD_RECORD
159 Replaces OLD_RECORD with this one in the database. If there is an error,
160 returns the error, otherwise returns false.
165 my ( $new, $old ) = ( shift, shift );
168 return "Can't change domain - reorder."
169 if $old->getfield('domain') ne $new->getfield('domain');
171 $new->SUPER::replace($old);
177 Just returns false (no error) for now.
179 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
183 Just returns false (no error) for now.
185 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
189 Just returns false (no error) for now.
191 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
195 Checks all fields to make sure this is a valid domain. If there is an error,
196 returns the error, otherwise returns false. Called by the insert and replace
199 Sets any fixed values; see L<FS::part_svc>.
207 my $x = $self->setfixed;
208 return $x unless ref($x);
213 if ( $self->svcnum ) {
214 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
215 $pkgnum = $cust_svc->pkgnum;
217 $pkgnum = $self->pkgnum;
220 my($recref) = $self->hashref;
222 unless ( $whois_hack ) {
223 unless ( $self->email ) { #find out an email address
225 foreach ( qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } ) ) {
226 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $_->svcnum } );
227 push @svc_acct, $svc_acct if $svc_acct;
230 if ( scalar(@svc_acct) == 0 ) {
231 return "Must order an account in package ". $pkgnum. " first";
232 } elsif ( scalar(@svc_acct) > 1 ) {
233 return "More than one account in package ". $pkgnum. ": specify admin contact email";
235 $self->email($svc_acct[0]->username. '@'. $mydomain);
240 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
241 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
242 $recref->{domain} = "$1.$2";
244 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
245 $recref->{domain} = $1;
247 return "Illegal domain ". $recref->{domain}.
248 " (or unknown registry - try \$whois_hack)";
251 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
252 $recref->{action} = $1;
254 $self->ut_textn('purpose');
260 Returns the Net::Whois::Domain object (see L<Net::Whois>) for this domain, or
261 undef if the domain is not found in whois.
263 (If $FS::svc_domain::whois_hack is true, returns that in all cases instead.)
268 $whois_hack or new Net::Whois::Domain $_[0]->domain;
278 die "_whois depriciated";
281 =item submit_internic
283 Submits a registration email for this domain.
287 sub submit_internic {
290 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
291 return unless $cust_pkg;
292 my $cust_main = qsearchs( 'cust_main', { 'custnum' => $cust_pkg->custnum } );
293 return unless $cust_main;
296 'action' => $self->action,
297 'purpose' => $self->purpose,
298 'domain' => $self->domain,
299 'company' => $cust_main->company
300 || $cust_main->getfield('first'). ' '.
301 $cust_main->getfield('last')
303 'city' => $cust_main->city,
304 'state' => $cust_main->state,
305 'zip' => $cust_main->zip,
306 'country' => $cust_main->country,
307 'last' => $cust_main->getfield('last'),
308 'first' => $cust_main->getfield('first'),
309 'daytime' => $cust_main->daytime,
310 'fax' => $cust_main->fax,
311 'email' => $self->email,
312 'tech_contact' => $tech_contact,
313 'primary' => shift @nameservers,
314 'primary_ip' => shift @nameserver_ips,
318 my @xtemplate = @template;
321 OLOOP: while ( defined( $line = shift @xtemplate ) ) {
323 if ( $line =~ /^###LOOP###$/ ) {
325 LOADBUF: while ( defined( $line = shift @xtemplate ) ) {
326 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
330 'address' => $cust_main->address2
331 ? [ $cust_main->address1, $cust_main->address2 ]
332 : [ $cust_main->address1 ]
334 'secondary' => [ @nameservers ],
335 'secondary_ip' => [ @nameserver_ips ],
338 my @xbuffer = @buffer;
339 SUBLOOP: while ( defined( $line = shift @xbuffer ) ) {
340 if ( $line =~ /###(\w+)###/ ) {
341 #last LOOP unless my($lub)=shift@{$lubs{$1}};
342 next OLOOP unless my $lub = shift @{$lubs{$1}};
343 $line =~ s/###(\w+)###/$lub/e;
353 if ( $line =~ /###(\w+)###/ ) {
354 #$line =~ s/###(\w+)###/$subs{$1}/eg;
355 $line =~ s/###(\w+)###/$subs{$1}/e;
364 if ( $self->action eq "M" ) {
365 $subject = "MODIFY DOMAIN ". $self->domain;
366 } elsif ( $self->action eq "N" ) {
367 $subject = "NEW DOMAIN ". $self->domain;
369 croak "submit_internic called with action ". $self->action;
372 $ENV{SMTPHOSTS} = $smtpmachine;
373 $ENV{MAILADDRESS} = $from;
374 my $header = Mail::Header->new( [
379 "Date: ". time2str("%a, %d %b %Y %X %z", time),
383 my($msg)=Mail::Internet->new(
388 $msg->smtpsend or die "Can't send registration email"; #die? warn?
396 $Id: svc_domain.pm,v 1.4 2000-01-29 21:10:13 ivan Exp $
400 All BIND/DNS fields should be included (and exported).
402 Delete doesn't send a registration template.
404 All registries should be supported.
406 Should change action to a real field.
408 The $recref stuff in sub check should be cleaned up.
412 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
413 L<FS::part_svc>, L<FS::cust_pkg>, L<FS::SSH>, L<Net::Whois>, L<ssh>,
414 L<dot-qmail>, schema.html from the base documentation, config.html from the