diff options
Diffstat (limited to 'bootstrap/make-named.pl')
-rwxr-xr-x | bootstrap/make-named.pl | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/bootstrap/make-named.pl b/bootstrap/make-named.pl new file mode 100755 index 0000000..a9ea02d --- /dev/null +++ b/bootstrap/make-named.pl @@ -0,0 +1,129 @@ +#!/usr/bin/perl -I /root/tgmanage +use strict; + +BEGIN { + require "include/config.pm"; + eval { + require "include/config.local.pm"; + }; +} + + +use Net::IP; +use Net::IP qw(:PROC); + +unless ( (($#ARGV == 0 ) || ( $#ARGV == 1)) + && (( $ARGV[0] eq "master" ) || ( $ARGV[0] eq "slave" )) ) +{ + print STDERR "Invalid usage!\ncat netnames.txt | $0 <master|slave> [basedir]\n"; + exit 1; +} + +my $role = $ARGV[0]; + +my $base = "/etc"; +$base = $ARGV[1] if $#ARGV == 1; +$base .= "/" if not $base =~ m/\/$/ and not $base eq ""; + +my $bind_base = $base . "bind/"; +my $named_file = $bind_base . "named.conf"; + +if ( -f $named_file ) +{ + print STDERR $named_file . " already exists. Cowardly refusing to continue.\n"; + exit; +} + +my $run = `date +%Y%m%d-%H%M`; + +open NFILE, ">" . $named_file or die ( $! . " " . $named_file ); + +chomp $run; +print NFILE <<EOF; +// This named.conf was generated by make-named.pl at $run +// The current version of make-named.pl should not overwrite this file. +acl tg-nett { $nms::config::base_ipv4net; $nms::config::base_ipv6net; $nms::config::extra_net; 127.0.0.0/8; ::1; }; +acl ns-xfr { $nms::config::sec_v4; $nms::config::sec_v6; $nms::config::pri_v4; $nms::config::pri_v6; $nms::config::noc_nett; }; +acl ext-xfr { $nms::config::ext_xfer; }; + +options { + directory "/etc/bind"; + allow-recursion { tg-nett; }; + allow-query { any; }; + allow-transfer { ns-xfr; }; + recursion yes; + auth-nxdomain no; + listen-on-v6 { any; }; +}; + +key DHCP_UPDATER { + algorithm HMAC-MD5.SIG-ALG.REG.INT; + secret $nms::config::ddns_key; +}; +EOF + +if ( $role eq "master" ) +{ + print NFILE <<EOF; + +zone "$nms::config::tgname.gathering.org" { + type master; + file "$nms::config::tgname.gathering.org.zone"; + notify yes; + allow-transfer { ns-xfr; }; +}; + +zone "infra.$nms::config::tgname.gathering.org" { + type master; + file "infra.$nms::config::tgname.gathering.org.zone"; + notify yes; + allow-transfer { ns-xfr; }; +}; + +zone "$nms::config::ipv6zone" { + type master; + allow-update { key DHCP_UPDATER; }; + notify yes; + file "$nms::config::ipv6zone.zone"; + allow-transfer { ns-xfr; ext-xfr; }; +}; + +include "/etc/bind/named.conf.default-zones"; +include "named.reverse4.conf"; +include "named.master-include.conf"; +EOF +} + +if ( $role eq "slave" ) +{ + print NFILE <<EOF; + +masters master_ns { $nms::config::pri_v6; $nms::config::pri_v4; }; + +zone "$nms::config::tgname.gathering.org" { + type slave; + file "slave/$nms::config::tgname.gathering.org"; + notify no; + masters { master_ns; }; +}; + +zone "infra.$nms::config::tgname.gathering.org" { + type slave; + file "slave/infra.$nms::config::tgname.gathering.org"; + notify no; + masters { master_ns; }; +}; + +zone "$nms::config::ipv6zone" { + type slave; + notify no; + masters { master_ns; }; + file "slave/$nms::config::ipv6zone:"; + allow-transfer { ns-xfr; ext-xfr; }; +}; + +include "named.conf.default-zones"; +include "named.slave-reverse4.conf"; +include "named.slave-include.conf"; +EOF +} |