line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
TinyDNS::Reader - Read TinyDNS files. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 DESCRIPTION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
This module allows the parsing of a TinyDNS data-file, or individual records |
9
|
|
|
|
|
|
|
taken from one. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use TinyDNS::Reader; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $tmp = TinyDNS::Reader->new( file => "./zones/example.com" ); |
18
|
|
|
|
|
|
|
my $dns = $tmp->parse(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
foreach my $record ( @$dns ) |
21
|
|
|
|
|
|
|
{ |
22
|
|
|
|
|
|
|
print $record . "\n"; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This module contains code for reading a zone-file which has been |
29
|
|
|
|
|
|
|
created for use with L<DJB's tinydns|http://cr.yp.to/djbdns/tinydns.html>. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
A zonefile may be parsed and turned into a series of L<TinyDNS::Record> objects, |
32
|
|
|
|
|
|
|
one for each valid record which is found. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
If you wish to merge multiple records, referring to the same hostname, you should also consult the documentation for the L<TinyeDNS::Reader::Merged> module. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
3
|
|
|
3
|
|
26673
|
use strict; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
70
|
|
43
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
80
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
package TinyDNS::Reader; |
46
|
|
|
|
|
|
|
|
47
|
3
|
|
|
3
|
|
759
|
use TinyDNS::Record; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
827
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
our $VERSION = '0.7.7'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head2 new |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
The constructor should be given either a "C<file>" or "C<text>" parameter, |
56
|
|
|
|
|
|
|
containing the filename to parse, or the text to parse, respectively. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new |
61
|
|
|
|
|
|
|
{ |
62
|
10
|
|
|
10
|
1
|
8397
|
my ( $proto, %supplied ) = (@_); |
63
|
10
|
|
33
|
|
|
35
|
my $class = ref($proto) || $proto; |
64
|
|
|
|
|
|
|
|
65
|
10
|
|
|
|
|
12
|
my $self = {}; |
66
|
10
|
|
|
|
|
12
|
bless( $self, $class ); |
67
|
|
|
|
|
|
|
|
68
|
10
|
50
|
|
|
|
24
|
if ( $supplied{ 'file' } ) |
|
|
50
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
|
|
0
|
$self->{ 'data' } = $self->_readFile( $supplied{ 'file' } ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ( $supplied{ 'text' } ) |
73
|
|
|
|
|
|
|
{ |
74
|
10
|
|
|
|
|
19
|
$self->{ 'data' } = $supplied{ 'text' }; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
die "Missing 'text' or 'file' argument."; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
23
|
return $self; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=begin doc |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Read the contents of the specified file. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Invoked by the constructor if it was passed a C<file> argument. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=end doc |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _readFile |
97
|
|
|
|
|
|
|
{ |
98
|
0
|
|
|
0
|
|
0
|
my ( $self, $file ) = (@_); |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
open( my $handle, "<", $file ) or |
101
|
|
|
|
|
|
|
die "Failed to read $file - $!"; |
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
my $text = ""; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
while ( my $line = <$handle> ) |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
|
|
0
|
$text .= $line; |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
0
|
close($handle); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
return ($text); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 parse |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Process and return an array of L<TinyDNS::Records> from the data contained |
118
|
|
|
|
|
|
|
in the file specified by our constructor, or the scalar reference. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub parse |
123
|
|
|
|
|
|
|
{ |
124
|
10
|
|
|
10
|
1
|
1215
|
my ($self) = (@_); |
125
|
|
|
|
|
|
|
|
126
|
10
|
|
|
|
|
8
|
my $records; |
127
|
|
|
|
|
|
|
|
128
|
10
|
|
|
|
|
33
|
foreach my $line ( split( /[\n\r]/, $self->{ 'data' } ) ) |
129
|
|
|
|
|
|
|
{ |
130
|
11
|
|
|
|
|
15
|
chomp($line); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
11
|
50
|
33
|
|
|
37
|
next if ( !$line || !length($line) ); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
11
|
|
|
|
|
13
|
$line =~ s/#.*$//s; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
11
|
50
|
33
|
|
|
27
|
next if ( !$line || !length($line) ); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
11
|
50
|
|
|
|
25
|
next if ( $line =~ /^\s*[:.]/ ); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
|
149
|
11
|
|
|
|
|
30
|
$line = lc($line); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
11
|
|
|
|
|
26
|
my $rec = TinyDNS::Record->new($line); |
155
|
11
|
50
|
|
|
|
24
|
push( @$records, $rec ) if ($rec); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
10
|
|
|
|
|
18
|
return ($records); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Steve Kemp <steve@steve.org.uk> |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Copyright (C) 2014-2015 Steve Kemp <steve@steve.org.uk>. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This code was developed for an online Git-based DNS hosting solution, |
176
|
|
|
|
|
|
|
which can be found at: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 8 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * |
181
|
|
|
|
|
|
|
https://dns-api.com/ |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=back |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
This library is free software. You can modify and or distribute it under |
186
|
|
|
|
|
|
|
the same terms as Perl itself. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|