#!/usr/bin/perl

# Print a list of all dNSDomain2 zones in LDAP to
# include in BIND.

use strict;
use Net::LDAP;

my @masters = qw(192.168.1.20   192.168.2.56);

my $ldap = Net::LDAP->new('localhost') or die "$@";

my $mesg = $ldap->bind('cn=manager,dc=qupps,dc=biz', password=>'heh?');

$mesg = $ldap->search(
    base   => "ou=pdns,ou=dns,dc=qupps,dc=biz",
    filter => "(&(objectClass=dnsDomain2)(sOARecord=*))",
    attrs  => [ 'associatedDomain' ],
);

$mesg->code && die $mesg->error;

foreach my $e ($mesg->entries) {
    my $zone = $e->get_value('associateddomain');

    print "zone \"$zone\" IN {\n";
    print "  type slave;\n";
    print "  file \"$zone.zone\";\n";
    print "  masters { " . join('; ', @masters) . "; };\n";
    print "};\n";
}

$ldap->unbind;

