#!/usr/bin/perl sub BEGIN { unshift (@INC, '/usr/local/openlsm/lib/perl_module'); unshift (@INC, '/usr/lib/perl5/'); } use strict; use warnings; use POSIX qw(strftime); use File::Slurp; # global setting my $BasePath = "/var/named/chroot"; my $namedConf_Path = "${BasePath}/etc/named.conf"; my $ZoneDir = "${BasePath}/var/named"; ## global variables my %F_ZONE; my %R_ZONE; my %F_REC; my %R_REC; my %Hash_IPAddr; my $Zone1; my $Zone2; no warnings 'uninitialized'; ################################ ## functions sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } ## list of all available # ipaddrs in forward zone sub IPList { while (my ($z_name,$h_ref)= each(%F_REC)) { while (my ($myhost,$h_info)= each(%{$h_ref})) { my $ipaddr = $h_info->{'A'}; $Hash_IPAddr{"$ipaddr"}{'zone'} = $z_name; } # } #zones } ################################ my $GoAhead = "NO"; if ( $ARGV[0] =~ m/-+verify/ ) { print "\nWelcome to dnsTool\n"; print "-" x 50 ."\n"; } else { print "\n * Usage: $0 { --verify }\n\n"; exit 1;} #Parse named.conf file my @text = read_file($namedConf_Path); my $filter=0; my $z_name; foreach my $line (@text) { chomp($line); if (($line !~ /^\s*$/) && ($line !~ /^\s*#.*/) && ($line !~ /^\s*;.*/)) { #print "\nL-$line"; ## forward and reverse zone if ($line =~ m/^\s?zone\s+("|')(\d+).(\d+).(\d+).in-addr.arpa("|')\s+{/) { $filter=2; $z_name = "$2.$3.$4"; #print "\nReverse START- $4.$3.$2"; } elsif (($line =~ m/^\s?zone\s+("|')(.*)("|')\s+.*{/) && ($line !~ m/arpa("|')\s+(IN|)\s+{/)) { $filter=1; $z_name = "$2"; #print "\nForward START- $2"; } elsif ($line =~ m/^\s?};.*$/ ) { if (($filter == 2) || ($filter == 1)) { #print "\n$line - END"; $filter=0; $z_name = undef; } } else { if (($filter == 2) || ($filter == 1)) { #print "\nL-$line"; if ($line =~ m/^\s+(\w+)\s+(.*);/) { if ($z_name ne '.') { my $field = "$2"; my $field_key = "$1"; $field =~ s/"//; $field =~ s/"//; #print "\n\tField[$z_name]- $1 - $2"; if ($filter == 1) { $F_ZONE{"$z_name"}{"$field_key"} = $field; } if ($filter == 2) { $R_ZONE{"$z_name"}{"$field_key"} = "$field"; } } #ignore zone-if } } } #zone-if-else } #line-if } ############### Action here ############### while (my ($z_name,$h_ref)= each(%F_ZONE)) { #print "\nZone- $z_name => $h_ref->{'type'} => $h_ref->{'file'}"; my $z_file = "${ZoneDir}/$h_ref->{'file'}"; #print "\nForward Zone- $z_name - $z_file"; my $out = `named-checkzone $z_name $z_file`; print "\n$out"; } print "\n"; while (my ($z_name,$h_ref)= each(%R_ZONE)) { #print "\nZone- $z_name => $h_ref->{'type'} => $h_ref->{'file'}"; my $z_file = "${ZoneDir}/$h_ref->{'file'}"; $z_name = ${z_name}.".in-addr.arpa"; #print "\nReverse Zone- $z_name - $z_file"; my $out = `named-checkzone $z_name $z_file`; print "\n$out"; } ################################ #end print "\n\n";