line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Provision::Unix::DNS; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Provision::Unix::DNS::VERSION = '1.07'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
# ABSTRACT: generic class for common DNS tasks |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1829
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use English qw( -no_match_vars ); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
6
|
|
11
|
1
|
|
|
1
|
|
876
|
use Params::Validate qw(:all); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use lib 'lib'; |
14
|
|
|
|
|
|
|
use Provision::Unix::Utility; |
15
|
|
|
|
|
|
|
my $util; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
|
|
|
|
|
|
my $class = shift; |
19
|
|
|
|
|
|
|
my %p = validate( |
20
|
|
|
|
|
|
|
@_, |
21
|
|
|
|
|
|
|
{ prov => { type => OBJECT }, |
22
|
|
|
|
|
|
|
debug => { type => BOOLEAN, optional => 1, default => 1 }, |
23
|
|
|
|
|
|
|
fatal => { type => BOOLEAN, optional => 1, default => 1 }, |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $self = { |
28
|
|
|
|
|
|
|
prov => $p{prov}, |
29
|
|
|
|
|
|
|
debug => $p{debug}, |
30
|
|
|
|
|
|
|
fatal => $p{fatal}, |
31
|
|
|
|
|
|
|
}; |
32
|
|
|
|
|
|
|
bless( $self, $class ); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$util = Provision::Unix::Utility->new( log => $p{prov}, debug=>$p{debug},fatal=>$p{fatal} ); |
35
|
|
|
|
|
|
|
$self->{server} = $self->_get_server() or return; |
36
|
|
|
|
|
|
|
$self->{prov}->audit("loaded DNS"); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub connect { |
42
|
|
|
|
|
|
|
my $self = shift; |
43
|
|
|
|
|
|
|
my %args = @_; |
44
|
|
|
|
|
|
|
foreach ( keys %args ) { delete $args{$_} if ! defined $args{$_}; }; |
45
|
|
|
|
|
|
|
$self->{server}->connect(%args); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub create_zone { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
############################################ |
51
|
|
|
|
|
|
|
# Usage : $dns->create_zone({ zone=>'example.com' }); |
52
|
|
|
|
|
|
|
# Purpose : Create a new zone |
53
|
|
|
|
|
|
|
# Returns : failure: undef |
54
|
|
|
|
|
|
|
# : success: zone_id for nictool, 1 for others methods |
55
|
|
|
|
|
|
|
# Parameters |
56
|
|
|
|
|
|
|
# Required : S - zone - the fully qualified zone name |
57
|
|
|
|
|
|
|
# Optional : S - contact - the email address of the hostmaster |
58
|
|
|
|
|
|
|
# : I - ttl, refresh, retry, expire, minimum |
59
|
|
|
|
|
|
|
# : S - template - the name of a template to use |
60
|
|
|
|
|
|
|
# : S - ip - an IP address for the template |
61
|
|
|
|
|
|
|
# : S - mailip - an IP address for the zones MX |
62
|
|
|
|
|
|
|
# Throws : no exceptions |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
my %args = @_; |
66
|
|
|
|
|
|
|
foreach ( keys %args ) { delete $args{$_} if ! defined $args{$_}; }; |
67
|
|
|
|
|
|
|
$self->{server}->create_zone(%args); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub create_zone_record { |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
############################################ |
73
|
|
|
|
|
|
|
# Usage : $dns->create_zone_record(); |
74
|
|
|
|
|
|
|
# Purpose : Create a new zone record |
75
|
|
|
|
|
|
|
# Returns : failure: undef, success: 1 |
76
|
|
|
|
|
|
|
# Parameters |
77
|
|
|
|
|
|
|
# Required : S - zone - the fully qualified zone name |
78
|
|
|
|
|
|
|
# : S - name - the zone record name |
79
|
|
|
|
|
|
|
# : S - type - A, MX, CNAME, NS, SRV, TXT |
80
|
|
|
|
|
|
|
# : S - address - an IP address |
81
|
|
|
|
|
|
|
# : S - port - SRV records only |
82
|
|
|
|
|
|
|
# : S - priority - SRV records only |
83
|
|
|
|
|
|
|
# Optional : S - ttl - TTL |
84
|
|
|
|
|
|
|
# : S - zone_id - zone id |
85
|
|
|
|
|
|
|
# : S - weight (mx & srv records only) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $self = shift; |
88
|
|
|
|
|
|
|
$self->{server}->create_zone_record(@_); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub get_zone { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
############################################ |
94
|
|
|
|
|
|
|
# Usage : $dns->get_zone( zone=>'example.com'); |
95
|
|
|
|
|
|
|
# Purpose : Find a zone |
96
|
|
|
|
|
|
|
# Returns : depends on $dns backend |
97
|
|
|
|
|
|
|
# Parameters |
98
|
|
|
|
|
|
|
# Required : S - zone - the fully qualified zone name |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my $self = shift; |
101
|
|
|
|
|
|
|
return $self->{server}->get_zone(@_); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub modify_zone { |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub delete_zone { |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
return $self->{server}->delete_zone(@_); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub delete_zone_record { |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
return $self->{server}->delete_zone_record(@_); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub qualify { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# this is server dependent. BIND and NicTool support shortcuts like @. Others |
122
|
|
|
|
|
|
|
# need to be fully qualified (like tinydns). |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
return $self->{server}->qualify(@_); |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _get_server { |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
my $prov = $self->{prov}; |
132
|
|
|
|
|
|
|
my $debug = $self->{debug}; |
133
|
|
|
|
|
|
|
my $fatal = $self->{fatal}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
my $chosen_server = $prov->{config}{DNS}{server} |
136
|
|
|
|
|
|
|
or $prov->error( 'missing [DNS] server setting in provision.conf', |
137
|
|
|
|
|
|
|
fatal => $fatal, |
138
|
|
|
|
|
|
|
debug => $debug, |
139
|
|
|
|
|
|
|
); |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# try to autodetect the server |
142
|
|
|
|
|
|
|
if ( ! $chosen_server ) { |
143
|
|
|
|
|
|
|
if ( $util->find_bin( 'tinydns', debug=>0,fatal => 0 ) ) { |
144
|
|
|
|
|
|
|
$chosen_server = 'tinydns'; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
elsif ( $util->find_bin( 'named', debug=>0,fatal => 0) ) { |
147
|
|
|
|
|
|
|
$chosen_server = 'bind'; |
148
|
|
|
|
|
|
|
}; |
149
|
|
|
|
|
|
|
}; |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
if ( ! $chosen_server ) { |
152
|
|
|
|
|
|
|
return $prov->error( "No DNS server selected and I could not find one installed. Giving up.", |
153
|
|
|
|
|
|
|
fatal => $fatal, |
154
|
|
|
|
|
|
|
debug => $debug, |
155
|
|
|
|
|
|
|
); |
156
|
|
|
|
|
|
|
}; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
if ( $chosen_server eq 'nictool' ) { |
159
|
|
|
|
|
|
|
eval { require Provision::Unix::DNS::NicTool; }; |
160
|
|
|
|
|
|
|
if ($EVAL_ERROR) { |
161
|
|
|
|
|
|
|
return $prov->error ( $EVAL_ERROR, fatal => $fatal, debug => $debug ); |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
my $r = Provision::Unix::DNS::NicTool->new( |
164
|
|
|
|
|
|
|
prov => $prov, |
165
|
|
|
|
|
|
|
fatal => $fatal, |
166
|
|
|
|
|
|
|
debug => $debug, |
167
|
|
|
|
|
|
|
); |
168
|
|
|
|
|
|
|
#warn Data::Dumper::Dumper($r); |
169
|
|
|
|
|
|
|
if ( ! $r ) { |
170
|
|
|
|
|
|
|
return $prov->error( $prov->get_last_error(), |
171
|
|
|
|
|
|
|
debug => $debug, |
172
|
|
|
|
|
|
|
fatal => $fatal, |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
return $r; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
elsif ( $chosen_server eq 'tinydns' ) { |
178
|
|
|
|
|
|
|
require Provision::Unix::DNS::tinydns; |
179
|
|
|
|
|
|
|
return Provision::Unix::DNS::tinydns->new( prov => $prov ); |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
elsif ( $chosen_server eq 'bind' ) { |
182
|
|
|
|
|
|
|
require Provision::Unix::DNS::BIND; |
183
|
|
|
|
|
|
|
return Provision::Unix::DNS::BIND->new( prov => $prov ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
else { |
186
|
|
|
|
|
|
|
return $prov->error( "no support for $chosen_server yet", |
187
|
|
|
|
|
|
|
fatal => $fatal, |
188
|
|
|
|
|
|
|
debug => $debug, |
189
|
|
|
|
|
|
|
); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
1; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
__END__ |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=pod |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=encoding UTF-8 |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 NAME |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Provision::Unix::DNS - generic class for common DNS tasks |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 VERSION |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
version 1.07 |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 SYNOPSIS |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
The Provision::Unix::DNS provides a consistent API for managing DNS zones and records regardless of the underlying DNS server. Applications make calls to Provision::Unix::DNS such as create_zone, create_zone_record, modify_zone, etc. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
use Provision::Unix::DNS; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
my $dns = Provision::Unix::DNS->new(); |
216
|
|
|
|
|
|
|
$dns->zone_create( zone=>'example.com' ); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
$dns->zone_modify( zone=>'example.com', hostmaster=>'dnsadmin@admin-zone.com' ); |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 DESCRIPTION |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Rather than write code to generate BIND zone files, tinydns data files, or API calls to various servers, write your application to use Provision::Unix::DNS instead. The higher level DNS class contains methods for each type of DNS task as well as error handling, rollback support, and logging. Based on the settings in your provision.conf file, your request will be dispatched to your DNS Server of choice. Subclasses are created for each type of DNS server. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Support is included for NicTool via its native API and tinydns. I will leave it to others (or myself in the unplanned future) to write modules to interface with other DNS servers. Good candidates for modules are BIND and PowerDNS. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 FUNCTIONS |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 create_zone |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 create_zone_record |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 get_zone |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 BUGS |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-unix-provision-dns at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Provision-Unix>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head1 SUPPORT |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
perldoc Provision::Unix::DNS |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
You can also look for information at: |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=over 4 |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Provision-Unix> |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Provision-Unix> |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item * CPAN Ratings |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Provision-Unix> |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item * Search CPAN |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Provision-Unix> |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=back |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 AUTHOR |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Matt Simerson <msimerson@cpan.org> |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
This software is copyright (c) 2014 by The Network People, Inc.. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
275
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |