#!/usr/bin/perl -w # # Copyright (c) 2000 2000 James Raftery . All rights reserved. # This program is free software; you can redistribute it and/or # modify it under the same terms as Perl itself. # Please submit bug reports, patches and comments to the author. # # This program is a filter which reads a version 2 RIPE-like database # and outputs BIND master-file-format and tinydns-data format DNS data # for domain objects. # # Inspired by code written by Niall Richard Murphy, IE Domain Registry, # University College Dublin for the IEDR's modified RIPE DB and which # output BIND data only. # use Getopt::Std; getopts("b:t:s:o:h"); unless ($opt_t or $opt_b) { print "Required argument missing.\n"; $opt_h = 1; } if ($opt_h) { print <>$opt_b") or die "Open $opt_b failed: $!"; print B "\$TTL $opt_s\n"; } if ($opt_t) { open(T, ">>$opt_t") or die "Open $opt_t failed: $!"; } $opt_o = "" unless $opt_o; $/ = ""; while (<>) { if (/^\*dn: /) { # domain object @object = split(/\n/); foreach (@object) { if (s/^\*dn: //) { # Domain tr/A-Z/a-z/; s/\.+$//; $fqdn = $_; $bindfqdn = (s/\.$opt_o$//o ? $_ : "$_."); next; } if (s/^\*ns: //) { # Nameserver ($_, $ip) = split; $ip = "" unless $ip; tr/A-Z/a-z/; s/\.+$//; $ip = "" unless /(^|\.)$fqdn$/; $ns = $_; $bindns = (s/\.$opt_o$//o ? $_ : "$_."); $rr{"tiny"} .= "&${fqdn}:$ip:$ns:$opt_s\n"; $rr{"glue"} .= "$bindns\t\tA\t$ip\n" if $ip; $rr{"bind"} .= ($rr{"bind"} ? "\t" : $bindfqdn) . "\t\tNS\t$bindns\n"; } } if ($opt_b) { if ($rr{"glue"}) { print B $rr{"glue"}; $rr{"glue"} = ""; } if ($rr{"bind"}) { print B $rr{"bind"}; $rr{"bind"} = ""; } } if ($opt_t and $rr{"tiny"}) { print T $rr{"tiny"}; $rr{"tiny"} = ""; } } }