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/Conf.pm | 7 +++++ FS/FS/domain_record.pm | 78 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 6 deletions(-) (limited to 'FS') diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index d8191c278..905c60d2b 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -1199,6 +1199,13 @@ httemplate/docs/config.html 'type' => 'checkbox', }, + { + 'key' => 'disable_autoreverse', + 'section' => 'BIND', + 'description' => 'Disable automatic synchronization of reverse-ARPA entries.', + 'type' => 'checkbox', + }, + ); 1; diff --git a/FS/FS/domain_record.pm b/FS/FS/domain_record.pm index ea0c48d4f..2a30594da 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.2.1 From 3d7ce17fee0a42b8d476ae7e7eaeef5fc24043d0 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 7 Apr 2004 13:11:20 +0000 Subject: added options to select username, svcnum, svcpart --- FS/bin/freeside-reexport | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'FS') diff --git a/FS/bin/freeside-reexport b/FS/bin/freeside-reexport index b5c50a422..34ccbc715 100644 --- a/FS/bin/freeside-reexport +++ b/FS/bin/freeside-reexport @@ -1,6 +1,8 @@ -#!/usr/bin/perl -Tw +#!/usr/bin/perl -w use strict; +use vars qw($opt_s $opt_u $opt_p); +use Getopt::Std; use FS::UID qw(adminsuidsetup); use FS::Record qw(qsearch qsearchs); use FS::part_export; @@ -20,20 +22,27 @@ if ( $export_x =~ /^(\d+)$/ ) { or die "no exports of type $export_x found\n"; } -my $svc_something = shift or die &usage; -my $svc_x; -if ( $svc_something =~ /^(\d+)$/ ) { - my $cust_svc = qsearchs('cust_svc', { svcnum=>$1 } ) - or die "svcnum $svc_something not found\n"; - $svc_x = $cust_svc->svc_x; -} else { - $svc_x = qsearchs('svc_acct', { username=>$svc_something } ) - or die "username $svc_something not found\n"; +getopts('s:u:p:'); + +my @svc_x = (); +if ( $opt_s ) { + my $cust_svc = qsearchs('cust_svc', { svcnum=>$opt_s } ) + or die "svcnum $opt_s not found\n"; + push @svc_x, $cust_svc->svc_x; +} elsif ( $opt_u ) { + my $svc_x = qsearchs('svc_acct', { username=>$opt_u } ) + or die "username $opt_u not found\n"; + push @svc_x, $svc_x; +} elsif ( $opt_p ) { + push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart=>$opt_p } ); + die "no services with svcpart $opt_p found\n" unless @svc_x; } foreach my $part_export ( @part_export ) { - my $error = $part_export->export_insert($svc_x); - die $error if $error; + foreach my $svc_x ( @svc_x ) { + my $error = $part_export->export_insert($svc_x); + die $error if $error; + } } @@ -47,7 +56,7 @@ freeside-reexport - Command line tool to re-trigger export jobs for existing ser =head1 SYNOPSIS - freeside-reexport user exportnum|exporttype svcnum|username + freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ] =head1 DESCRIPTION -- cgit v1.2.1 From fad8705f1dacd35d394c8a0290fdd0a372400bc1 Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 7 Apr 2004 13:12:17 +0000 Subject: oops, update the usage too --- FS/bin/freeside-reexport | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'FS') diff --git a/FS/bin/freeside-reexport b/FS/bin/freeside-reexport index 34ccbc715..54af9dd80 100644 --- a/FS/bin/freeside-reexport +++ b/FS/bin/freeside-reexport @@ -47,7 +47,7 @@ foreach my $part_export ( @part_export ) { sub usage { - die "Usage:\n\n freeside-reexport user exportnum|exporttype svcnum|username\n"; + die "Usage:\n\n freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ]\n"; } =head1 NAME -- cgit v1.2.1 From df33a04853368c1ccb95ea1718b1ebad93b78672 Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 13 Apr 2004 20:01:57 +0000 Subject: adding forgotten test --- FS/t/part_export-communigate_pro.t | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 FS/t/part_export-communigate_pro.t (limited to 'FS') diff --git a/FS/t/part_export-communigate_pro.t b/FS/t/part_export-communigate_pro.t new file mode 100644 index 000000000..88b8b64e0 --- /dev/null +++ b/FS/t/part_export-communigate_pro.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::part_export::communigate_pro; +$loaded=1; +print "ok 1\n"; -- cgit v1.2.1