1 package FS::svc_domain;
4 use vars qw(@ISA @EXPORT_OK $whois_hack $conf $mydomain $smtpmachine);
10 use FS::Record qw(fields qsearch qsearchs);
14 @ISA = qw(FS::Record Exporter);
15 @EXPORT_OK = qw(fields);
19 $mydomain = $conf->config('domain');
20 $smtpmachine = $conf->config('smtpmachine');
22 my($internic)="/var/spool/freeside/conf/registries/internic";
23 my($conf_tech)="$internic/tech_contact";
24 my($conf_from)="$internic/from";
25 my($conf_to)="$internic/to";
26 my($nameservers)="$internic/nameservers";
27 my($template)="$internic/template";
29 open(TECH_CONTACT,$conf_tech) or die "Can't open $conf_tech: $!";
30 my($tech_contact)=map {
31 /^(.*)$/ or die "Illegal line in $conf_tech!"; #yes, we trust the file
33 } grep $_ !~ /^(#|$)/, <TECH_CONTACT>;
36 open(FROM,$conf_from) or die "Can't open $conf_from: $!";
38 /^(.*)$/ or die "Illegal line in $conf_from!"; #yes, we trust the file
40 } grep $_ !~ /^(#|$)/, <FROM>;
43 open(TO,$conf_to) or die "Can't open $conf_to: $!";
45 /^(.*)$/ or die "Illegal line in $conf_to!"; #yes, we trust the file
47 } grep $_ !~ /^(#|$)/, <TO>;
50 open(NAMESERVERS,$nameservers) or die "Can't open $nameservers: $!";
51 my(@nameservers)=map {
52 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
53 or die "Illegal line in $nameservers!"; #yes, we trust the file
55 } grep $_ !~ /^(#|$)/, <NAMESERVERS>;
57 open(NAMESERVERS,$nameservers) or die "Can't open $nameservers: $!";
58 my(@nameserver_ips)=map {
59 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
60 or die "Illegal line in $nameservers!"; #yes, we trust the file
62 } grep $_ !~ /^(#|$)/, <NAMESERVERS>;
65 open(TEMPLATE,$template) or die "Can't open $template: $!";
67 /^(.*)$/ or die "Illegal line in $to!"; #yes, we trust the file
74 FS::svc_domain - Object methods for svc_domain records
80 $record = create FS::svc_domain \%hash;
81 $record = create FS::svc_domain { 'column' => 'value' };
83 $error = $record->insert;
85 $error = $new_record->replace($old_record);
87 $error = $record->delete;
89 $error = $record->check;
91 $error = $record->suspend;
93 $error = $record->unsuspend;
95 $error = $record->cancel;
99 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
100 FS::Record. The following fields are currently supported:
104 =item svcnum - primary key (assigned automatically for new accounts)
116 Creates a new domain. To add the domain to the database, see L<"insert">.
121 my($proto,$hashref)=@_;
123 #now in FS::Record::new
125 #foreach $field (fields('svc_domain')) {
126 # $hashref->{$field}='' unless defined $hashref->{$field};
129 $proto->new('svc_domain',$hashref);
135 Adds this domain to the database. If there is an error, returns the error,
136 otherwise returns false.
138 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
139 defined. An FS::cust_svc record will be created and inserted.
141 The additional field I<action> should be set to I<N> for new domains or I<M>
144 A registration or transfer email will be submitted unless
145 $FS::svc_domain::whois_hack is true.
153 local $SIG{HUP} = 'IGNORE';
154 local $SIG{INT} = 'IGNORE';
155 local $SIG{QUIT} = 'IGNORE';
156 local $SIG{TERM} = 'IGNORE';
157 local $SIG{TSTP} = 'IGNORE';
160 return $error if $error;
162 return "Domain in use (here)"
163 if qsearchs('svc_domain',{'domain'=> $self->domain } );
165 my($whois)=(($self->_whois)[0]);
166 return "Domain in use (see whois)"
167 if ( $self->action eq "N" && $whois !~ /^No match for/ );
168 return "Domain not found (see whois)"
169 if ( $self->action eq "M" && $whois =~ /^No match for/ );
171 my($svcnum)=$self->getfield('svcnum');
174 $cust_svc=create FS::cust_svc ( {
176 'pkgnum' => $self->getfield('pkgnum'),
177 'svcpart' => $self->getfield('svcpart'),
179 my($error) = $cust_svc->insert;
180 return $error if $error;
181 $svcnum = $self->setfield('svcnum',$cust_svc->getfield('svcnum'));
186 $cust_svc->del if $cust_svc;
190 $self->submit_internic unless $whois_hack;
197 Deletes this domain from the database. If there is an error, returns the
198 error, otherwise returns false.
200 The corresponding FS::cust_svc record will be deleted as well.
208 my($svcnum)=$self->getfield('svcnum');
211 return $error if $error;
213 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
214 $error = $cust_svc->del;
215 return $error if $error;
220 =item replace OLD_RECORD
222 Replaces OLD_RECORD with this one in the database. If there is an error,
223 returns the error, otherwise returns false.
231 return "(Old) Not a svc_domain record!" unless $old->table eq "svc_domain";
232 return "Can't change svcnum!"
233 unless $old->getfield('svcnum') eq $new->getfield('svcnum');
235 return "Can't change domain - reorder."
236 if $old->getfield('domain') ne $new->getfield('domain');
239 return $error if $error;
241 local $SIG{HUP} = 'IGNORE';
242 local $SIG{INT} = 'IGNORE';
243 local $SIG{QUIT} = 'IGNORE';
244 local $SIG{TERM} = 'IGNORE';
245 local $SIG{TSTP} = 'IGNORE';
247 $error = $new->rep($old);
248 return $error if $error;
256 Just returns false (no error) for now.
258 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
268 Just returns false (no error) for now.
270 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
280 Just returns false (no error) for now.
282 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
292 Checks all fields to make sure this is a valid domain. If there is an error,
293 returns the error, otherwise returns false. Called by the insert and replace
296 Sets any fixed values; see L<FS::part_svc>.
302 return "Not a svc_domain record!" unless $self->table eq "svc_domain";
303 my($recref) = $self->hashref;
305 $recref->{svcnum} =~ /^(\d*)$/ or return "Illegal svcnum";
306 $recref->{svcnum} = $1;
308 #get part_svc (and pkgnum)
309 my($svcpart,$pkgnum);
310 my($svcnum)=$self->getfield('svcnum');
312 my($cust_svc)=qsearchs('cust_svc',{'svcnum'=>$svcnum});
313 return "Unknown svcnum" unless $cust_svc;
314 $svcpart=$cust_svc->svcpart;
315 $pkgnum=$cust_svc->pkgnum;
317 $svcpart=$self->svcpart;
318 $pkgnum=$self->pkgnum;
320 my($part_svc)=qsearchs('part_svc',{'svcpart'=>$svcpart});
321 return "Unkonwn svcpart" unless $part_svc;
323 #set fixed fields from part_svc
325 foreach $field ( fields('svc_acct') ) {
326 if ( $part_svc->getfield('svc_domain__'. $field. '_flag') eq 'F' ) {
327 $self->setfield($field,$part_svc->getfield('svc_domain__'. $field) );
331 unless ( $whois_hack ) {
332 unless ( $self->email ) { #find out an email address
334 foreach ( qsearch('cust_svc',{'pkgnum'=>$pkgnum}) ) {
335 my($svc_acct)=qsearchs('svc_acct',{'svcnum'=>$_->svcnum});
336 push @svc_acct, $svc_acct if $svc_acct;
339 if ( scalar(@svc_acct) == 0 ) {
340 return "Must order an account first";
341 } elsif ( scalar(@svc_acct) > 1 ) {
342 return "More than one account in package ". $pkgnum. ": specify admin contact email";
344 $self->email($svc_acct[0]->username. '@'. $mydomain);
349 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
350 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
351 $recref->{domain} = "$1.$2";
353 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
354 $recref->{domain} = $1;
356 return "Illegal domain ". $recref->{domain}.
357 " (or unknown registry - try \$whois_hack)";
360 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
361 $recref->{action} = $1;
363 $self->ut_textn('purpose');
369 Executes the command:
373 and returns the output.
375 (Always returns I<No match for domian "$domain".> if
376 $FS::svc_domain::whois_hack is set true.)
382 my($domain)=$self->domain;
383 return ( "No match for domain \"$domain\"." ) if $whois_hack;
384 open(WHOIS,"whois do $domain |");
388 =item submit_internic
390 Submits a registration email for this domain.
394 sub submit_internic {
397 my($cust_pkg)=qsearchs('cust_pkg',{'pkgnum'=>$self->pkgnum});
398 return unless $cust_pkg;
399 my($cust_main)=qsearchs('cust_main',{'custnum'=>$cust_pkg->custnum});
400 return unless $cust_main;
403 'action' => $self->action,
404 'purpose' => $self->purpose,
405 'domain' => $self->domain,
406 'company' => $cust_main->company
407 || $cust_main->getfield('first'). ' '.
408 $cust_main->getfield('last')
410 'city' => $cust_main->city,
411 'state' => $cust_main->state,
412 'zip' => $cust_main->zip,
413 'country' => $cust_main->country,
414 'last' => $cust_main->getfield('last'),
415 'first' => $cust_main->getfield('first'),
416 'daytime' => $cust_main->daytime,
417 'fax' => $cust_main->fax,
418 'email' => $self->email,
419 'tech_contact' => $tech_contact,
420 'primary' => shift @nameservers,
421 'primary_ip' => shift @nameserver_ips,
425 my(@xtemplate)=@template;
428 OLOOP: while ( defined($line = shift @xtemplate) ) {
430 if ( $line =~ /^###LOOP###$/ ) {
432 LOADBUF: while ( defined($line = shift @xtemplate) ) {
433 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
437 'address' => $cust_main->address2
438 ? [ $cust_main->address1, $cust_main->address2 ]
439 : [ $cust_main->address1 ]
441 'secondary' => [ @nameservers ],
442 'secondary_ip' => [ @nameserver_ips ],
445 my(@xbuffer)=@buffer;
446 SUBLOOP: while ( defined($line = shift @xbuffer) ) {
447 if ( $line =~ /###(\w+)###/ ) {
448 #last LOOP unless my($lub)=shift@{$lubs{$1}};
449 next OLOOP unless my $lub = shift @{$lubs{$1}};
450 $line =~ s/###(\w+)###/$lub/e;
460 if ( $line =~ /###(\w+)###/ ) {
461 #$line =~ s/###(\w+)###/$subs{$1}/eg;
462 $line =~ s/###(\w+)###/$subs{$1}/e;
471 if ( $self->action eq "M" ) {
472 $subject = "MODIFY DOMAIN ". $self->domain;
473 } elsif ($self->action eq "N" ) {
474 $subject = "NEW DOMAIN ". $self->domain;
476 croak "submit_internic called with action ". $self->action;
479 $ENV{SMTPHOSTS}=$smtpmachine;
480 $ENV{MAILADDRESS}=$from;
481 my($header)=Mail::Header->new( [
486 "Date: ". time2str("%a, %d %b %Y %X %z",time),
490 my($msg)=Mail::Internet->new(
495 $msg->smtpsend or die "Can't send registration email"; #die? warn?
503 It doesn't properly override FS::Record yet.
505 All BIND/DNS fields should be included (and exported).
507 All registries should be supported.
509 Not all configuration access is through FS::Conf!
511 Should change action to a real field.
515 L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>, L<FS::part_svc>, L<FS::cust_pkg>,
516 L<FS::SSH>, L<ssh>, L<dot-qmail>, schema.html from the base documentation,
517 config.html from the base documentation.
521 ivan@voicenet.com 97-jul-21
523 rewrite ivan@sisd.com 98-mar-10
525 add internic bits ivan@sisd.com 98-mar-14
527 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
528 bmccane@maxbaud.net 98-apr-3
530 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
531 ivan@sisd.com 98-jul-17-19
533 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23