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';
125 $error = $self->check;
126 return $error if $error;
128 return "Domain in use (here)"
129 if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
131 my $whois = ($self->_whois)[0];
132 return "Domain in use (see whois)"
133 if ( $self->action eq "N" && $whois !~ /^No match for/ );
134 return "Domain not found (see whois)"
135 if ( $self->action eq "M" && $whois =~ /^No match for/ );
137 $error = $self->SUPER::insert;
138 return $error if $error;
140 $self->submit_internic unless $whois_hack;
147 Deletes this domain from the database. If there is an error, returns the
148 error, otherwise returns false.
150 The corresponding FS::cust_svc record will be deleted as well.
152 =item replace OLD_RECORD
154 Replaces OLD_RECORD with this one in the database. If there is an error,
155 returns the error, otherwise returns false.
160 my ( $new, $old ) = ( shift, shift );
163 return "Can't change domain - reorder."
164 if $old->getfield('domain') ne $new->getfield('domain');
166 $new->SUPER::replace($old);
172 Just returns false (no error) for now.
174 Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
178 Just returns false (no error) for now.
180 Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
184 Just returns false (no error) for now.
186 Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
190 Checks all fields to make sure this is a valid domain. If there is an error,
191 returns the error, otherwise returns false. Called by the insert and replace
194 Sets any fixed values; see L<FS::part_svc>.
202 my $x = $self->setfixed;
203 return $x unless ref($x);
208 if ( $self->svcnum ) {
209 my $cust_svc = qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
210 $pkgnum = $cust_svc->pkgnum;
212 $pkgnum = $self->pkgnum;
215 my($recref) = $self->hashref;
217 unless ( $whois_hack ) {
218 unless ( $self->email ) { #find out an email address
220 foreach ( qsearch( 'cust_svc', { 'pkgnum' => $pkgnum } ) ) {
221 my $svc_acct = qsearchs( 'svc_acct', { 'svcnum' => $_->svcnum } );
222 push @svc_acct, $svc_acct if $svc_acct;
225 if ( scalar(@svc_acct) == 0 ) {
226 return "Must order an account in package ". $pkgnum. " first";
227 } elsif ( scalar(@svc_acct) > 1 ) {
228 return "More than one account in package ". $pkgnum. ": specify admin contact email";
230 $self->email($svc_acct[0]->username. '@'. $mydomain);
235 #if ( $recref->{domain} =~ /^([\w\-\.]{1,22})\.(com|net|org|edu)$/ ) {
236 if ( $recref->{domain} =~ /^([\w\-]{1,22})\.(com|net|org|edu)$/ ) {
237 $recref->{domain} = "$1.$2";
239 } elsif ( $whois_hack && $recref->{domain} =~ /^([\w\-\.]+)$/ ) {
240 $recref->{domain} = $1;
242 return "Illegal domain ". $recref->{domain}.
243 " (or unknown registry - try \$whois_hack)";
246 $recref->{action} =~ /^(M|N)$/ or return "Illegal action";
247 $recref->{action} = $1;
249 $self->ut_textn('purpose');
255 Executes the command:
259 and returns the output.
261 (Always returns I<No match for domian "$domain".> if
262 $FS::svc_domain::whois_hack is set true.)
268 my $domain = $self->domain;
269 return ( "No match for domain \"$domain\"." ) if $whois_hack;
270 open(WHOIS, "whois do $domain |");
274 =item submit_internic
276 Submits a registration email for this domain.
280 sub submit_internic {
283 my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
284 return unless $cust_pkg;
285 my $cust_main = qsearchs( 'cust_main', { 'custnum' => $cust_pkg->custnum } );
286 return unless $cust_main;
289 'action' => $self->action,
290 'purpose' => $self->purpose,
291 'domain' => $self->domain,
292 'company' => $cust_main->company
293 || $cust_main->getfield('first'). ' '.
294 $cust_main->getfield('last')
296 'city' => $cust_main->city,
297 'state' => $cust_main->state,
298 'zip' => $cust_main->zip,
299 'country' => $cust_main->country,
300 'last' => $cust_main->getfield('last'),
301 'first' => $cust_main->getfield('first'),
302 'daytime' => $cust_main->daytime,
303 'fax' => $cust_main->fax,
304 'email' => $self->email,
305 'tech_contact' => $tech_contact,
306 'primary' => shift @nameservers,
307 'primary_ip' => shift @nameserver_ips,
311 my @xtemplate = @template;
314 OLOOP: while ( defined( $line = shift @xtemplate ) ) {
316 if ( $line =~ /^###LOOP###$/ ) {
318 LOADBUF: while ( defined( $line = shift @xtemplate ) ) {
319 last LOADBUF if ( $line =~ /^###ENDLOOP###$/ );
323 'address' => $cust_main->address2
324 ? [ $cust_main->address1, $cust_main->address2 ]
325 : [ $cust_main->address1 ]
327 'secondary' => [ @nameservers ],
328 'secondary_ip' => [ @nameserver_ips ],
331 my @xbuffer = @buffer;
332 SUBLOOP: while ( defined( $line = shift @xbuffer ) ) {
333 if ( $line =~ /###(\w+)###/ ) {
334 #last LOOP unless my($lub)=shift@{$lubs{$1}};
335 next OLOOP unless my $lub = shift @{$lubs{$1}};
336 $line =~ s/###(\w+)###/$lub/e;
346 if ( $line =~ /###(\w+)###/ ) {
347 #$line =~ s/###(\w+)###/$subs{$1}/eg;
348 $line =~ s/###(\w+)###/$subs{$1}/e;
357 if ( $self->action eq "M" ) {
358 $subject = "MODIFY DOMAIN ". $self->domain;
359 } elsif ( $self->action eq "N" ) {
360 $subject = "NEW DOMAIN ". $self->domain;
362 croak "submit_internic called with action ". $self->action;
365 $ENV{SMTPHOSTS} = $smtpmachine;
366 $ENV{MAILADDRESS} = $from;
367 my $header = Mail::Header->new( [
372 "Date: ". time2str("%a, %d %b %Y %X %z", time),
376 my($msg)=Mail::Internet->new(
381 $msg->smtpsend or die "Can't send registration email"; #die? warn?
389 $Id: svc_domain.pm,v 1.5 1998-12-30 00:30:47 ivan Exp $
393 All BIND/DNS fields should be included (and exported).
395 Delete doesn't send a registration template.
397 All registries should be supported.
399 Should change action to a real field.
401 The $recref stuff in sub check should be cleaned up.
405 L<FS::svc_Common>, L<FS::Record>, L<FS::Conf>, L<FS::cust_svc>,
406 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.
410 ivan@voicenet.com 97-jul-21
412 rewrite ivan@sisd.com 98-mar-10
414 add internic bits ivan@sisd.com 98-mar-14
416 Changed 'day' to 'daytime' because Pg6.3 reserves the day word
417 bmccane@maxbaud.net 98-apr-3
419 /var/spool/freeside/conf/registries/internic/, Mail::Internet, etc.
420 ivan@sisd.com 98-jul-17-19
422 pod, some FS::Conf (not complete) ivan@sisd.com 98-sep-23
424 $Log: svc_domain.pm,v $
425 Revision 1.5 1998-12-30 00:30:47 ivan
426 svc_ stuff is more properly OO - has a common superclass FS::svc_Common
428 Revision 1.3 1998/11/13 09:56:57 ivan
429 change configuration file layout to support multiple distinct databases (with
430 own set of config files, export, etc.)
432 Revision 1.2 1998/10/14 08:18:21 ivan
433 More informative error messages and better doc for admin contact email stuff