1 package FS::svc_domain;
4 use vars qw( @ISA $whois_hack $conf $mydomain $smtpmachine
5 $tech_contact $from $to @nameservers @nameserver_ips @template
11 use FS::Record qw(fields qsearch qsearchs);
16 @ISA = qw( FS::svc_Common );
18 #ask FS::UID to run this stuff for us later
19 $FS::UID::callback{'FS::domain'} = sub {
22 $mydomain = $conf->config('domain');
23 $smtpmachine = $conf->config('smtpmachine');
25 my($internic)="/registries/internic";
26 $tech_contact = $conf->config("$internic/tech_contact");
27 $from = $conf->config("$internic/from");
28 $to = $conf->config("$internic/to");
29 my(@ns) = $conf->config("$internic/nameservers");
31 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
32 or die "Illegal line in $internic/nameservers";
36 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
37 or die "Illegal line in $internic/nameservers!";
40 @template = map { $_. "\n" } $conf->config("$internic/template");
46 FS::svc_domain - Object methods for svc_domain records
52 $record = new FS::svc_domain \%hash;
53 $record = new FS::svc_domain { 'column' => 'value' };
55 $error = $record->insert;
57 $error = $new_record->replace($old_record);
59 $error = $record->delete;
61 $error = $record->check;
63 $error = $record->suspend;
65 $error = $record->unsuspend;
67 $error = $record->cancel;
71 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
72 FS::svc_Common. The following fields are currently supported:
76 =item svcnum - primary key (assigned automatically for new accounts)
88 Creates a new domain. To add the domain to the database, see L<"insert">.
92 sub table { 'svc_domain'; }
96 Adds this domain to the database. If there is an error, returns the error,
97 otherwise returns false.
99 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
100 defined. An FS::cust_svc record will be created and inserted.
102 The additional field I<action> should be set to I<N> for new domains or I<M>
105 A registration or transfer email will be submitted unless
106 $FS::svc_domain::whois_hack is true.
108 The additional field I<email> can be used to manually set the admin contact
109 email address on this email. Otherwise, the svc_acct records for this package
110 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
111 in the same package, it is automatically used. Otherwise an error is returned.
119 local $SIG{HUP} = 'IGNORE';
120 local $SIG{INT} = 'IGNORE';
121 local $SIG{QUIT} = 'IGNORE';
122 local $SIG{TERM} = 'IGNORE';
123 local $SIG{TSTP} = 'IGNORE';
124 local $SIG{PIPE} = 'IGNORE';
126 $error = $self->check;
127 return $error if $error;
129 return "Domain in use (here)"
130 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
132 my $whois = ($self->_whois)[0];
133 return "Domain in use (see whois)"
134 if ( $self->action eq "N" && $whois !~ /^No match for/ );
135 return "Domain not found (see whois)"
136 if ( $self->action eq "M" && $whois =~ /^No match for/ );
138 $error = $self->SUPER::insert;
139 return $error if $error;
141 $self->submit_internic unless $whois_hack;
148 Deletes this domain from the database. If there is an error, returns the
149 error, otherwise returns false.
151 The corresponding FS::cust_svc record will be deleted as well.
153 =item replace OLD_RECORD
155 Replaces OLD_RECORD with this one in the database. If there is an error,
156 returns the error, otherwise returns false.
161 my ( $new, $old ) = ( shift, shift );
164 return "Can't change domain - reorder."
165 if $old->getfield('domain') ne $new->getfield('domain');
167 $new->SUPER::replace($old);
173 Just returns false (no error) for now.
175 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
179 Just returns false (no error) for now.
181 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
185 Just returns false (no error) for now.
187 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
191 Checks all fields to make sure this is a valid domain. If there is an error,
192 returns the error, otherwise returns false. Called by the insert and replace
195 Sets any fixed values; see L<FS::part_svc>.
203 my $x = $self->setfixed;
204 return $x unless ref($x);
209 if ( $self->svcnum ) {
210 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
211 $pkgnum = $cust_svc->pkgnum;
213 $pkgnum = $self->pkgnum;
216 my($recref) = $self->hashref;
218 unless ( $whois_hack ) {
219 unless ( $self->email ) { #find out an email address
221 foreach ( qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } ) ) {
222 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $_->svcnum } );
223 push @svc_acct, $svc_acct if $svc_acct;
226 if ( scalar(@svc_acct) == 0 ) {
227 return "Must order an account in package ". $pkgnum. " first";
228 } elsif ( scalar(@svc_acct) > 1 ) {
229 return "More than one account in package ". $pkgnum. ": specify admin contact email";
231 $self->email($svc_acct[0]->username. '@'. $mydomain);
236 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
237 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
238 $recref->{domain} = "$1.$2";
240 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
241 $recref->{domain} = $1;
243 return "Illegal domain ". $recref->{domain}.
244 " (or unknown registry - try \$whois_hack)";
247 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
248 $recref->{action} = $1;
250 $self->ut_textn('purpose');
256 Executes the command:
260 and returns the output.
262 (Always returns I<No match for domian "$domain".> if
263 $FS::svc_domain::whois_hack is set true.)
269 my $domain = $self->domain;
270 return ( "No match for domain \"$domain\"." ) if $whois_hack;
271 open(WHOIS, "whois do $domain |");
275 =item submit_internic
277 Submits a registration email for this domain.
281 sub submit_internic {
284 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
285 return unless $cust_pkg;
286 my $cust_main = qsearchs( 'cust_main', { 'custnum' => $cust_pkg->custnum } );
287 return unless $cust_main;
290 'action' => $self->action,
291 'purpose' => $self->purpose,
292 'domain' => $self->domain,
293 'company' => $cust_main->company
294 || $cust_main->getfield('first'). ' '.
295 $cust_main->getfield('last')
297 'city' => $cust_main->city,
298 'state' => $cust_main->state,
299 'zip' => $cust_main->zip,
300 'country' => $cust_main->country,
301 'last' => $cust_main->getfield('last'),
302 'first' => $cust_main->getfield('first'),
303 'daytime' => $cust_main->daytime,
304 'fax' => $cust_main->fax,
305 'email' => $self->email,
306 'tech_contact' => $tech_contact,
307 'primary' => shift @nameservers,
308 'primary_ip' => shift @nameserver_ips,
312 my @xtemplate = @template;
315 OLOOP: while ( defined( $line = shift @xtemplate ) ) {
317 if ( $line =~ /^###LOOP###$/ ) {
319 LOADBUF: while ( defined( $line = shift @xtemplate ) ) {
320 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
324 'address' => $cust_main->address2
325 ? [ $cust_main->address1, $cust_main->address2 ]
326 : [ $cust_main->address1 ]
328 'secondary' => [ @nameservers ],
329 'secondary_ip' => [ @nameserver_ips ],
332 my @xbuffer = @buffer;
333 SUBLOOP: while ( defined( $line = shift @xbuffer ) ) {
334 if ( $line =~ /###(\w+)###/ ) {
335 #last LOOP unless my($lub)=shift@{$lubs{$1}};
336 next OLOOP unless my $lub = shift @{$lubs{$1}};
337 $line =~ s/###(\w+)###/$lub/e;
347 if ( $line =~ /###(\w+)###/ ) {
348 #$line =~ s/###(\w+)###/$subs{$1}/eg;
349 $line =~ s/###(\w+)###/$subs{$1}/e;
358 if ( $self->action eq "M" ) {
359 $subject = "MODIFY DOMAIN ". $self->domain;
360 } elsif ( $self->action eq "N" ) {
361 $subject = "NEW DOMAIN ". $self->domain;
363 croak "submit_internic called with action ". $self->action;
366 $ENV{SMTPHOSTS} = $smtpmachine;
367 $ENV{MAILADDRESS} = $from;
368 my $header = Mail::Header->new( [
373 "Date: ". time2str("%a, %d %b %Y %X %z", time),
377 my($msg)=Mail::Internet->new(
382 $msg->smtpsend or die "Can't send registration email"; #die? warn?
390 $Id: svc_domain.pm,v 1.6 1999-01-25 12:26:17 ivan Exp $
394 All BIND/DNS fields should be included (and exported).
396 Delete doesn't send a registration template.
398 All registries should be supported.
400 Should change action to a real field.
402 The $recref stuff in sub check should be cleaned up.
406 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
407 L<FS::part_svc>, L<FS::cust_pkg>, L<FS::SSH>, L<ssh>, L<dot-qmail>, schema.html from the base documentation, config.html from the base documentation.
411 ivan@voicenet.com 97-jul-21
413 rewrite ivan@sisd.com 98-mar-10
415 add internic bits ivan@sisd.com 98-mar-14
417 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
418 bmccane@maxbaud.net 98-apr-3
420 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
421 ivan@sisd.com 98-jul-17-19
423 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23
425 $Log: svc_domain.pm,v $
426 Revision 1.6 1999-01-25 12:26:17 ivan
427 yet more mod_perl stuff
429 Revision 1.5 1998/12/30 00:30:47 ivan
430 svc_ stuff is more properly OO - has a common superclass FS::svc_Common
432 Revision 1.3 1998/11/13 09:56:57 ivan
433 change configuration file layout to support multiple distinct databases (with
434 own set of config files, export, etc.)
436 Revision 1.2 1998/10/14 08:18:21 ivan
437 More informative error messages and better doc for admin contact email stuff