#! /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
	};
}	

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

	-f "/etc/bind/dynamic/$d.tg07.gathering.org" and next;
			
	print "/etc/bind/dynamic/$d.tg07.gathering.org\n";
	open ZONE, ">/etc/bind/dynamic/$d.tg07.gathering.org"
		or die "/etc/bind/dynamic/$d.tg07.gathering.org";

	print ZONE <<"EOF";
; autogenerated and updated from dhcpd -- DO NOT TOUCH!
\$TTL 3600
@	IN	SOA	sysrq.tg07.gathering.org.	abuse.gathering.org. (
			3   ; serial
			3600 ; refresh 
			1800 ; retry
			608400 ; expire
			3600 ) ; minimum and default TTL

		IN	NS	sysrq.tg07.gathering.org.
		IN	NS	insert.tg07.gathering.org.

EOF
}
