line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNSbed; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20364
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
6
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
66
|
|
7
|
1
|
|
|
1
|
|
971
|
use JSON; |
|
1
|
|
|
|
|
18913
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
1358
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
45940
|
|
|
1
|
|
|
|
|
31
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
9
|
use vars qw/$VERSION/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1180
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.02'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
15
|
0
|
|
|
|
|
|
my $uid = shift; |
16
|
0
|
|
|
|
|
|
my $token = shift; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
bless {uid=>$uid,token=>$token},$class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub addZone { |
22
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
23
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
24
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
25
|
0
|
|
0
|
|
|
|
my $zone = shift || croak "you must provide a zone name"; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
$self->reqTemplate('addZone',"uid=$uid&token=$token&zone=$zone"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub delZone { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
33
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
34
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$self->reqTemplate('delZone',"uid=$uid&token=$token&zid=$zid"); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub addRecord { |
40
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
42
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
43
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
44
|
0
|
|
|
|
|
|
my %args = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $rname = $args{rname}; |
47
|
0
|
|
|
|
|
|
my $rtype = $args{rtype}; |
48
|
0
|
|
|
|
|
|
my $rvalue = $args{rvalue}; |
49
|
0
|
|
|
|
|
|
my $ttl = $args{ttl}; |
50
|
0
|
|
|
|
|
|
my $mxnum = $args{mxnum}; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->reqTemplate('addRecord',"uid=$uid&token=$token&zid=$zid&rname=$rname&rtype=$rtype&rvalue=$rvalue&ttl=$ttl&mxnum=$mxnum"); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub delRecord { |
56
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
57
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
58
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
59
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
60
|
0
|
|
|
|
|
|
my %args = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $rid = $args{rid}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->reqTemplate('delRecord',"uid=$uid&token=$token&zid=$zid&rid=$rid"); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub listZones { |
68
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
69
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
70
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
71
|
0
|
|
|
|
|
|
my $zid = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
|
if ($zid) { |
74
|
0
|
|
|
|
|
|
$self->reqTemplate('listZones',"uid=$uid&token=$token&zid=$zid"); |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
$self->reqTemplate('listZones',"uid=$uid&token=$token"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub checkZone { |
81
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
83
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
84
|
0
|
|
0
|
|
|
|
my $zone = shift || croak "you must provide a valid zone"; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self->reqTemplate('checkZone',"uid=$uid&token=$token&zone=$zone"); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub listRecords { |
90
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
92
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
93
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
94
|
0
|
|
|
|
|
|
my %args = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $rid = $args{rid}; |
97
|
0
|
|
|
|
|
|
my $rids = $args{rids}; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if ($rid) { |
|
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->reqTemplate('listRecords',"uid=$uid&token=$token&zid=$zid&rid=$rid"); |
101
|
|
|
|
|
|
|
} elsif ($rids) { |
102
|
0
|
|
|
|
|
|
$self->reqTemplate('listRecords',"uid=$uid&token=$token&zid=$zid&rids=$rids"); |
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
|
$self->reqTemplate('listRecords',"uid=$uid&token=$token&zid=$zid"); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub modifyRecord { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
111
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
112
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
113
|
0
|
|
|
|
|
|
my %args = @_; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $rid = $args{rid}; |
116
|
0
|
|
|
|
|
|
my $rname = $args{rname}; |
117
|
0
|
|
|
|
|
|
my $rtype = $args{rtype}; |
118
|
0
|
|
|
|
|
|
my $rvalue = $args{rvalue}; |
119
|
0
|
|
|
|
|
|
my $ttl = $args{ttl}; |
120
|
0
|
|
|
|
|
|
my $mxnum = $args{mxnum}; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->reqTemplate('modifyRecord',"uid=$uid&token=$token&zid=$zid&rid=$rid&rname=$rname&rtype=$rtype&rvalue=$rvalue&ttl=$ttl&mxnum=$mxnum"); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub searchRecords { |
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
127
|
0
|
|
|
|
|
|
my $uid = $self->{uid}; |
128
|
0
|
|
|
|
|
|
my $token = $self->{token}; |
129
|
0
|
|
0
|
|
|
|
my $zid = shift || croak "you must provide a zone ID"; |
130
|
0
|
|
|
|
|
|
my %args = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $keyword = $args{keyword}; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
$self->reqTemplate('searchRecords',"uid=$uid&token=$token&zid=$zid&keyword=$keyword"); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub reqTemplate { |
138
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
139
|
0
|
|
|
|
|
|
my $path = shift; |
140
|
0
|
|
|
|
|
|
my $args = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $url = "http://www.dnsbed.com/api/$path"; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
145
|
0
|
|
|
|
|
|
$ua->timeout(30); |
146
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new(POST => $url); |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$req->content_type('application/x-www-form-urlencoded'); |
149
|
0
|
|
|
|
|
|
$req->content($args); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
my $res = $ua->request($req); |
152
|
0
|
|
|
|
|
|
return decode_json($res->decoded_content); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
1; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 NAME |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Net::DNSbed - Perl client for DNSbed API |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 VERSION |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Version 0.02 |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SYNOPSIS |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
use Net::DNSbed; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
my $dnsbed = Net::DNSbed->new($uid,$token); |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
$dnsbed->addZone($zone); |
175
|
|
|
|
|
|
|
$dnsbed->listZones; |
176
|
|
|
|
|
|
|
$dnsbed->checkZone($zone); |
177
|
|
|
|
|
|
|
$dnsbed->delZone($zid); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$dnsbed->addRecord($zid, |
180
|
|
|
|
|
|
|
rname => $rname, |
181
|
|
|
|
|
|
|
rtype => $rtype, |
182
|
|
|
|
|
|
|
rvalue => $rvalue, |
183
|
|
|
|
|
|
|
ttl => $ttl, |
184
|
|
|
|
|
|
|
mxnum => $mxnum); |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
$dnsbed->modifyRecord($zid, |
187
|
|
|
|
|
|
|
rid => $rid, |
188
|
|
|
|
|
|
|
rname => $rname, |
189
|
|
|
|
|
|
|
rtype => $rtype, |
190
|
|
|
|
|
|
|
rvalue => $rvalue, |
191
|
|
|
|
|
|
|
ttl => $ttl, |
192
|
|
|
|
|
|
|
mxnum => $mxnum); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
$dnsbed->delRecord($zid,rid => $rid); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
$dnsbed->listRecords($zid); |
197
|
|
|
|
|
|
|
$dnsbed->listRecords($zid,rid => $rid); |
198
|
|
|
|
|
|
|
$dnsbed->listRecords($zid,rids => $rids); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$dnsbed->searchRecords($zid,keyword => $keyword); |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 METHODS |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 new(uid,token) |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
Initialize the object. You should be able to get your UID and token from DNSbed.com |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head2 addZone(zone) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
The argument is the valid zone name, i.e, google.com, but not www.google.com |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
For the result of this method and all the methods below, just Data::Dumper it. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
use Data::Dumper; |
216
|
|
|
|
|
|
|
my $res = $dnsbed->addZone($zone); |
217
|
|
|
|
|
|
|
print Dumper $res; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 listZones() |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
use Data::Dumper; |
222
|
|
|
|
|
|
|
my $res = $dnsbed->listZones; # or |
223
|
|
|
|
|
|
|
my $res = $dnsbed->listZones($zid); |
224
|
|
|
|
|
|
|
print Dumper $res; |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head2 checkZone(zone) |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
use Data::Dumper; |
229
|
|
|
|
|
|
|
my $res = $dnsbed->checkZone($zone); |
230
|
|
|
|
|
|
|
print Dumper $res; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 delZone(zid) |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
The only argument is a valid zone ID. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 addRecord(zid,rr_hash) |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
The first argument is zid, which must be provided. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
The keys in rr_hash must have: |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
rname: the record's name, i.e, www (but not www.example.com) |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
rtype: the record's type, which can be one of these: A, CNAME, AAAA, MX, NS, TXT |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
rvalue: the record's value, it could be an IP address or a hostname, based on the type |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
ttl: the record's TTL, it's a number, i.e, 600 means 600 seconds |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
mxnum: if the record's type is MX, this means MX host's priority, otherwise it's meaningless |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 modifyRecord(zid,rr_hash) |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
The first argument is zid, which must be provided. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
The keys in rr_hash must have: |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
rid: the record's ID with the values you want to modify |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
rname, rtype, rvalue, ttl, mxnum: the new values provided by you |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Notice: after executing this method, the old RID will be lost, with the new record you get a new RID, not the before one. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 delRecord(zid,rr_hash) |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
The first argument is zid, which must be provided. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
The keys in rr_hash must have: |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
rid: the record's ID with the values you want to delete |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 listRecords(zid,optional_rr_hash) |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
The first argument is zid, which must be provided. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
If you don't provide the second argument, it returns all the records for this zone ID. |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
optional_rr_hash could have one of these two keys: |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
rid: if provided, it returns only one record with this rid |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
rids: it could be, i.e, "1,2,3,4", then returns the records with rid 1,2,3 and 4 |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=head2 searchRecords(zid,kw_hash) |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
The first argument is zid, which must be provided. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
The keys in kw_hash must have: |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
keyword: the keyword you want to search with |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
It returns the records whose rname or rvalue have the keyword included. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=head1 SEE ALSO |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
http://www.dnsbed.com/API.pdf |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=head1 AUTHOR |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
Ken Peng |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head1 BUGS/LIMITATIONS |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
If you have found bugs, please send email to |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 SUPPORT |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
perldoc Net::DNSbed |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Copyright 2012 Ken Peng, all rights reserved. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
322
|
|
|
|
|
|
|
it under the same terms as Perl itself. |