#! /usr/bin/env perl

use strict;
use warnings;

# we will list our name servers as CLI arguments
my %ourNS = map { lc $_ => 1 } @ARGV;
# if we don't clear ARGV, perl thinks we're passing filenames
# to open for STDIN
@ARGV = ();

# The tab delimited file of nameserver\tdomain are on STDIN
my @domainList = <>;
chomp @domainList;

my %weHost;
my %dontHost;

# get the ones we DO host
for ( my $i = 0; $i < @domainList; $i++ ) {
   my ($ns,$domain) = split( "\t", $domainList[$i] );
   $weHost{$domain} = 1 if $ourNS{lc $ns} || defined( $weHost{$domain} );
}

# get the ones we DON'T host. NOTE: we do it this way because a user may have
# us as a primary or a secondary, and have an entry with some other entity
for ( my $i = 0; $i < @domainList; $i++ ) {
   my ($ns,$domain) = split( "\t", $domainList[$i] );
   $dontHost{$domain} = 1 unless defined( $weHost{$domain} );
}

# dump the output
print "We don't do DNS for these domains\n" . join( "\n", keys %dontHost ) . "\n";

1;