X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fbind.import;h=41313fba653337aee388b5d15950a62f83c117bd;hp=5c4149501ddad4bf463321b153a951835efd17f0;hb=97c0616b60819a23dbc6d7d6ebf2ff1dc3446e91;hpb=4920ad2671d712afe23d731e25bc5b53955397b7 diff --git a/bin/bind.import b/bin/bind.import index 5c4149501..41313fba6 100755 --- a/bin/bind.import +++ b/bin/bind.import @@ -1,14 +1,19 @@ #!/usr/bin/perl -w # -# $Id: bind.import,v 1.1 2002-05-23 13:00:08 ivan Exp $ - -#need to manually put header in /usr/local/etc/freeside/export./named.conf.HEADER +# -s: import slave zones as master. useful if you need to recreate your +# primary nameserver from a secondary +# -c chroot_dir: import data from chrooted bind (corrects the path for +# downloading zone files +# +# need to manually put header in +# /usr/local/etc/freeside/export./named.conf.HEADER use strict; use vars qw( %d_part_svc ); +use Getopt::Std; use Term::Query qw(query); #use BIND::Conf_Parser; -#use DNS::ZoneParse; +#use DNS::ZoneParse 0.81; #use Net::SCP qw(iscp); use Net::SCP qw(scp); @@ -20,9 +25,13 @@ use FS::domain_record; #use FS::svc_acct; #use FS::part_svc; +use vars qw($opt_s $opt_c); +getopts("sc:"); + my $user = shift or die &usage; adminsuidsetup $user; +$FS::svc_Common::noexport_hack = 1; $FS::domain_record::noserial_hack = 1; use vars qw($spooldir); @@ -78,7 +87,7 @@ print "\nBIND import completed.\n"; ## sub usage { - die "Usage:\n\n svc_domain.import user\n"; + die "Usage:\n\n bind.import user\n"; } ######## @@ -98,18 +107,28 @@ BEGIN { sub handle_zone { my($self, $name, $class, $type, $options) = @_; return unless $class eq 'in'; - return if grep { $name eq $_ } - ( qw( . localhost 127.in-addr.arpa 0.in-addr.arpa 255.in-addr.arpa ) ); - - my $domain = new FS::svc_domain( { - svcpart => $main::domain_svcpart, - domain => $name, - action => 'N', - } ); - my $error = $domain->insert; - die $error if $error; + return if grep { $name eq $_ } (qw( + . localhost 127.in-addr.arpa 0.in-addr.arpa 255.in-addr.arpa + 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa + 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.int + )); + + use FS::Record qw(qsearchs); + use FS::svc_domain; + + my $domain = + qsearchs('svc_domain', { 'domain' => $name } ) + || new FS::svc_domain( { + svcpart => $main::domain_svcpart, + domain => $name, + action => 'N', + } ); + unless ( $domain->svcnum ) { + my $error = $domain->insert; + die $error if $error; + } - if ( $type eq 'slave' ) { + if ( $type eq 'slave' && !$main::opt_s ) { #use Data::Dumper; #print Dumper($options); @@ -127,7 +146,7 @@ BEGIN { die $error if $error; } - } elsif ( $type eq 'master' ) { + } elsif ( $type eq 'master' || ( $type eq 'slave' && $main::opt_s ) ) { my $file = $options->{file}; @@ -135,14 +154,16 @@ BEGIN { my $basefile = basename($file); my $sourcefile = $file; $sourcefile = "$named_dir/$sourcefile" unless $file =~ /^\//; + $sourcefile = "$main::opt_c/$sourcefile" if $main::opt_c; + use Net::SCP qw(iscp scp); scp("root\@$main::named_machine:$sourcefile", - "$main::prefix/$basefile.import"); + "$main::prefix/$basefile.import"); - use DNS::ZoneParse; + use DNS::ZoneParse 0.84; my $zone = DNS::ZoneParse->new("$main::prefix/$basefile.import"); - my $dump = $zone->Dump; + my $dump = $zone->dump; #use Data::Dumper; #print "$name: ". Dumper($dump); @@ -182,6 +203,8 @@ BEGIN { } } + #} else { + # die "unrecognized type $type\n"; } }