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);
15 @ISA = qw(FS::Record Exporter);
17 #ask FS::UID to run this stuff for us later
18 $FS::UID::callback{'FS::domain'} = sub {
21 $mydomain = $conf->config('domain');
22 $smtpmachine = $conf->config('smtpmachine');
24 my($internic)="/registries/internic";
25 $tech_contact = $conf->config("$internic/tech_contact");
26 $from = $conf->config("$internic/from");
27 $to = $conf->config("$internic/to");
28 my(@ns) = $conf->config("$internic/nameservers");
30 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
31 or die "Illegal line in $internic/nameservers";
35 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
36 or die "Illegal line in $internic/nameservers!";
39 @template = map { $_. "\n" } $conf->config("$internic/template");
45 FS::svc_domain - Object methods for svc_domain records
51 $record = new FS::svc_domain \%hash;
52 $record = new FS::svc_domain { 'column' => 'value' };
54 $error = $record->insert;
56 $error = $new_record->replace($old_record);
58 $error = $record->delete;
60 $error = $record->check;
62 $error = $record->suspend;
64 $error = $record->unsuspend;
66 $error = $record->cancel;
70 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
71 FS::Record. The following fields are currently supported:
75 =item svcnum - primary key (assigned automatically for new accounts)
87 Creates a new domain. To add the domain to the database, see L<"insert">.
91 sub table { 'svc_domain'; }
95 Adds this domain to the database. If there is an error, returns the error,
96 otherwise returns false.
98 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
99 defined. An FS::cust_svc record will be created and inserted.
101 The additional field I<action> should be set to I<N> for new domains or I<M>
104 A registration or transfer email will be submitted unless
105 $FS::svc_domain::whois_hack is true.
107 The additional field I<email> can be used to manually set the admin contact
108 email address on this email. Otherwise, the svc_acct records for this package
109 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
110 in the same package, it is automatically used. Otherwise an error is returned.
118 local $SIG{HUP} = 'IGNORE';
119 local $SIG{INT} = 'IGNORE';
120 local $SIG{QUIT} = 'IGNORE';
121 local $SIG{TERM} = 'IGNORE';
122 local $SIG{TSTP} = 'IGNORE';
124 $error = $self->check;
125 return $error if $error;
127 return "Domain in use (here)"
128 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
130 my $whois = ($self->_whois)[0];
131 return "Domain in use (see whois)"
132 if ( $self->action eq "N" && $whois !~ /^No match for/ );
133 return "Domain not found (see whois)"
134 if ( $self->action eq "M" && $whois =~ /^No match for/ );
136 my $svcnum = $self->svcnum;
139 $cust_svc = new FS::cust_svc ( {
141 'pkgnum' => $self->pkgnum,
142 'svcpart' => $self->svcpart,
144 my $error = $cust_svc->insert;
145 return $error if $error;
146 $svcnum = $self->setfield( 'svcnum', $cust_svc->svcnum );
149 $error = $self->SUPER::insert;
151 $cust_svc->delete if $cust_svc;
155 $self->submit_internic unless $whois_hack;
162 Deletes this domain from the database. If there is an error, returns the
163 error, otherwise returns false.
165 The corresponding FS::cust_svc record will be deleted as well.
173 my $svcnum = $self->svcnum;
175 $error = $self->delete;
176 return $error if $error;
178 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $svcnum } );
179 $error = $cust_svc->delete;
180 return $error if $error;
185 =item replace OLD_RECORD
187 Replaces OLD_RECORD with this one in the database. If there is an error,
188 returns the error, otherwise returns false.
193 my ( $new, $old ) = ( shift, shift );
196 return "Can't change domain - reorder."
197 if $old->getfield('domain') ne $new->getfield('domain');
199 $new->SUPER::replace($old);
205 Just returns false (no error) for now.
207 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
217 Just returns false (no error) for now.
219 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
229 Just returns false (no error) for now.
231 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
241 Checks all fields to make sure this is a valid domain. If there is an error,
242 returns the error, otherwise returns false. Called by the insert and replace
245 Sets any fixed values; see L<FS::part_svc>.
252 my($recref) = $self->hashref;
257 $self->ut_numbern('svcnum')
259 return $error if $error;
261 #get part_svc (and pkgnum)
262 my($svcpart,$pkgnum);
263 my($svcnum)=$self->getfield('svcnum');
265 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
266 return "Unknown svcnum" unless $cust_svc;
267 $svcpart=$cust_svc->svcpart;
268 $pkgnum=$cust_svc->pkgnum;
270 $svcpart=$self->svcpart;
271 $pkgnum=$self->pkgnum;
273 my($part_svc)=qsearchs('part_svc',{'svcpart'=>$svcpart});
274 return "Unkonwn svcpart" unless $part_svc;
276 #set fixed fields from part_svc
278 foreach $field ( fields('svc_acct') ) {
279 if ( $part_svc->getfield('svc_domain__'. $field. '_flag') eq 'F' ) {
280 $self->setfield($field,$part_svc->getfield('svc_domain__'. $field) );
284 unless ( $whois_hack ) {
285 unless ( $self->email ) { #find out an email address
287 foreach ( qsearch('cust_svc',{'pkgnum'=>$pkgnum}) ) {
288 my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$_->svcnum});
289 push @svc_acct, $svc_acct if $svc_acct;
292 if ( scalar(@svc_acct) == 0 ) {
293 return "Must order an account in package ". $pkgnum. " first";
294 } elsif ( scalar(@svc_acct) > 1 ) {
295 return "More than one account in package ". $pkgnum. ": specify admin contact email";
297 $self->email($svc_acct[0]->username. '@'. $mydomain);
302 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
303 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
304 $recref->{domain} = "$1.$2";
306 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
307 $recref->{domain} = $1;
309 return "Illegal domain ". $recref->{domain}.
310 " (or unknown registry - try \$whois_hack)";
313 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
314 $recref->{action} = $1;
316 $self->ut_textn('purpose');
322 Executes the command:
326 and returns the output.
328 (Always returns I<No match for domian "$domain".> if
329 $FS::svc_domain::whois_hack is set true.)
335 my $domain = $self->domain;
336 return ( "No match for domain \"$domain\"." ) if $whois_hack;
337 open(WHOIS, "whois do $domain |");
341 =item submit_internic
343 Submits a registration email for this domain.
347 sub submit_internic {
350 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
351 return unless $cust_pkg;
352 my cust_main) = qsearchs( 'cust_main', { 'custnum' => $cust_pkg->custnum } );
353 return unless $cust_main;
356 'action' => $self->action,
357 'purpose' => $self->purpose,
358 'domain' => $self->domain,
359 'company' => $cust_main->company
360 || $cust_main->getfield('first'). ' '.
361 $cust_main->getfield('last')
363 'city' => $cust_main->city,
364 'state' => $cust_main->state,
365 'zip' => $cust_main->zip,
366 'country' => $cust_main->country,
367 'last' => $cust_main->getfield('last'),
368 'first' => $cust_main->getfield('first'),
369 'daytime' => $cust_main->daytime,
370 'fax' => $cust_main->fax,
371 'email' => $self->email,
372 'tech_contact' => $tech_contact,
373 'primary' => shift @nameservers,
374 'primary_ip' => shift @nameserver_ips,
378 my @xtemplate = @template;
381 OLOOP: while ( defined( $line = shift @xtemplate ) ) {
383 if ( $line =~ /^###LOOP###$/ ) {
385 LOADBUF: while ( defined( $line = shift @xtemplate ) ) {
386 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
390 'address' => $cust_main->address2
391 ? [ $cust_main->address1, $cust_main->address2 ]
392 : [ $cust_main->address1 ]
394 'secondary' => [ @nameservers ],
395 'secondary_ip' => [ @nameserver_ips ],
398 my @xbuffer = @buffer;
399 SUBLOOP: while ( defined( $line = shift @xbuffer ) ) {
400 if ( $line =~ /###(\w+)###/ ) {
401 #last LOOP unless my($lub)=shift@{$lubs{$1}};
402 next OLOOP unless my $lub = shift @{$lubs{$1}};
403 $line =~ s/###(\w+)###/$lub/e;
413 if ( $line =~ /###(\w+)###/ ) {
414 #$line =~ s/###(\w+)###/$subs{$1}/eg;
415 $line =~ s/###(\w+)###/$subs{$1}/e;
424 if ( $self->action eq "M" ) {
425 $subject = "MODIFY DOMAIN ". $self->domain;
426 } elsif ( $self->action eq "N" ) {
427 $subject = "NEW DOMAIN ". $self->domain;
429 croak "submit_internic called with action ". $self->action;
432 $ENV{SMTPHOSTS} = $smtpmachine;
433 $ENV{MAILADDRESS} = $from;
434 my $header = Mail::Header->new( [
439 "Date: ". time2str("%a, %d %b %Y %X %z", time),
443 my($msg)=Mail::Internet->new(
448 $msg->smtpsend or die "Can't send registration email"; #die? warn?
456 $Id: svc_domain.pm,v 1.4 1998-12-29 11:59:55 ivan Exp $
460 All BIND/DNS fields should be included (and exported).
462 Delete doesn't send a registration template.
464 All registries should be supported.
466 Should change action to a real field.
470 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
471 L<FS::SSH>, L<ssh>, L<dot-qmail>, schema.html from the base documentation,
472 config.html from the base documentation.
476 ivan@voicenet.com 97-jul-21
478 rewrite ivan@sisd.com 98-mar-10
480 add internic bits ivan@sisd.com 98-mar-14
482 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
483 bmccane@maxbaud.net 98-apr-3
485 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
486 ivan@sisd.com 98-jul-17-19
488 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23
490 $Log: svc_domain.pm,v $
491 Revision 1.4 1998-12-29 11:59:55 ivan
492 mostly properly OO, some work still to be done with svc_ stuff
494 Revision 1.3 1998/11/13 09:56:57 ivan
495 change configuration file layout to support multiple distinct databases (with
496 own set of config files, export, etc.)
498 Revision 1.2 1998/10/14 08:18:21 ivan
499 More informative error messages and better doc for admin contact email stuff