From 5bd5f206a77cf975515d955119d4dff7764a2d8c Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 3 Feb 2000 05:17:39 +0000 Subject: beginning of DNS and Apache support --- FS/FS/domain_record.pm | 182 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 182 insertions(+) create mode 100644 FS/FS/domain_record.pm (limited to 'FS/FS/domain_record.pm') 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) 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 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, 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; + -- cgit v1.1 From 09a19f9ad1cc89c96b672e1f17af1099f7b3e2a1 Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 18 May 2001 14:08:55 +0000 Subject: tyop --- FS/FS/domain_record.pm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 9b7081b..743f43c 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -123,7 +123,7 @@ sub check { 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"; + or return "Illegal data for SOA record: $recdata"; $self->recdata($1); } elsif ( $self->rectype eq 'NS' ) { $self->recdata =~ /^([a-z0-9\.\-]+)$/ @@ -156,7 +156,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.1 2000-02-03 05:16:52 ivan Exp $ +$Id: domain_record.pm,v 1.2 2001-05-18 14:08:55 ivan Exp $ =head1 BUGS @@ -172,7 +172,10 @@ L, schema.html from the base documentation. =head1 HISTORY $Log: domain_record.pm,v $ -Revision 1.1 2000-02-03 05:16:52 ivan +Revision 1.2 2001-05-18 14:08:55 ivan +tyop + +Revision 1.1 2000/02/03 05:16:52 ivan beginning of DNS and Apache support -- cgit v1.1 From 1da2eb3c205a088809fb8b72b42a454b94b74c43 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 21 Aug 2001 02:44:47 +0000 Subject: remove $Log$ --- FS/FS/domain_record.pm | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 743f43c..0f634bf 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -156,7 +156,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.2 2001-05-18 14:08:55 ivan Exp $ +$Id: domain_record.pm,v 1.3 2001-08-21 02:44:47 ivan Exp $ =head1 BUGS @@ -169,16 +169,6 @@ course, it's still better than editing the zone files directly. :) L, schema.html from the base documentation. -=head1 HISTORY - -$Log: domain_record.pm,v $ -Revision 1.2 2001-05-18 14:08:55 ivan -tyop - -Revision 1.1 2000/02/03 05:16:52 ivan -beginning of DNS and Apache support - - =cut 1; -- cgit v1.1 From 0da1c2b1d5dbe10b304d131f6807b18a237b5d45 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Apr 2002 10:09:42 +0000 Subject: allow uppercase zones... --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 0f634bf..9f00356 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -107,7 +107,7 @@ sub check { return "Unknown svcnum (in svc_domain)" unless qsearchs('svc_domain', { 'svcnum' => $self->svcnum } ); - $self->reczone =~ /^(@|[a-z0-9\.\-]+)$/ + $self->reczone =~ /^(@|[a-zA-Z0-9\.\-]+)$/ or return "Illegal reczone: ". $self->reczone; $self->reczone($1); @@ -156,7 +156,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.3 2001-08-21 02:44:47 ivan Exp $ +$Id: domain_record.pm,v 1.4 2002-04-20 10:09:42 ivan Exp $ =head1 BUGS -- cgit v1.1 From 01d8a89e66c00077619e408ce8a79f847e32214c Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Apr 2002 10:12:26 +0000 Subject: allow uppercase in zone data. --- FS/FS/domain_record.pm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 9f00356..23955b6 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -107,7 +107,7 @@ sub check { return "Unknown svcnum (in svc_domain)" unless qsearchs('svc_domain', { 'svcnum' => $self->svcnum } ); - $self->reczone =~ /^(@|[a-zA-Z0-9\.\-]+)$/ + $self->reczone =~ /^(@|[a-z0-9\.\-]+)$/i or return "Illegal reczone: ". $self->reczone; $self->reczone($1); @@ -122,15 +122,15 @@ sub check { if ( $self->rectype eq 'SOA' ) { my $recdata = $self->recdata; $recdata =~ s/\s+/ /g; - $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( (\d+ ){5}\))$/ + $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( (\d+ ){5}\))$/i or return "Illegal data for SOA record: $recdata"; $self->recdata($1); } elsif ( $self->rectype eq 'NS' ) { - $self->recdata =~ /^([a-z0-9\.\-]+)$/ + $self->recdata =~ /^([a-z0-9\.\-]+)$/i or return "Illegal data for NS record: ". $self->recdata; $self->recdata($1); } elsif ( $self->rectype eq 'MX' ) { - $self->recdata =~ /^(\d+)\s+([a-z0-9\.\-]+)$/ + $self->recdata =~ /^(\d+)\s+([a-z0-9\.\-]+)$/i or return "Illegal data for MX record: ". $self->recdata; $self->recdata("$1 $2"); } elsif ( $self->rectype eq 'A' ) { @@ -138,11 +138,11 @@ sub check { or return "Illegal data for A record: ". $self->recdata; $self->recdata($1); } elsif ( $self->rectype eq 'PTR' ) { - $self->recdata =~ /^([a-z0-9\.\-]+)$/ + $self->recdata =~ /^([a-z0-9\.\-]+)$/i or return "Illegal data for PTR record: ". $self->recdata; $self->recdata($1); } elsif ( $self->rectype eq 'CNAME' ) { - $self->recdata =~ /^([a-z0-9\.\-]+)$/ + $self->recdata =~ /^([a-z0-9\.\-]+)$/i or return "Illegal data for CNAME record: ". $self->recdata; $self->recdata($1); } else { @@ -156,7 +156,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.4 2002-04-20 10:09:42 ivan Exp $ +$Id: domain_record.pm,v 1.5 2002-04-20 10:12:26 ivan Exp $ =head1 BUGS -- cgit v1.1 From cb63b8c06cdf912ce61b4b459a238dadfd9c64fc Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Apr 2002 10:49:33 +0000 Subject: allow * MX records --- FS/FS/domain_record.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 23955b6..24db4c2 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -107,7 +107,7 @@ sub check { return "Unknown svcnum (in svc_domain)" unless qsearchs('svc_domain', { 'svcnum' => $self->svcnum } ); - $self->reczone =~ /^(@|[a-z0-9\.\-]+)$/i + $self->reczone =~ /^(@|[a-z0-9\.\-\*]+)$/i or return "Illegal reczone: ". $self->reczone; $self->reczone($1); @@ -119,6 +119,9 @@ sub check { $self->rectype; $self->rectype($1); + return "Illegal reczone for ". $self->rectype. ": ". $self->reczone + if $self->rectype !~ /^MX$/i && $self->reczone =~ /\*/; + if ( $self->rectype eq 'SOA' ) { my $recdata = $self->recdata; $recdata =~ s/\s+/ /g; @@ -156,7 +159,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.5 2002-04-20 10:12:26 ivan Exp $ +$Id: domain_record.pm,v 1.6 2002-04-20 10:49:33 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4d5485150720c91d9945c3ae3cad9427ece23833 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 20 Apr 2002 11:57:36 +0000 Subject: working BIND import --- FS/FS/domain_record.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 24db4c2..6f4dd02 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -114,7 +114,7 @@ sub check { $self->recaf =~ /^(IN)$/ or return "Illegal recaf: ". $self->recaf; $self->recaf($1); - $self->rectype =~ /^(SOA|NS|MX|A|PTR|CNAME)$/ + $self->rectype =~ /^(SOA|NS|MX|A|PTR|CNAME|_mstr)$/ or return "Illegal rectype (only SOA NS MX A PTR CNAME recognized): ". $self->rectype; $self->rectype($1); @@ -148,6 +148,9 @@ sub check { $self->recdata =~ /^([a-z0-9\.\-]+)$/i or return "Illegal data for CNAME record: ". $self->recdata; $self->recdata($1); + } elsif ( $self->rectype eq '_mstr' ) { + $self->recdata =~ /^((\d{1,3}\.){3}\d{1,3})$/ + or return "Illegal data for _master pseudo-record: ". $self->recdata; } else { die "ack!"; } @@ -159,7 +162,7 @@ sub check { =head1 VERSION -$Id: domain_record.pm,v 1.6 2002-04-20 10:49:33 ivan Exp $ +$Id: domain_record.pm,v 1.7 2002-04-20 11:57:35 ivan Exp $ =head1 BUGS -- cgit v1.1 From 23186f0338ec248d930c85db08cc997bca42525b Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 22 May 2002 18:44:01 +0000 Subject: bind export, editing zones, deleting unaudited domains, mmm --- FS/FS/domain_record.pm | 129 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 6f4dd02..44e70ad 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -3,7 +3,7 @@ package FS::domain_record; use strict; use vars qw( @ISA ); #use FS::Record qw( qsearch qsearchs ); -use FS::Record qw( qsearchs ); +use FS::Record qw( qsearchs dbh ); use FS::svc_domain; @ISA = qw(FS::Record); @@ -71,12 +71,80 @@ otherwise returns false. =cut +sub insert { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->SUPER::insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + unless ( $self->rectype =~ /^(SOA|_mstr)$/ ) { + my $error = $self->increment_serial; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =item delete Delete this record from the database. =cut +sub delete { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->SUPER::delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + unless ( $self->rectype =~ /^(SOA|_mstr)$/ ) { + my $error = $self->increment_serial; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =item replace OLD_RECORD Replaces the OLD_RECORD with this one in the database. If there is an error, @@ -84,6 +152,40 @@ returns the error, otherwise returns false. =cut +sub replace { + my $self = shift; + + local $SIG{HUP} = 'IGNORE'; + local $SIG{INT} = 'IGNORE'; + local $SIG{QUIT} = 'IGNORE'; + local $SIG{TERM} = 'IGNORE'; + local $SIG{TSTP} = 'IGNORE'; + local $SIG{PIPE} = 'IGNORE'; + + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + my $dbh = dbh; + + my $error = $self->SUPER::replace(@_); + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + + unless ( $self->rectype eq 'SOA' ) { + my $error = $self->increment_serial; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + + $dbh->commit or die $dbh->errstr if $oldAutoCommit; + + ''; + +} + =item check Checks all fields to make sure this is a valid example. If there is @@ -158,11 +260,34 @@ sub check { ''; #no error } +=item increment_serial + +=cut + +sub increment_serial { + my $self = shift; + + my $soa = qsearchs('domain_record', { + svcnum => $self->svcnum, + reczone => '@', #or full domain ? + recaf => 'IN', + rectype => 'SOA', + } ) or return "soa record not found; can't increment serial"; + + my $data = $soa->recdata; + $data =~ s/(\(\D*)(\d+)/$1.($2+1)/e; #well, it works. + + my %hash = $soa->hash; + $hash{recdata} = $data; + my $new = new FS::domain_record \%hash; + $new->replace($soa); +} + =back =head1 VERSION -$Id: domain_record.pm,v 1.7 2002-04-20 11:57:35 ivan Exp $ +$Id: domain_record.pm,v 1.8 2002-05-22 18:44:01 ivan Exp $ =head1 BUGS -- cgit v1.1 From 4920ad2671d712afe23d731e25bc5b53955397b7 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 23 May 2002 13:00:08 +0000 Subject: bind: allow adding slave domains too --- FS/FS/domain_record.pm | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 44e70ad..4ed713c 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -1,7 +1,7 @@ package FS::domain_record; use strict; -use vars qw( @ISA ); +use vars qw( @ISA $noserial_hack ); #use FS::Record qw( qsearch qsearchs ); use FS::Record qw( qsearchs dbh ); use FS::svc_domain; @@ -85,6 +85,16 @@ sub insert { local $FS::UID::AutoCommit = 0; my $dbh = dbh; + if ( $self->rectype eq '_mstr' ) { #delete all other records + foreach my $domain_record ( reverse $self->svc_domain->domain_record ) { + my $error = $domain_record->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + } + } + my $error = $self->SUPER::insert; if ( $error ) { $dbh->rollback if $oldAutoCommit; @@ -265,6 +275,7 @@ sub check { =cut sub increment_serial { + return '' if $noserial_hack; my $self = shift; my $soa = qsearchs('domain_record', { @@ -283,11 +294,22 @@ sub increment_serial { $new->replace($soa); } +=item svc_domain + +Returns the domain (see L $self->svcnum } ); +} + =back =head1 VERSION -$Id: domain_record.pm,v 1.8 2002-05-22 18:44:01 ivan Exp $ +$Id: domain_record.pm,v 1.9 2002-05-23 13:00:08 ivan Exp $ =head1 BUGS -- cgit v1.1 From 75f034098e0dc30b2a34ec4273a8f9fbe1147e5e Mon Sep 17 00:00:00 2001 From: ivan Date: Mon, 10 Jun 2002 23:02:41 +0000 Subject: fix *** ERROR: unterminated L<...> at line 299 in file FS/domain_record.pm --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 4ed713c..03f9e10 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -296,7 +296,7 @@ sub increment_serial { =item svc_domain -Returns the domain (see L) for this record. =cut @@ -309,7 +309,7 @@ sub svc_domain { =head1 VERSION -$Id: domain_record.pm,v 1.9 2002-05-23 13:00:08 ivan Exp $ +$Id: domain_record.pm,v 1.10 2002-06-10 23:02:41 ivan Exp $ =head1 BUGS -- cgit v1.1 From b32a862877102bd755bec2c83713b6f3ffb35dfa Mon Sep 17 00:00:00 2001 From: ivan Date: Sun, 23 Jun 2002 19:16:45 +0000 Subject: domain_record records attached to svc_www records are no longer delete-able, patch from "Stephen Bechard" , thanks! closes: Bug#434 --- FS/FS/domain_record.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 03f9e10..37cc6c9 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -5,6 +5,7 @@ use vars qw( @ISA $noserial_hack ); #use FS::Record qw( qsearch qsearchs ); use FS::Record qw( qsearchs dbh ); use FS::svc_domain; +use FS::svc_www; @ISA = qw(FS::Record); @@ -124,6 +125,9 @@ Delete this record from the database. sub delete { my $self = shift; + return "Can't delete a domain record which has a website!" + if qsearchs( 'svc_www', { 'recnum' => $self->recnum } ); + local $SIG{HUP} = 'IGNORE'; local $SIG{INT} = 'IGNORE'; local $SIG{QUIT} = 'IGNORE'; @@ -309,7 +313,7 @@ sub svc_domain { =head1 VERSION -$Id: domain_record.pm,v 1.10 2002-06-10 23:02:41 ivan Exp $ +$Id: domain_record.pm,v 1.11 2002-06-23 19:16:45 ivan Exp $ =head1 BUGS -- cgit v1.1 From 9aec22e5fd00800c6e7952ae5b85cc639d4b1e78 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 20 Mar 2003 03:41:03 +0000 Subject: apache export! --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 37cc6c9..3297e6b 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -261,7 +261,7 @@ sub check { or return "Illegal data for PTR record: ". $self->recdata; $self->recdata($1); } elsif ( $self->rectype eq 'CNAME' ) { - $self->recdata =~ /^([a-z0-9\.\-]+)$/i + $self->recdata =~ /^([a-z0-9\.\-]+|\@)$/i or return "Illegal data for CNAME record: ". $self->recdata; $self->recdata($1); } elsif ( $self->rectype eq '_mstr' ) { @@ -313,7 +313,7 @@ sub svc_domain { =head1 VERSION -$Id: domain_record.pm,v 1.11 2002-06-23 19:16:45 ivan Exp $ +$Id: domain_record.pm,v 1.12 2003-03-20 03:41:03 ivan Exp $ =head1 BUGS -- cgit v1.1 From 48f60f666bab22a3ca5196cf6cd573b8691e4aae Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 29 Mar 2003 04:53:44 +0000 Subject: correct web UI for svc_www services & no more @.domain in www_shellcommands export --- FS/FS/domain_record.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 3297e6b..2f7e270 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -309,11 +309,30 @@ sub svc_domain { qsearchs('svc_domain', { svcnum => $self->svcnum } ); } +=item zone + +Returns the canonical zone name. + +=cut + +sub zone { + my $self = shift; + my $zone = $self->reczone; # or die ? + if ( $zone =~ /\.$/ ) { + $zone =~ s/\.$//; + } else { + my $svc_domain = $self->svc_domain; # or die ? + $zone .= '.'. $svc_domain->domain; + $zone =~ s/^\@\.//; + } + $zone; +} + =back =head1 VERSION -$Id: domain_record.pm,v 1.12 2003-03-20 03:41:03 ivan Exp $ +$Id: domain_record.pm,v 1.13 2003-03-29 04:53:44 ivan Exp $ =head1 BUGS -- cgit v1.1 From fdf62da26a4a9127fd43f359163f231a89bc692d Mon Sep 17 00:00:00 2001 From: khoff Date: Thu, 24 Apr 2003 18:45:03 +0000 Subject: Support for nWnDnHnMnS time format --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 2f7e270..d3682c3 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -241,7 +241,7 @@ sub check { if ( $self->rectype eq 'SOA' ) { my $recdata = $self->recdata; $recdata =~ s/\s+/ /g; - $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( (\d+ ){5}\))$/i + $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( ([\dwdhmsWDHMS]+ ){5}\))$/i or return "Illegal data for SOA record: $recdata"; $self->recdata($1); } elsif ( $self->rectype eq 'NS' ) { @@ -332,7 +332,7 @@ sub zone { =head1 VERSION -$Id: domain_record.pm,v 1.13 2003-03-29 04:53:44 ivan Exp $ +$Id: domain_record.pm,v 1.14 2003-04-24 18:45:03 khoff Exp $ =head1 BUGS -- cgit v1.1 From e77371fc4d3443c7b97a387bd25897b52200d64a Mon Sep 17 00:00:00 2001 From: khoff Date: Tue, 29 Apr 2003 18:28:50 +0000 Subject: Better SOA checking --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index d3682c3..77b9550 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -241,7 +241,7 @@ sub check { if ( $self->rectype eq 'SOA' ) { my $recdata = $self->recdata; $recdata =~ s/\s+/ /g; - $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( ([\dwdhmsWDHMS]+ ){5}\))$/i + $recdata =~ /^([a-z0-9\.\-]+ [\w\-\+]+\.[a-z0-9\.\-]+ \( ((\d+|((\d+[WDHMS])+)) ){5}\))$/i or return "Illegal data for SOA record: $recdata"; $self->recdata($1); } elsif ( $self->rectype eq 'NS' ) { @@ -332,7 +332,7 @@ sub zone { =head1 VERSION -$Id: domain_record.pm,v 1.14 2003-04-24 18:45:03 khoff Exp $ +$Id: domain_record.pm,v 1.15 2003-04-29 18:28:50 khoff Exp $ =head1 BUGS -- cgit v1.1 From 58d44fbe5eb9ab32e6d87063a4a3b22ddba9a828 Mon Sep 17 00:00:00 2001 From: khoff Date: Tue, 5 Aug 2003 00:20:51 +0000 Subject: Virtual field merge --- FS/FS/domain_record.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index 77b9550..ea0c48d 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -271,7 +271,7 @@ sub check { die "ack!"; } - ''; #no error + $self->SUPER::check; } =item increment_serial @@ -332,7 +332,7 @@ sub zone { =head1 VERSION -$Id: domain_record.pm,v 1.15 2003-04-29 18:28:50 khoff Exp $ +$Id: domain_record.pm,v 1.16 2003-08-05 00:20:43 khoff Exp $ =head1 BUGS -- cgit v1.1 From ca19c9b9d3f40739a201e8100c22f5cba3730b9e Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 7 Apr 2004 11:39:15 +0000 Subject: automatically update reverse-ARPA records (Bug#462) / recognize SOA records with the fqdn as well as @ --- FS/FS/domain_record.pm | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 6 deletions(-) (limited to 'FS/FS/domain_record.pm') diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index ea0c48d..2a30594 100644 --- a/FS/FS/domain_record.pm +++ b/FS/FS/domain_record.pm @@ -1,7 +1,8 @@ package FS::domain_record; use strict; -use vars qw( @ISA $noserial_hack ); +use vars qw( @ISA $noserial_hack $DEBUG ); +use FS::Conf; #use FS::Record qw( qsearch qsearchs ); use FS::Record qw( qsearchs dbh ); use FS::svc_domain; @@ -9,6 +10,8 @@ use FS::svc_www; @ISA = qw(FS::Record); +$DEBUG = 1; + =head1 NAME FS::domain_record - Object methods for domain_record records @@ -110,6 +113,18 @@ sub insert { } } + my $conf = new FS::Conf; + if ( $self->rectype =~ /^A$/ && ! $conf->exists('disable_autoreverse') ) { + my $reverse = $self->reverse_record; + if ( $reverse && ! $reverse->recnum ) { + my $error = $reverse->insert; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error adding corresponding reverse-ARPA record: $error"; + } + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -153,6 +168,18 @@ sub delete { } } + my $conf = new FS::Conf; + if ( $self->rectype =~ /^A$/ && ! $conf->exists('disable_autoreverse') ) { + my $reverse = $self->reverse_record; + if ( $reverse && $reverse->recnum && $reverse->recdata eq $self->zone.'.' ){ + my $error = $reverse->delete; + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "error removing corresponding reverse-ARPA record: $error"; + } + } + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -284,10 +311,16 @@ sub increment_serial { my $soa = qsearchs('domain_record', { svcnum => $self->svcnum, - reczone => '@', #or full domain ? + reczone => '@', + recaf => 'IN', + rectype => 'SOA', } ) + || qsearchs('domain_record', { + svcnum => $self->svcnum, + reczone => $self->svc_domain->domain.'.', recaf => 'IN', rectype => 'SOA', - } ) or return "soa record not found; can't increment serial"; + } ) + or return "soa record not found; can't increment serial"; my $data = $soa->recdata; $data =~ s/(\(\D*)(\d+)/$1.($2+1)/e; #well, it works. @@ -328,11 +361,44 @@ sub zone { $zone; } -=back +=item reverse_record + +Returns the corresponding reverse-ARPA record as another FS::domain_record +object. If the specific record does not exist in the database but the +reverse-ARPA zone itself does, an appropriate new record is created. If no +reverse-ARPA zone is available at all, returns false. + +(You can test whether or not record itself exists in the database or is a new +object that might need to be inserted by checking the recnum field) -=head1 VERSION +Mostly used by the insert and delete methods - probably should see them for +examples. -$Id: domain_record.pm,v 1.16 2003-08-05 00:20:43 khoff Exp $ +=cut + +sub reverse_record { + my $self = shift; + warn "reverse_record called\n" if $DEBUG; + #should support classless reverse-ARPA ala rfc2317 too + $self->recdata =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ + or return ''; + my $domain = "$3.$2.$1.in-addr.arpa"; + my $ptr_reczone = $4; + warn "reverse_record: searching for domain: $domain\n" if $DEBUG; + my $svc_domain = qsearchs('svc_domain', { 'domain' => $domain } ) + or return ''; + warn "reverse_record: found domain: $domain\n" if $DEBUG; + my %hash = ( + 'svcnum' => $svc_domain->svcnum, + 'reczone' => $ptr_reczone, + 'recaf' => 'IN', + 'rectype' => 'PTR', + ); + qsearchs('domain_record', \%hash ) + or new FS::domain_record { %hash, 'recdata' => $self->zone.'.' }; +} + +=back =head1 BUGS -- cgit v1.1