1#!/usr/bin/perl 2# 3# $Id: dnscheck.pl 883 2010-06-15 08:27:51Z calle $ 4# 5# Copyright (c) 2007 .SE (The Internet Infrastructure Foundation). 6# All rights reserved. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28# 29###################################################################### 30 31require 5.008; 32use warnings; 33use strict; 34 35use Getopt::Long; 36use Pod::Usage; 37use DNSCheck; 38 39###################################################################### 40 41sub main { 42 my $help = 0; 43 my $debug = 0; 44 my $raw = 0; 45 46 my $locale = 'en'; 47 my ( 48 $configdir, $sitedir, $configfile, $siteconfigfile, 49 $policyfile, $sitepolicyfile, $localefile, @nameservers, 50 $what_test, $rootsource, $history, 51 ); 52 53 GetOptions( 54 'help|?' => \$help, 55 'raw' => \$raw, 56 'debug+' => \$debug, 57 'configdir=s' => \$configdir, 58 'sitedir=s' => \$sitedir, 59 'configfile=s' => \$configfile, 60 'siteconfigfile=s' => \$siteconfigfile, 61 'policyfile=s' => \$policyfile, 62 'sitepolicyfile=s' => \$sitepolicyfile, 63 'localefile=s' => \$localefile, 64 'locale=s' => \$locale, 65 'nameserver=s' => \@nameservers, 66 'test=s' => \$what_test, 67 'rootsource=s' => \$rootsource, 68 'history=s' => \$history, 69 ) or pod2usage(2); 70 pod2usage(1) if ($help); 71 72 my $zone = shift @ARGV; 73 74 unless ($zone) { 75 pod2usage(2); 76 } 77 78 my $extras = {}; 79 $extras->{logging}->{interactive} = 1; 80 $extras->{debug} = $debug; 81 82 my $conf = {}; 83 $conf->{configdir} = $configdir if $configdir; 84 $conf->{sitedir} = $sitedir if $sitedir; 85 $conf->{configfile} = $configfile if $configfile; 86 $conf->{siteconfigfile} = $siteconfigfile if $siteconfigfile; 87 $conf->{policyfile} = $policyfile if $policyfile; 88 $conf->{sitepolicyfile} = $sitepolicyfile if $sitepolicyfile; 89 $conf->{localefile} = $localefile if $localefile; 90 $conf->{locale} = ($raw ? undef : $locale); 91 $conf->{extras} = $extras; 92 $conf->{rootsource} = $rootsource; 93 94 my $check = new DNSCheck($conf); 95 96 foreach my $ns (@nameservers) { 97 my ($name, $ip) = split(m|/|, $ns); 98 if ($ip) { 99 $check->add_fake_glue($zone, $name, $ip); 100 } else { 101 $check->add_fake_glue($zone, $name); 102 } 103 } 104 105 my $href; 106 $href = [split /,/, $history] if defined($history); 107 108 if ($what_test) { 109 $what_test = lc($what_test); 110 } 111 112 if (!$what_test or $what_test eq 'zone') { 113 $check->zone->test($zone, $href); 114 } elsif ($what_test eq 'connectivity') { 115 $check->connectivity->test($zone); 116 } elsif ($what_test eq 'consistency') { 117 $check->consistency->test($zone); 118 } elsif ($what_test eq 'dnssec') { 119 $check->dnssec->test($zone); 120 } elsif ($what_test eq 'delegation') { 121 $check->delegation->test($zone, $href); 122 } elsif ($what_test eq 'soa') { 123 $check->soa->test($zone); 124 } else { 125 print 126 "Don't know how to perform a test of type $what_test on a zone.\n"; 127 exit(1); 128 } 129 130 $check->log_nameserver_times; 131} 132 133main(); 134 135__END__ 136 137=head1 NAME 138 139dnscheck - DNSCheck Tool 140 141=head1 SYNOPSIS 142 143dnscheck [options] zone 144 145Options: 146 147 --help brief help message 148 --debug enable debugging. use twice for dns packet dump. 149 --raw raw log output, suitable for automatic processing 150 --configdir directory to look for config files in 151 --sitedir directory to look for site-specific config in 152 --configfile specify a configuration file 153 --siteconfigfile specify a file to read site config from 154 --policyfile specify a policy file 155 --sitepolicyfile specify a file to read site-specific policy from 156 --localefile specify a file to read locale from 157 --locale specify a locale to be used 158 --nameserver specify glue data as the name of a nameserver, or as 159 a name followed by a slash and its IP address. This 160 option can be given several times to specify multiple 161 servers or multiple IP addresses for the same name. 162 --history specify delegation history. Give the nameserver names 163 as a comma-separated list. 164 --test=<test> Specify which of the whole-zone tests to run. Currently 165 available are: zone, connectivity, consistency, 166 dnssec, delegation and soa. 167 168 More specific options override less specific ones. If you, for example, give 169 both C<--configdir> and C<--sitepolicyfile> all config will be read from files 170 in the directory given in the first option, except for site-specific policy 171 changes which will be read from the given file. 172 173 The locales available for use with the C<--locale> switch at the time being 174 are sv and en. en is the default. 175