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);
19 @ISA = qw( FS::svc_Common );
21 #ask FS::UID to run this stuff for us later
22 $FS::UID::callback{'FS::domain'} = sub {
25 $mydomain = $conf->config('domain');
26 $smtpmachine = $conf->config('smtpmachine');
28 my($internic)="/registries/internic";
29 $tech_contact = $conf->config("$internic/tech_contact");
30 $from = $conf->config("$internic/from");
31 $to = $conf->config("$internic/to");
32 my(@ns) = $conf->config("$internic/nameservers");
34 /^\s*\d+\.\d+\.\d+\.\d+\s+([^\s]+)\s*$/
35 or die "Illegal line in $internic/nameservers";
39 /^\s*(\d+\.\d+\.\d+\.\d+)\s+([^\s]+)\s*$/
40 or die "Illegal line in $internic/nameservers!";
43 @template = map { $_. "\n" } $conf->config("$internic/template");
49 FS::svc_domain - Object methods for svc_domain records
55 $record = new FS::svc_domain \%hash;
56 $record = new FS::svc_domain { 'column' => 'value' };
58 $error = $record->insert;
60 $error = $new_record->replace($old_record);
62 $error = $record->delete;
64 $error = $record->check;
66 $error = $record->suspend;
68 $error = $record->unsuspend;
70 $error = $record->cancel;
74 An FS::svc_domain object represents a domain. FS::svc_domain inherits from
75 FS::svc_Common. The following fields are currently supported:
79 =item svcnum - primary key (assigned automatically for new accounts)
91 Creates a new domain. To add the domain to the database, see L<"insert">.
95 sub table { 'svc_domain'; }
99 Adds this domain to the database. If there is an error, returns the error,
100 otherwise returns false.
102 The additional fields I<pkgnum> and I<svcpart> (see L<FS::cust_svc>) should be
103 defined. An FS::cust_svc record will be created and inserted.
105 The additional field I<action> should be set to I<N> for new domains or I<M>
108 A registration or transfer email will be submitted unless
109 $FS::svc_domain::whois_hack is true.
111 The additional field I<email> can be used to manually set the admin contact
112 email address on this email. Otherwise, the svc_acct records for this package
113 (see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
114 in the same package, it is automatically used. Otherwise an error is returned.
122 local $SIG{HUP} = 'IGNORE';
123 local $SIG{INT} = 'IGNORE';
124 local $SIG{QUIT} = 'IGNORE';
125 local $SIG{TERM} = 'IGNORE';
126 local $SIG{TSTP} = 'IGNORE';
127 local $SIG{PIPE} = 'IGNORE';
129 $error = $self->check;
130 return $error if $error;
132 return "Domain in use (here)"
133 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
135 my $whois = ($self->_whois)[0];
136 return "Domain in use (see whois)"
137 if ( $self->action eq "N" && $whois !~ /^No match for/ );
138 return "Domain not found (see whois)"
139 if ( $self->action eq "M" && $whois =~ /^No match for/ );
141 $error = $self->SUPER::insert;
142 return $error if $error;
144 $self->submit_internic unless $whois_hack;
151 Deletes this domain from the database. If there is an error, returns the
152 error, otherwise returns false.
154 The corresponding FS::cust_svc record will be deleted as well.
156 =item replace OLD_RECORD
158 Replaces OLD_RECORD with this one in the database. If there is an error,
159 returns the error, otherwise returns false.
164 my ( $new, $old ) = ( shift, shift );
167 return "Can't change domain - reorder."
168 if $old->getfield('domain') ne $new->getfield('domain');
170 $new->SUPER::replace($old);
176 Just returns false (no error) for now.
178 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
182 Just returns false (no error) for now.
184 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
188 Just returns false (no error) for now.
190 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
194 Checks all fields to make sure this is a valid domain. If there is an error,
195 returns the error, otherwise returns false. Called by the insert and replace
198 Sets any fixed values; see L<FS::part_svc>.
206 my $x = $self->setfixed;
207 return $x unless ref($x);
212 if ( $self->svcnum ) {
213 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
214 $pkgnum = $cust_svc->pkgnum;
216 $pkgnum = $self->pkgnum;
219 my($recref) = $self->hashref;
221 unless ( $whois_hack ) {
222 unless ( $self->email ) { #find out an email address
224 foreach ( qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } ) ) {
225 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $_->svcnum } );
226 push @svc_acct, $svc_acct if $svc_acct;
229 if ( scalar(@svc_acct) == 0 ) {
230 return "Must order an account in package ". $pkgnum. " first";
231 } elsif ( scalar(@svc_acct) > 1 ) {
232 return "More than one account in package ". $pkgnum. ": specify admin contact email";
234 $self->email($svc_acct[0]->username. '@'. $mydomain);
239 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
240 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
241 $recref->{domain} = "$1.$2";
243 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
244 $recref->{domain} = $1;
246 return "Illegal domain ". $recref->{domain}.
247 " (or unknown registry - try \$whois_hack)";
250 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
251 $recref->{action} = $1;
253 $self->ut_textn('purpose');
259 Executes the command:
263 and returns the output.
265 (Always returns I<No match for domian "$domain".> if
266 $FS::svc_domain::whois_hack is set true.)
272 my $domain = $self->domain;
273 return ( "No match for domain \"$domain\"." ) if $whois_hack;
274 open(WHOIS, "whois do $domain |");
278 =item submit_internic
280 Submits a registration email for this domain.
284 sub submit_internic {
287 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
288 return unless $cust_pkg;
289 my $cust_main = qsearchs( 'cust_main', { 'custnum' => $cust_pkg->custnum } );
290 return unless $cust_main;
293 'action' => $self->action,
294 'purpose' => $self->purpose,
295 'domain' => $self->domain,
296 'company' => $cust_main->company
297 || $cust_main->getfield('first'). ' '.
298 $cust_main->getfield('last')
300 'city' => $cust_main->city,
301 'state' => $cust_main->state,
302 'zip' => $cust_main->zip,
303 'country' => $cust_main->country,
304 'last' => $cust_main->getfield('last'),
305 'first' => $cust_main->getfield('first'),
306 'daytime' => $cust_main->daytime,
307 'fax' => $cust_main->fax,
308 'email' => $self->email,
309 'tech_contact' => $tech_contact,
310 'primary' => shift @nameservers,
311 'primary_ip' => shift @nameserver_ips,
315 my @xtemplate = @template;
318 OLOOP: while ( defined( $line = shift @xtemplate ) ) {
320 if ( $line =~ /^###LOOP###$/ ) {
322 LOADBUF: while ( defined( $line = shift @xtemplate ) ) {
323 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
327 'address' => $cust_main->address2
328 ? [ $cust_main->address1, $cust_main->address2 ]
329 : [ $cust_main->address1 ]
331 'secondary' => [ @nameservers ],
332 'secondary_ip' => [ @nameserver_ips ],
335 my @xbuffer = @buffer;
336 SUBLOOP: while ( defined( $line = shift @xbuffer ) ) {
337 if ( $line =~ /###(\w+)###/ ) {
338 #last LOOP unless my($lub)=shift@{$lubs{$1}};
339 next OLOOP unless my $lub = shift @{$lubs{$1}};
340 $line =~ s/###(\w+)###/$lub/e;
350 if ( $line =~ /###(\w+)###/ ) {
351 #$line =~ s/###(\w+)###/$subs{$1}/eg;
352 $line =~ s/###(\w+)###/$subs{$1}/e;
361 if ( $self->action eq "M" ) {
362 $subject = "MODIFY DOMAIN ". $self->domain;
363 } elsif ( $self->action eq "N" ) {
364 $subject = "NEW DOMAIN ". $self->domain;
366 croak "submit_internic called with action ". $self->action;
369 $ENV{SMTPHOSTS} = $smtpmachine;
370 $ENV{MAILADDRESS} = $from;
371 my $header = Mail::Header->new( [
376 "Date: ". time2str("%a, %d %b %Y %X %z", time),
380 my($msg)=Mail::Internet->new(
385 $msg->smtpsend or die "Can't send registration email"; #die? warn?
393 $Id: svc_domain.pm,v 1.7 1999-04-07 14:40:15 ivan Exp $
397 All BIND/DNS fields should be included (and exported).
399 Delete doesn't send a registration template.
401 All registries should be supported.
403 Should change action to a real field.
405 The $recref stuff in sub check should be cleaned up.
409 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
410 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.
414 ivan@voicenet.com 97-jul-21
416 rewrite ivan@sisd.com 98-mar-10
418 add internic bits ivan@sisd.com 98-mar-14
420 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
421 bmccane@maxbaud.net 98-apr-3
423 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
424 ivan@sisd.com 98-jul-17-19
426 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23
428 $Log: svc_domain.pm,v $
429 Revision 1.7 1999-04-07 14:40:15 ivan
430 use all stuff that's qsearch'ed to avoid warnings
432 Revision 1.6 1999/01/25 12:26:17 ivan
433 yet more mod_perl stuff
435 Revision 1.5 1998/12/30 00:30:47 ivan
436 svc_ stuff is more properly OO - has a common superclass FS::svc_Common
438 Revision 1.3 1998/11/13 09:56:57 ivan
439 change configuration file layout to support multiple distinct databases (with
440 own set of config files, export, etc.)
442 Revision 1.2 1998/10/14 08:18:21 ivan
443 More informative error messages and better doc for admin contact email stuff