#! /usr/bin/perl -w
use strict;

my $date = `date --rfc-2822`;
chomp $date;

my @nets = ();
open NAMES, "switches.txt"
	or die "switches.txt: $!";
while (<NAMES>) {
	chomp;
	/87\.76\.(\d+\.\d+)\s+(\d+)\s+(\S+)/ or next;
	push @nets, {
		net => $1,
		netmask => $2,
		name => $3
	};
}	

print <<"EOF";
// Autogenerated by make-named-secondary.pl at $date. Do not edit manually! 

options {
        directory "/etc/bind";
	allow-query { any; };
	allow-transfer { 194.19.3.20; }; 
	auth-nxdomain no;
	recursion yes;

//	forwarders { 194.19.2.11; 194.19.3.11; }; 
//	forward only;
};

zone "." { type hint; file "db.root"; };

zone "0.0.127.in-addr.arpa" {
	type master;
	file "0.0.127.in-addr.arpa";
	notify no;
};

zone "tg07.gathering.org" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	file "tg07.gathering.org";
};

// nett-subnett
zone "239.0.194.in-addr.arpa" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	file "239.0.194.in-addr.arpa";
	allow-transfer { 193.0.0.0/22; };
};

// serversubnett
zone "254.0.194.in-addr.arpa" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	file "254.0.194.in-addr.arpa";
	allow-transfer { 193.0.0.0/22; };
};
zone "255.0.194.in-addr.arpa" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	file "255.0.194.in-addr.arpa";
	allow-transfer { 193.0.0.0/22; };
};

zone "76.87.in-addr.arpa" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	allow-update { key DHCP_UPDATER; };
	file "dynamic/0.194.in-addr.arpa";	
	allow-transfer { 194.19.3.20; 193.0.0.0/22; };
};

key DHCP_UPDATER {
	algorithm HMAC-MD5.SIG-ALG.REG.INT;
	secret 5Yz1azvh7mE0IRGffTvtKg==;
};

EOF

for my $net (@nets) {
	my $d = $net->{name};

	print <<"EOF";
zone "$d.tg07.gathering.org" {
	type slave;
	notify no;
	masters { 87.76.254.2; };
	allow-update { key DHCP_UPDATER; };
	file "dynamic/$d.tg07.gathering.org";
	allow-transfer { 194.19.3.20; };
};
EOF
}
