#! /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.pl at $date. Do not edit manually! 

options {
        directory "/etc/bind";
	allow-query { any; };
	allow-transfer { 194.19.3.20; 87.76.255.2; }; 
	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 master;
	file "tg07.gathering.org";
	notify yes;
	allow-transfer { 87.76.255.2; };
};

// serversubnett
zone "254.76.87.in-addr.arpa" {
	type master;
	file "254.76.87.in-addr.arpa";
	notify yes;
	allow-transfer { 87.76.255.2; 193.0.0.0/22; };
};
zone "255.76.87.in-addr.arpa" {
	type master;
	file "255.76.87.in-addr.arpa";
	notify yes;
	allow-transfer { 87.76.255.2; 193.0.0.0/22; };
};

zone "76.87.in-addr.arpa" {
	type master;
	allow-update { key DHCP_UPDATER; };
	notify yes;
	file "dynamic/76.87.in-addr.arpa";	
	allow-transfer { 194.19.3.20; 87.76.255.2; 193.0.0.0/22; };
};

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

EOF

for my $net (@nets) {
	my $domain = $net->{name};
	print <<"EOF";
zone "$domain.tg07.gathering.org" {
	type master;
	allow-update { key DHCP_UPDATER; };
	notify yes;
	file "dynamic/$domain.tg07.gathering.org";
	allow-transfer { 194.19.3.20; 87.76.255.2; };
};
EOF
}
