line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::DNS::ValueDomain::DDNS; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
141283
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
4
|
2
|
|
|
2
|
|
11
|
use base qw/Class::Accessor::Fast Class::ErrorHandler/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3159
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9535
|
use Carp; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
195
|
|
7
|
2
|
|
|
2
|
|
1753
|
use Readonly; |
|
2
|
|
|
|
|
6566
|
|
|
2
|
|
|
|
|
117
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
2260
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
126550
|
|
|
2
|
|
|
|
|
69
|
|
10
|
2
|
|
|
2
|
|
2094
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
4380
|
|
|
2
|
|
|
|
|
1300
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Readonly::Scalar my $URL => 'dyn.value-domain.com/cgi-bin/dyn.fcg'; |
15
|
|
|
|
|
|
|
Readonly::Scalar my $SSL_PREFIX => 'ss1.xrea.com'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ua/); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Net::DNS::ValueDomain::DDNS - Update your Value-Domain (https://www.value-domain.com/) DynamicDNS records. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use Net::DNS::ValueDomain::DDNS; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Normal usage |
28
|
|
|
|
|
|
|
my $ddns = Net::DNS::ValueDomain::DDNS->new; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$ddns->update( |
31
|
|
|
|
|
|
|
domain => 'example.com', |
32
|
|
|
|
|
|
|
password => '1234', |
33
|
|
|
|
|
|
|
host => 'www', |
34
|
|
|
|
|
|
|
ip => '127.0.0.1', |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# Update multiple hosts on same IP |
38
|
|
|
|
|
|
|
my $ddns = Net::DNS::ValueDomain::DDNS->new( |
39
|
|
|
|
|
|
|
domain => 'example.com', |
40
|
|
|
|
|
|
|
password => '1234', |
41
|
|
|
|
|
|
|
ip => '127.0.0.1', |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
for my $host (qw/www mail */) { |
45
|
|
|
|
|
|
|
$ddns->update( host => $host ) or die $ddns->errstr; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 DESCRIPTION |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
This module help you to update your Value-Domain (https://www.value-domain.com/) DynamicDNS record(s). |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 METHODS |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 new( %config | \%config ) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Create a new Object. All %config keys and values (except 'host' and 'domain') is kept and reused by update() function. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
61
|
1
|
|
|
1
|
1
|
2959
|
my $class = shift; |
62
|
1
|
50
|
|
|
|
5
|
my $config = @_ > 1 ? {@_} : $_[0]; |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
5
|
my $self = bless {}, $class; |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
6
|
$self->config($config) if $config; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
4
|
if ( !$self->config->{use_https} ) { |
69
|
1
|
|
|
|
|
3
|
eval { require Crypt::SSLeay; }; |
|
1
|
|
|
|
|
951
|
|
70
|
1
|
50
|
|
|
|
3624
|
if ($@) { |
71
|
0
|
|
|
|
|
0
|
carp |
72
|
|
|
|
|
|
|
"Require Crypt::SSLeay for ssl connection. If you don't want to do that, try new( use_https => 0 )."; |
73
|
0
|
|
|
|
|
0
|
$self->config->{use_https} = 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
12
|
$self->ua( LWP::UserAgent->new ); |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
20
|
$self; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 config( %config | \%config ) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
set config veriables |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub config { |
89
|
10
|
|
|
10
|
1
|
385
|
my $self = shift; |
90
|
10
|
50
|
|
|
|
24
|
my $config = @_ > 1 ? {@_} : $_[0]; |
91
|
|
|
|
|
|
|
|
92
|
10
|
|
100
|
|
|
85
|
$self->{_config} ||= {}; |
93
|
|
|
|
|
|
|
|
94
|
10
|
100
|
|
|
|
27
|
if ($config) { |
95
|
5
|
|
|
|
|
13
|
map { $self->{_config}->{$_} = $config->{$_} } keys %$config; |
|
13
|
|
|
|
|
37
|
|
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
10
|
|
|
|
|
28
|
$self->{_config}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head2 protocol |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
return used protocol name. 'http' or 'https' |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub protocol { |
108
|
0
|
0
|
|
0
|
1
|
0
|
shift->config->{use_https} ? 'https' : 'http'; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 update( %config | \%config ) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Update your DynamicDNS record. %config parameters are: |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over 4 |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
C - Domain name being updated. (Required) |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
C - Value-Domain Dynamic DNS Password. (Required) |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
C - Sub-domain name being updated. For example if your hostname is "www.example.com" you should set "www" here. (Optional) |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
C - The IP address to be updated. if empty, your current ip is used. (Optional) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=back |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
If something error has be occurred, return undef. Use errstr() method to get error message. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub update { |
132
|
6
|
|
|
6
|
1
|
2565
|
my $self = shift; |
133
|
6
|
100
|
|
|
|
23
|
my $args = @_ > 1 ? {@_} : $_[0]; |
134
|
|
|
|
|
|
|
|
135
|
6
|
|
|
|
|
17
|
my $config = $self->config($args); |
136
|
|
|
|
|
|
|
|
137
|
6
|
100
|
|
|
|
262
|
croak 'domain is required' unless $config->{domain}; |
138
|
5
|
100
|
|
|
|
170
|
croak 'password is required' unless $config->{password}; |
139
|
|
|
|
|
|
|
|
140
|
4
|
50
|
|
|
|
13
|
my $url = |
141
|
|
|
|
|
|
|
( $config->{use_https} ) |
142
|
|
|
|
|
|
|
? "https://$SSL_PREFIX/$URL" |
143
|
|
|
|
|
|
|
: "http://$URL"; |
144
|
|
|
|
|
|
|
|
145
|
4
|
|
100
|
|
|
39
|
my $parameters = { |
|
|
|
100
|
|
|
|
|
146
|
|
|
|
|
|
|
d => $config->{domain}, |
147
|
|
|
|
|
|
|
p => $config->{password}, |
148
|
|
|
|
|
|
|
h => $config->{host} || q{}, |
149
|
|
|
|
|
|
|
i => $config->{ip} || q{}, |
150
|
|
|
|
|
|
|
}; |
151
|
4
|
|
|
|
|
5
|
my $query = '?'; |
152
|
4
|
|
|
|
|
16
|
while ( my ( $k, $v ) = each %$parameters ) { |
153
|
16
|
|
|
|
|
106
|
$query .= "$k=$v&",; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
15
|
my $res = $self->ua->get( $url . $query ); |
157
|
|
|
|
|
|
|
|
158
|
4
|
50
|
|
|
|
58
|
unless ( $res->is_success ) { |
159
|
0
|
|
|
|
|
0
|
$self->error( $res->status_line ); |
160
|
0
|
|
|
|
|
0
|
return; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
4
|
100
|
|
|
|
40
|
unless ( $res->content =~ /status=0/ ) { |
164
|
1
|
|
|
|
|
17
|
my $error = $res->content; |
165
|
1
|
|
|
|
|
12
|
chomp $error; |
166
|
1
|
|
|
|
|
9
|
$self->error($error); |
167
|
1
|
|
|
|
|
14
|
return; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
3
|
|
|
|
|
39
|
1; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 errstr() |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
return last error. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 ACCESSORS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 ua |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
L object. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 AUTHOR |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Daisuke Murase, Etypester@cpan.orgE |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 LICENSE |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
190
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
1; |