<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
     "dtd/xml/4.1.2/docbookx.dtd"[
<!ENTITY % afnic_custom SYSTEM "../../lib/afnic-docbook.inc">
%afnic_custom;
]>
<!-- $Id: zone-file-generator.db,v 1.3 2003-10-22 16:19:18 bortzmeyer Exp $ -->
<article>
  <articleinfo>
    <title>The zone file generator</title>
    <author>
      <surname>Bortzmeyer</surname>
      <firstname>Stephane</firstname>
    </author>
    <pubdate>$Date: 2003-10-22 16:19:18 $</pubdate>
  </articleinfo>
<para>It is quite difficult to write a software that will work for every NIC
in the world (even with a lot of options in the configuration
file). Unless everybody chooses the same model of a registry, of
course. But if you want to follow your own way, you'll have to do some
coding. One element of this software is the zone file generator, that
will create a zone file from the information stored in the database.</para>

<para>In this model, the information (domain names,
contacts, name servers - not always with the IP address, only when
it's necessary, resellers, etc) is in some sort of database (a RDBMS, for
instance) and the zone file is generated from the database.</para>

<para>To extract info from the database, use something like <ulink url="http://www.perl.com/pub/a/1999/10/DBI.html">Perl DBI</ulink> (a ten-line script is
sufficient) or a shell command as simple as (for PostgreSQL):

<programlisting>
#!/bin/sh
psql -q --no-align --tuples-only registry \
     -c "SELECT address, hosts.name as host, domains.name as domain\
           FROM Hosts,Domains,Nameservers\
           WHERE nameservers.domain = domains.id AND \
                 nameservers.nameserver = hosts.id" |\
   awk -F \| '{ print $3". IN NS "$2"."; if ($1) {print $2". IN A "$1"" } }' 
</programlisting>
This generator is not perfect. If a name server is used for N domains,
its glue record will appear N times in the zone file. But you get the idea.
</para>

<para>This is more work than just managing the BIND zone file by hand but it's worth
it.</para>

</article>

