1 package FS::svc_domain;
4 use vars qw(@ISA @EXPORT_OK $whois_hack $conf $mydomain $smtpmachine
5 $tech_contact $from $to @nameservers @nameserver_ips @template
12 use FS::Record qw(fields qsearch qsearchs);
16 @ISA = qw(FS::Record Exporter);
17 @EXPORT_OK = qw(fields);
19 #ask FS::UID to run this stuff for us later
20 $FS::UID::callback{'FS::domain'} = sub {
23 $mydomain = $conf->config('domain');
24 $smtpmachine = $conf->config('smtpmachine');
26 my($internic)="/registries/internic";
27 $tech_contact = $conf->config("$internic/tech_contact");
28 $from = $conf->config("$internic/from");
29 $to = $conf->config("$internic/to");
30 my(@ns) = $conf->config("$internic/nameservers");
32 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
33 or die "Illegal line in $internic/nameservers";
37 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
38 or die "Illegal line in $internic/nameservers!";
41 @template = map { $_. "\n" } $conf->config("$internic/template");
47 FS::svc_domain - Object methods for svc_domain records
53 $record = create FS::svc_domain \%hash;
54 $record = create FS::svc_domain { 'column' => 'value' };
56 $error = $record->insert;
58 $error = $new_record->replace($old_record);
60 $error = $record->delete;
62 $error = $record->check;
64 $error = $record->suspend;
66 $error = $record->unsuspend;
68 $error = $record->cancel;
72 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
73 FS::Record. The following fields are currently supported:
77 =item svcnum - primary key (assigned automatically for new accounts)
89 Creates a new domain. To add the domain to the database, see L<"insert">.
94 my($proto,$hashref)=@_;
96 #now in FS::Record::new
98 #foreach $field (fields('svc_domain')) {
99 # $hashref->{$field}='' unless defined $hashref->{$field};
102 $proto->new('svc_domain',$hashref);
108 Adds this domain to the database. If there is an error, returns the error,
109 otherwise returns false.
111 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
112 defined. An FS::cust_svc record will be created and inserted.
114 The additional field I<action> should be set to I<N> for new domains or I<M>
117 A registration or transfer email will be submitted unless
118 $FS::svc_domain::whois_hack is true.
120 The additional field I<email> can be used to manually set the admin contact
121 email address on this email. Otherwise, the svc_acct records for this package
122 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
123 in the same package, it is automatically used. Otherwise an error is returned.
131 local $SIG{HUP} = 'IGNORE';
132 local $SIG{INT} = 'IGNORE';
133 local $SIG{QUIT} = 'IGNORE';
134 local $SIG{TERM} = 'IGNORE';
135 local $SIG{TSTP} = 'IGNORE';
138 return $error if $error;
140 return "Domain in use (here)"
141 if qsearchs('svc_domain',{'domain'=> $self->domain } );
143 my($whois)=(($self->_whois)[0]);
144 return "Domain in use (see whois)"
145 if ( $self->action eq "N" && $whois !~ /^No match for/ );
146 return "Domain not found (see whois)"
147 if ( $self->action eq "M" && $whois =~ /^No match for/ );
149 my($svcnum)=$self->getfield('svcnum');
152 $cust_svc=create FS::cust_svc ( {
154 'pkgnum' => $self->getfield('pkgnum'),
155 'svcpart' => $self->getfield('svcpart'),
157 my($error) = $cust_svc->insert;
158 return $error if $error;
159 $svcnum = $self->setfield('svcnum',$cust_svc->getfield('svcnum'));
164 $cust_svc->del if $cust_svc;
168 $self->submit_internic unless $whois_hack;
175 Deletes this domain from the database. If there is an error, returns the
176 error, otherwise returns false.
178 The corresponding FS::cust_svc record will be deleted as well.
186 my($svcnum)=$self->getfield('svcnum');
189 return $error if $error;
191 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
192 $error = $cust_svc->del;
193 return $error if $error;
198 =item replace OLD_RECORD
200 Replaces OLD_RECORD with this one in the database. If there is an error,
201 returns the error, otherwise returns false.
209 return "(Old) Not a svc_domain record!" unless $old->table eq "svc_domain";
210 return "Can't change svcnum!"
211 unless $old->getfield('svcnum') eq $new->getfield('svcnum');
213 return "Can't change domain - reorder."
214 if $old->getfield('domain') ne $new->getfield('domain');
217 return $error if $error;
219 local $SIG{HUP} = 'IGNORE';
220 local $SIG{INT} = 'IGNORE';
221 local $SIG{QUIT} = 'IGNORE';
222 local $SIG{TERM} = 'IGNORE';
223 local $SIG{TSTP} = 'IGNORE';
225 $error = $new->rep($old);
226 return $error if $error;
234 Just returns false (no error) for now.
236 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
246 Just returns false (no error) for now.
248 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
258 Just returns false (no error) for now.
260 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
270 Checks all fields to make sure this is a valid domain. If there is an error,
271 returns the error, otherwise returns false. Called by the insert and replace
274 Sets any fixed values; see L<FS::part_svc>.
280 return "Not a svc_domain record!" unless $self->table eq "svc_domain";
281 my($recref) = $self->hashref;
283 $recref->{svcnum} =~ /^(\d*)$/ or return "Illegal svcnum";
284 $recref->{svcnum} = $1;
286 #get part_svc (and pkgnum)
287 my($svcpart,$pkgnum);
288 my($svcnum)=$self->getfield('svcnum');
290 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
291 return "Unknown svcnum" unless $cust_svc;
292 $svcpart=$cust_svc->svcpart;
293 $pkgnum=$cust_svc->pkgnum;
295 $svcpart=$self->svcpart;
296 $pkgnum=$self->pkgnum;
298 my($part_svc)=qsearchs('part_svc',{'svcpart'=>$svcpart});
299 return "Unkonwn svcpart" unless $part_svc;
301 #set fixed fields from part_svc
303 foreach $field ( fields('svc_acct') ) {
304 if ( $part_svc->getfield('svc_domain__'. $field. '_flag') eq 'F' ) {
305 $self->setfield($field,$part_svc->getfield('svc_domain__'. $field) );
309 unless ( $whois_hack ) {
310 unless ( $self->email ) { #find out an email address
312 foreach ( qsearch('cust_svc',{'pkgnum'=>$pkgnum}) ) {
313 my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$_->svcnum});
314 push @svc_acct, $svc_acct if $svc_acct;
317 if ( scalar(@svc_acct) == 0 ) {
318 return "Must order an account in package ". $pkgnum. " first";
319 } elsif ( scalar(@svc_acct) > 1 ) {
320 return "More than one account in package ". $pkgnum. ": specify admin contact email";
322 $self->email($svc_acct[0]->username. '@'. $mydomain);
327 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
328 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
329 $recref->{domain} = "$1.$2";
331 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
332 $recref->{domain} = $1;
334 return "Illegal domain ". $recref->{domain}.
335 " (or unknown registry - try \$whois_hack)";
338 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
339 $recref->{action} = $1;
341 $self->ut_textn('purpose');
347 Executes the command:
351 and returns the output.
353 (Always returns I<No match for domian "$domain".> if
354 $FS::svc_domain::whois_hack is set true.)
360 my($domain)=$self->domain;
361 return ( "No match for domain \"$domain\"." ) if $whois_hack;
362 open(WHOIS,"whois do $domain |");
366 =item submit_internic
368 Submits a registration email for this domain.
372 sub submit_internic {
375 my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$self->pkgnum});
376 return unless $cust_pkg;
377 my($cust_main)=qsearchs('cust_main',{'custnum'=>$cust_pkg->custnum});
378 return unless $cust_main;
381 'action' => $self->action,
382 'purpose' => $self->purpose,
383 'domain' => $self->domain,
384 'company' => $cust_main->company
385 || $cust_main->getfield('first'). ' '.
386 $cust_main->getfield('last')
388 'city' => $cust_main->city,
389 'state' => $cust_main->state,
390 'zip' => $cust_main->zip,
391 'country' => $cust_main->country,
392 'last' => $cust_main->getfield('last'),
393 'first' => $cust_main->getfield('first'),
394 'daytime' => $cust_main->daytime,
395 'fax' => $cust_main->fax,
396 'email' => $self->email,
397 'tech_contact' => $tech_contact,
398 'primary' => shift @nameservers,
399 'primary_ip' => shift @nameserver_ips,
403 my(@xtemplate)=@template;
406 OLOOP: while ( defined($line = shift @xtemplate) ) {
408 if ( $line =~ /^###LOOP###$/ ) {
410 LOADBUF: while ( defined($line = shift @xtemplate) ) {
411 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
415 'address' => $cust_main->address2
416 ? [ $cust_main->address1, $cust_main->address2 ]
417 : [ $cust_main->address1 ]
419 'secondary' => [ @nameservers ],
420 'secondary_ip' => [ @nameserver_ips ],
423 my(@xbuffer)=@buffer;
424 SUBLOOP: while ( defined($line = shift @xbuffer) ) {
425 if ( $line =~ /###(\w+)###/ ) {
426 #last LOOP unless my($lub)=shift@{$lubs{$1}};
427 next OLOOP unless my $lub = shift @{$lubs{$1}};
428 $line =~ s/###(\w+)###/$lub/e;
438 if ( $line =~ /###(\w+)###/ ) {
439 #$line =~ s/###(\w+)###/$subs{$1}/eg;
440 $line =~ s/###(\w+)###/$subs{$1}/e;
449 if ( $self->action eq "M" ) {
450 $subject = "MODIFY DOMAIN ". $self->domain;
451 } elsif ($self->action eq "N" ) {
452 $subject = "NEW DOMAIN ". $self->domain;
454 croak "submit_internic called with action ". $self->action;
457 $ENV{SMTPHOSTS}=$smtpmachine;
458 $ENV{MAILADDRESS}=$from;
459 my($header)=Mail::Header->new( [
464 "Date: ". time2str("%a, %d %b %Y %X %z",time),
468 my($msg)=Mail::Internet->new(
473 $msg->smtpsend or die "Can't send registration email"; #die? warn?
481 It doesn't properly override FS::Record yet.
483 All BIND/DNS fields should be included (and exported).
485 All registries should be supported.
487 Not all configuration access is through FS::Conf!
489 Should change action to a real field.
493 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
494 L<FS::SSH>, L<ssh>, L<dot-qmail>, schema.html from the base documentation,
495 config.html from the base documentation.
499 $Id: svc_domain.pm,v 1.3 1998-11-13 09:56:57 ivan Exp $
503 ivan@voicenet.com 97-jul-21
505 rewrite ivan@sisd.com 98-mar-10
507 add internic bits ivan@sisd.com 98-mar-14
509 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
510 bmccane@maxbaud.net 98-apr-3
512 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
513 ivan@sisd.com 98-jul-17-19
515 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23
517 $Log: svc_domain.pm,v $
518 Revision 1.3 1998-11-13 09:56:57 ivan
519 change configuration file layout to support multiple distinct databases (with
520 own set of config files, export, etc.)
522 Revision 1.2 1998/10/14 08:18:21 ivan
523 More informative error messages and better doc for admin contact email stuff