summaryrefslogtreecommitdiff
path: root/FS
diff options
context:
space:
mode:
authorivan <ivan>2000-02-03 05:17:39 +0000
committerivan <ivan>2000-02-03 05:17:39 +0000
commit5bd5f206a77cf975515d955119d4dff7764a2d8c (patch)
tree1e344342389a47fe1b96e214ac757dfb5417f041 /FS
parent3bfec7cf75a1a4eb4da1cdf8c64003bd6babcd81 (diff)
beginning of DNS and Apache support
Diffstat (limited to 'FS')
-rw-r--r--FS/FS/cust_pkg.pm3
-rw-r--r--FS/FS/domain_record.pm182
-rw-r--r--FS/FS/svc_domain.pm68
-rw-r--r--FS/FS/svc_www.pm242
4 files changed, 493 insertions, 2 deletions
diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 1dcdab8..08be4e4 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -16,6 +16,7 @@ use FS::pkg_svc;
use FS::svc_acct;
use FS::svc_acct_sm;
use FS::svc_domain;
+use FS::svc_www;
@ISA = qw( FS::Record );
@@ -490,7 +491,7 @@ sub order {
=head1 VERSION
-$Id: cust_pkg.pm,v 1.3 1999-11-08 21:38:38 ivan Exp $
+$Id: cust_pkg.pm,v 1.4 2000-02-03 05:16:52 ivan Exp $
=head1 BUGS
diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm
new file mode 100644
index 0000000..9b7081b
--- /dev/null
+++ b/FS/FS/domain_record.pm
@@ -0,0 +1,182 @@
+package FS::domain_record;
+
+use strict;
+use vars qw( @ISA );
+#use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearchs );
+use FS::svc_domain;
+
+@ISA = qw(FS::Record);
+
+=head1 NAME
+
+FS::domain_record - Object methods for domain_record records
+
+=head1 SYNOPSIS
+
+ use FS::domain_record;
+
+ $record = new FS::domain_record \%hash;
+ $record = new FS::domain_record { 'column' => 'value' };
+
+ $error = $record->insert;
+
+ $error = $new_record->replace($old_record);
+
+ $error = $record->delete;
+
+ $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::domain_record object represents an entry in a DNS zone.
+FS::domain_record inherits from FS::Record. The following fields are currently
+supported:
+
+=over 4
+
+=item recnum - primary key
+
+=item svcnum - Domain (see L<FS::svc_domain>) of this entry
+
+=item reczone - partial (or full) zone for this entry
+
+=item recaf - address family for this entry, currently only `IN' is recognized.
+
+=item rectype - record type for this entry (A, MX, etc.)
+
+=item recdata - data for this entry
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new entry. To add the example to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to. You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+sub table { 'domain_record'; }
+
+=item insert
+
+Adds this record to the database. If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database. If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+=item check
+
+Checks all fields to make sure this is a valid example. If there is
+an error, returns the error, otherwise returns false. Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+ my $self = shift;
+
+ my $error =
+ $self->ut_numbern('recnum')
+ || $self->ut_number('svcnum')
+ ;
+ return $error if $error;
+
+ return "Unknown svcnum (in svc_domain)"
+ unless qsearchs('svc_domain', { 'svcnum' => $self->svcnum } );
+
+ $self->reczone =~ /^(@|[a-z0-9\.\-]+)$/
+ or return "Illegal reczone: ". $self->reczone;
+ $self->reczone($1);
+
+ $self->recaf =~ /^(IN)$/ or return "Illegal recaf: ". $self->recaf;
+ $self->recaf($1);
+
+ $self->rectype =~ /^(SOA|NS|MX|A|PTR|CNAME)$/
+ or return "Illegal rectype (only SOA NS MX A PTR CNAME recognized): ".
+ $self->rectype;
+ $self->rectype($1);
+
+ if ( $self->rectype eq 'SOA' ) {
+ my $recdata = $self->recdata;
+ $recdata =~ s/\s+/ /g;
+ $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( (\d+ ){5}\))$/
+ or return "Illegal data for SOA reocrd: $recdata";
+ $self->recdata($1);
+ } elsif ( $self->rectype eq 'NS' ) {
+ $self->recdata =~ /^([a-z0-9\.\-]+)$/
+ or return "Illegal data for NS record: ". $self->recdata;
+ $self->recdata($1);
+ } elsif ( $self->rectype eq 'MX' ) {
+ $self->recdata =~ /^(\d+)\s+([a-z0-9\.\-]+)$/
+ or return "Illegal data for MX record: ". $self->recdata;
+ $self->recdata("$1 $2");
+ } elsif ( $self->rectype eq 'A' ) {
+ $self->recdata =~ /^((\d{1,3}\.){3}\d{1,3})$/
+ or return "Illegal data for A record: ". $self->recdata;
+ $self->recdata($1);
+ } elsif ( $self->rectype eq 'PTR' ) {
+ $self->recdata =~ /^([a-z0-9\.\-]+)$/
+ or return "Illegal data for PTR record: ". $self->recdata;
+ $self->recdata($1);
+ } elsif ( $self->rectype eq 'CNAME' ) {
+ $self->recdata =~ /^([a-z0-9\.\-]+)$/
+ or return "Illegal data for CNAME record: ". $self->recdata;
+ $self->recdata($1);
+ } else {
+ die "ack!";
+ }
+
+ ''; #no error
+}
+
+=back
+
+=head1 VERSION
+
+$Id: domain_record.pm,v 1.1 2000-02-03 05:16:52 ivan Exp $
+
+=head1 BUGS
+
+The data validation doesn't check everything it could. In particular,
+there is no protection against bad data that passes the regex, duplicate
+SOA records, forgetting the trailing `.', impossible IP addersses, etc. Of
+course, it's still better than editing the zone files directly. :)
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=head1 HISTORY
+
+$Log: domain_record.pm,v $
+Revision 1.1 2000-02-03 05:16:52 ivan
+beginning of DNS and Apache support
+
+
+=cut
+
+1;
+
diff --git a/FS/FS/svc_domain.pm b/FS/FS/svc_domain.pm
index f960de0..4d4db5a 100644
--- a/FS/FS/svc_domain.pm
+++ b/FS/FS/svc_domain.pm
@@ -3,6 +3,8 @@ package FS::svc_domain;
use strict;
use vars qw( @ISA $whois_hack $conf $mydomain $smtpmachine
$tech_contact $from $to @nameservers @nameserver_ips @template
+ @mxmachines @nsmachines $soadefaultttl $soaemail $soaexpire $soamachine
+ $soarefresh $soaretry
);
use Carp;
use Mail::Internet;
@@ -16,6 +18,7 @@ use FS::cust_svc;
use FS::svc_acct;
use FS::cust_pkg;
use FS::cust_main;
+use FS::domain_record;
@ISA = qw( FS::svc_Common );
@@ -43,6 +46,15 @@ $FS::UID::callback{'FS::domain'} = sub {
} @ns;
@template = map { $_. "\n" } $conf->config("$internic/template");
+ @mxmachines = $conf->config('mxmachines');
+ @nsmachines = $conf->config('nsmachines');
+ $soadefaultttl = $conf->config('soadefaultttl');
+ $soaemail = $conf->config('soaemail');
+ $soaexpire = $conf->config('soaexpire');
+ $soamachine = $conf->config('soamachine');
+ $soarefresh = $conf->config('soarefresh');
+ $soaretry = $conf->config('soaretry');
+
};
=head1 NAME
@@ -114,6 +126,19 @@ email address on this email. Otherwise, the svc_acct records for this package
(see L<FS::cust_pkg>) are searched. If there is exactly one svc_acct record
in the same package, it is automatically used. Otherwise an error is returned.
+If any I<soamachine> configuration file exists, an SOA record is added to
+the domain_record table (see <FS::domain_record>).
+
+If any machines are defined in the I<nsmachines> configuration file, NS
+records are added to the domain_record table (see L<FS::domain_record>).
+
+If any machines are defined in the I<mxmachines> configuration file, MX
+records are added to the domain_record table (see L<FS::domain_record>).
+
+Any problems adding FS::domain_record records will emit warnings, but will
+not return errors from this method. If your configuration files are correct
+you shouln't have any problems.
+
=cut
sub insert {
@@ -144,6 +169,47 @@ sub insert {
$self->submit_internic unless $whois_hack;
+ if ( $soamachine ) {
+ my $soa = new FS::domain_record {
+ 'svcnum' => $self->svcnum,
+ 'reczone' => '@',
+ 'recaf' => 'IN',
+ 'rectype' => 'SOA',
+ 'recdata' => "$soamachine $soaemail ( ". time2str("%Y%m%e", time). "00 ".
+ "$soarefresh $soarety $soaexpire $soadefaultttl )"
+ };
+ $error = $soa->insert;
+ warn "WARNING: couldn't insert SOA record for new domain: $error" if $error;
+
+ foreach $nsmachine ( @nsmachines ) {
+ my $ns = new FS::domain_record {
+ 'svcnum' => $self->svcnum,
+ 'reczone' => '@',
+ 'recaf' => 'IN',
+ 'rectype' => 'NS',
+ 'recdata' => $nsmachine,
+ };
+ my $error = $ns->insert;
+ warn "WARNING: couldn't insert NS record for new domain: $error"
+ if $error;
+ }
+
+ foreach $mxmachine ( @mxmachines ) {
+ my $mx = new FS::domain_record {
+ 'svcnum' => $self->svcnum,
+ 'reczone' => '@',
+ 'recaf' => 'IN',
+ 'rectype' => 'mx',
+ 'recdata' => $mxmachine,
+ };
+ my $error = $mx->insert;
+ warn "WARNING: couldn't insert MX record for new domain: $error"
+ if $error;
+ }
+
+ }
+
+
''; #no error
}
@@ -393,7 +459,7 @@ sub submit_internic {
=head1 VERSION
-$Id: svc_domain.pm,v 1.4 2000-01-29 21:10:13 ivan Exp $
+$Id: svc_domain.pm,v 1.5 2000-02-03 05:16:52 ivan Exp $
=head1 BUGS
diff --git a/FS/FS/svc_www.pm b/FS/FS/svc_www.pm
new file mode 100644
index 0000000..fc1419c
--- /dev/null
+++ b/FS/FS/svc_www.pm
@@ -0,0 +1,242 @@
+package FS::svc_www;
+
+use strict;
+use vars qw(@ISA $conf $apacheroot $apachemachine $nossh_hack );
+#use FS::Record qw( qsearch qsearchs );
+use FS::Record qw( qsearchs );
+use FS::svc_Common;
+use FS::cust_svc;
+use FS::domain_record;
+use FS::svc_acct;
+use FS::SSH qw(ssh);
+
+@ISA = qw(svc_Common);
+
+#ask FS::UID to run this stuff for us later
+$FS::UID::callback{'FS::svc_www'} = sub {
+ $conf = new FS::Conf;
+ $apacheroot = $conf->config('apacheroot');
+ $apachemachine = $conf->config('apachemachine');
+};
+
+=head1 NAME
+
+FS::svc_www - Object methods for svc_www records
+
+=head1 SYNOPSIS
+
+ use FS::svc_www;
+
+ $record = new FS::svc_www \%hash;
+ $record = new FS::svc_www { 'column' => 'value' };
+
+ $error = $record->insert;
+
+ $error = $new_record->replace($old_record);
+
+ $error = $record->delete;
+
+ $error = $record->check;
+
+ $error = $record->suspend;
+
+ $error = $record->unsuspend;
+
+ $error = $record->cancel;
+
+=head1 DESCRIPTION
+
+An FS::svc_www object represents an web virtual host. FS::svc_www inherits
+from FS::svc_Common. The following fields are currently supported:
+
+=over 4
+
+=item svcnum - primary key
+
+=item recnum - DNS `A' record corresponding to this web virtual host. (see L<FS::domain_record))
+
+=item usersvc - account (see L<FS::svc_acct>) corresponding to this web virtual host.
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new web virtual host. To add the record to the database, see
+L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to. You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+sub table { 'svc_www'; }
+
+=item insert
+
+Adds this record to the database. If there is an error, returns the error,
+otherwise returns false.
+
+The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
+defined. An FS::cust_svc record will be created and inserted.
+
+If the configuration values (see L<FS::Conf>) I<apachemachine>, and
+I<apacheroot> exist, the command:
+
+ mkdir $apacheroot/$zone;
+ chown $username $apacheroot/$zone;
+ ln -s $apacheroot/$zone $homedir/$zone
+
+I<$zone> is the DNS A record pointed to by I<recnum>
+I<$username> is the username pointed to by I<usersvc>
+I<$homedir> is that user's home directory
+
+is executed on I<apachemachine> via ssh. This behaviour can be surpressed by
+setting $FS::svc_www::nossh_hack true.
+
+=cut
+
+sub insert {
+ my $self = shift;
+ my $error;
+
+ $error = $self->SUPER::insert;
+ return $error if $error;
+
+ my $domain_record = qsearchs('domain_record', { 'recnum' => $self->recnum } ); # or die ?
+ my $zone = $domain_record->reczone;
+ # or die ?
+ unless ( $zone =~ /\.$/ ) {
+ my $dom_svcnum = $domain_record->svcnum;
+ my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $dom_svcnum } );
+ # or die ?
+ $zone .= $svc_domain->domain;
+ }
+
+ my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
+ # or die ?
+ my $username = $svc_acct->username;
+ # or die ?
+ my $homedir = $svc_acct->dir;
+ # or die ?
+
+ if ( $apachemachine
+ && $apacheroot
+ && $zone
+ && $username
+ && $homedir
+ && ! $nossh_hack
+ ) {
+ ssh("root\@$apachemachine",
+ "mkdir $apacheroot/$zone; ".
+ "chown $username $apacheroot/$zone; ".
+ "ln -s $apacheroot/$zone $homedir/$zone"
+ );
+ }
+
+ '';
+}
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+sub delete {
+ my $self = shift;
+ my $error;
+
+ $error = $self->SUPER::delete;
+ return $error if $error;
+
+ '';
+}
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database. If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+sub replace {
+ my ( $new, $old ) = ( shift, shift );
+ my $error;
+
+ $error = $new->SUPER::replace($old);
+ return $error if $error;
+
+ '';
+}
+
+=item suspend
+
+Called by the suspend method of FS::cust_pkg (see L<FS::cust_pkg>).
+
+=item unsuspend
+
+Called by the unsuspend method of FS::cust_pkg (see L<FS::cust_pkg>).
+
+=item cancel
+
+Called by the cancel method of FS::cust_pkg (see L<FS::cust_pkg>).
+
+=item check
+
+Checks all fields to make sure this is a valid example. If there is
+an error, returns the error, otherwise returns false. Called by the insert
+and repalce methods.
+
+=cut
+
+sub check {
+ my $self = shift;
+
+ my $x = $self->setfixed;
+ return $x unless ref($x);
+ my $part_svc = $x;
+
+ my $error =
+ $self->ut_numbern('svcnum')
+ || $self->ut_number('recnum')
+ || $self->ut_number('usersvc')
+ ;
+ return $error if $error;
+
+ return "Unknown recnum: ". $self->recnum
+ unless qsearchs('domain_record', { 'recnum' => $self->recnum } );
+
+ return "Unknown usersvc (svc_acct.svcnum): ". $self->usersvc
+ unless qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
+
+ ''; #no error
+}
+
+=back
+
+=head1 VERSION
+
+$Id: svc_www.pm,v 1.1 2000-02-03 05:16:52 ivan Exp $
+
+=head1 BUGS
+
+=head1 SEE ALSO
+
+L<FS::svc_Common>, L<FS::Record>, L<FS::domain_record>, L<FS::cust_svc>,
+L<FS::part_svc>, L<FS::cust_pkg>, schema.html from the base documentation.
+
+=head1 HISTORY
+
+$Log: svc_www.pm,v $
+Revision 1.1 2000-02-03 05:16:52 ivan
+beginning of DNS and Apache support
+
+
+=cut
+
+1;
+