Last active
January 12, 2017 18:37
-
-
Save mat813/aa00cb7b781975b9f7e947dbc0450dc8 to your computer and use it in GitHub Desktop.
Revisions
-
mat813 revised this gist
Jan 12, 2017 . 1 changed file with 29 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ #!/usr/bin/env perl # use 5.008; use utf8; use strict; use warnings; @@ -9,60 +10,68 @@ use File::Path qw(make_path); use DNS::ZoneParse; use Data::Dumper; use Readonly; use Carp; my $directory = $ARGV[0]; Readonly::Scalar my $SEPARATOR => q(#); my $dh; opendir $dh, $directory; sub touch { my $out = File::Spec->catfile(@_); return if -e $out; my $f; open $f, '>', $out or carp "$out -> $!"; close $f or carp "$out -> $!"; return; } sub mkdata { return join($SEPARATOR, @_) . $SEPARATOR; } while (my $file = readdir $dh) { my $fullpath = File::Spec->catfile($directory, $file); next if -d $fullpath; my $basepath = File::Spec->catfile(reverse split /[.]/ms, $file); my $xfrpath = File::Spec->catfile($basepath, 'xfr_d'); my $dnspath = File::Spec->catfile($basepath, 'dns_d'); make_path($basepath, $xfrpath, $dnspath); touch($xfrpath, '127.0.0.1'); my $zh; open $zh, '<', $fullpath; my $origin = $file . q(.); while (my $line = <$zh>) { chomp $line; my ($rr, $ttl, $in, $type, $rrdata) = split /\s+/oms, $line, 5; my $rrname; if ($origin eq $rr) { $rrname = q(@); } else { $rrname = $rr; $rrname =~ s/[*]/-/oms; $rrname =~ s/[.]$origin//ms; } my $rrpath = File::Spec->catfile($dnspath, reverse split /[.]/ms, $rrname); make_path($rrpath); $rrdata =~ s/\//%/ogms; touch($rrpath, mkdata($type, $ttl, $rrdata)); } close $zh or carp $!; } closedir $dh; -
mat813 created this gist
Jan 12, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/usr/bin/env perl # use utf8; use strict; use warnings; use File::Spec; use File::Path qw(make_path); use DNS::ZoneParse; use Data::Dumper; my $directory = $ARGV[0]; use constant SEPARATOR => '#'; opendir((my $dh), $directory); sub touch { my $out = File::Spec->catfile(@_); return if -f $out; open(my $f, '>', $out) or warn "$out -> $!"; close $f; } sub mkdata { join(SEPARATOR, @_) . SEPARATOR; } while (my $file = readdir($dh)) { my $fullpath = File::Spec->catfile($directory, $file); next unless -f $fullpath; my $basepath = File::Spec->catfile(reverse split(/\./, $file)); my $xfrpath = File::Spec->catfile($basepath, 'xfr_d'); my $dnspath = File::Spec->catfile($basepath, 'dns_d'); make_path($basepath, $xfrpath, $dnspath); touch($xfrpath, '127.0.0.1'); open((my $zh), '<', $fullpath); my $origin = $file . '.'; while (my $line = <$zh>) { chomp($line); my ($rr, $ttl, $in, $type, $data) = split(/\s+/o, $line, 5); my $rrname; if ($origin eq $rr) { $rrname = '@'; } else { $rrname = $rr; $rrname =~ s/\*/-/o; $rrname =~ s/\.$origin//; } my $rrpath = File::Spec->catfile($dnspath, reverse split(/\./, $rrname)); make_path($rrpath); $data =~ s/\//%/og; touch($rrpath, mkdata($type, $ttl, $data)); } } closedir($dh);