EPP/Taeping.pm

filter: Statementstmt 26.9% 31 / 115 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 22 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 66.6% 10 / 15 Podpod 100% 5 / 5 totaltotal 21.1% 46 / 218 SCAR 65.5
CC
34
Cov
17%
new
462.0
make_request
132.0
get_billing_info
6.0
CRAP 700.8
« EPP/TCI.pm ↑ Summary EPP/CNic.pm »
1 package IO::EPP::Taeping;
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 IO::EPP::Taeping
8  
9 =head1 SYNOPSIS
10  
11 use IO::EPP::Taeping;
12  
13 # Parameters for LWP
14 my %sock_params = (
15 PeerHost => 'epp.nic.net.ru',
16 PeerPort => 7080,
17 SSL_key_file => 'key_file.pem',
18 SSL_cert_file => 'cert_file.pem',
19 LocalAddr => '1.2.3.4',
20 Timeout => 30,
21 );
22  
23 # Create object, get greeting and call login()
24 my $conn = IO::EPP::Taeping->new( {
25 user => 'XXX-3LVL',
26 pass => 'XXXXXXXX',
27 sock_params => \%sock_params,
28 test_mode => 0, # real connect
29 } );
30  
31 # Check domain
32 my ( $answ, $code, $msg ) = $conn->check_domains( { domains => [ 'my.pp.ru', 'my.org.ru' ] } );
33  
34 # Call logout() and destroy object
35 undef $conn;
36  
37  
38 =head1 DESCRIPTION
39  
40 Module overwrites IO::EPP::RIPN where there are differences
41 and work with tcinet epp using http api
42  
43 Previously 3lvl.ru domains were serviced by TCI, but then were transferred to a separate registry, which has small differences
44  
45 For details see:
46 L<https://nic.net.ru/docs/EPP-3LVL.pdf>
47  
48 All documents -- L<http://pp.ru/documents.html>
49  
50 IO::EPP::Taeping works with .net.ru, .org.ru & .pp.ru only
51  
52 Domain transfer in these zones works as in the .su tld
53  
54 =cut
55  
56 1 ▶use IO::Socket::SSL;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 1 ▶use HTTP::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 1 ▶use Time::HiRes qw( time );
Subroutine BEGIN: called CC=1 SCAR=0.0
61  
62 1 ▶use IO::EPP::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use IO::EPP::RIPN;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 1 ▶use parent qw( IO::EPP::RIPN );
Subroutine BEGIN: called CC=1 SCAR=0.0
65  
66 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69  
70 sub make_request {
71 0 ▶ my ( $action, $params ) = @_;
Subroutine make_request: not called CC=11 SCAR=48.8
Pod documented
72  
73 #$params = IO::EPP::Base::recursive_utf8_unflaged( $params );
74  
75 0 my ( $code, $msg, $answ, $self );
76  
77 0 ▶ unless ( $params->{conn} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'conn'}) { } 0 0 0
78 # Default:
79 0 ▶ $params->{sock_params}{PeerHost} ||= 'epp.nic.net.ru';
Condition0%0/2
$params->{"sock_params"}{"PeerHost"} ||= "epp.nic.net.ru"
l!l
00
MC/DC0%0/1
$params->{"sock_params"}{"PeerHost"} ||= "epp.nic.net.ru"
$params->{"sock_params"}{"PeerHost"}
Truth table0%0/2
A
A= $params->{"sock_params"}{"PeerHost"}
Aresult
11
00
80 0 ▶ $params->{sock_params}{PeerPort} ||= 7080;
Condition0%0/2
$params->{"sock_params"}{"PeerPort"} ||= 7080
l!l
00
MC/DC0%0/1
$params->{"sock_params"}{"PeerPort"} ||= 7080
$params->{"sock_params"}{"PeerPort"}
Truth table0%0/2
A
A= $params->{"sock_params"}{"PeerPort"}
Aresult
11
00
81  
82 0 ( $self, $code, $msg ) = __PACKAGE__->new( $params );
83  
84 0 ▶ unless ( $code and $code == 1000 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code and $code == 1000) 0 0 0
Condition0%0/3
$code and $code == 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$code and $code == 1000
$code $code == 1000
Truth table0%0/3
A and B
A= $codeB= $code == 1000
ABresult
0X0
100
111
85 0 goto END_MR;
86 }
87 }
88 else {
89 0 $self = $params->{conn};
90 }
91  
92 0 $self->{critical_error} = '';
93  
94 0 ▶ if ( $self->can( $action ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can($action)) { } 0 0 0
95 0 ( $answ, $code, $msg ) = $self->$action( $params );
96 }
97 else {
98 0 $msg = "undefined command <$action>, request cancelled";
99 0 $code = 0;
100 }
101  
102 END_MR:
103  
104 0 ▶ $msg .= ', ' . $self->{critical_error} if $self->{critical_error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"critical_error"} 0 0 0
105  
106 0 my $full_answ = "code: $code\nmsg: $msg";
107  
108 0 ▶ $answ = {} unless $answ && ref $answ;
Branch: 1 branch
BranchTrueFalseTotal
unless $answ and ref $answ 0 0 0
Condition0%0/3
$answ and ref $answ
!ll&&!rl&&r
000
MC/DC0%0/2
$answ and ref $answ
$answ ref $answ
Truth table0%0/3
A and B
A= $answB= ref $answ
ABresult
0X0
100
111
109  
110 0 $answ->{code} = $code;
111 0 $answ->{msg} = $msg;
112  
113 0 ▶ return wantarray ? ( $answ, $full_answ, $self ) : $answ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
114 }
115  
116  
117 =head1 METHODS
118  
119 All methods except the ones listed below are completely the same as L<IO::EPP::RIPN>
120  
121 =head2 new
122  
123 Method is rewritten because of verify mode/hostname
124  
125 =cut
126  
127 sub new {
128 0 ▶ my ( $package, $params ) = @_;
Subroutine new: not called CC=21 SCAR=61.4
Pod documented
129  
130 0 my ( $self, $code, $msg );
131  
132 0 my $sock_params = delete $params->{sock_params};
133  
134 0 $sock_params->{SSL_verify_mode} = SSL_VERIFY_NONE; # there are no words
135 0 $sock_params->{verify_hostname} = 0;
136  
137 # Further all as in the RIPN
138  
139 0 my $host = $sock_params->{PeerHost};
140 0 my $port = $sock_params->{PeerPort};
141 0 my $url = "https://$host:$port";
142 0 my $local_address = $sock_params->{LocalAddr};
143 0 ▶ my $timeout = $sock_params->{Timeout} || 5;
Condition0%0/2
$sock_params->{'Timeout'} || 5
l!l
00
MC/DC0%0/1
$sock_params->{'Timeout'} || 5
$sock_params->{'Timeout'}
Truth table0%0/2
A
A= $sock_params->{'Timeout'}
Aresult
11
00
144  
145 0 my %ua_params = ( ssl_opts => $sock_params );
146 0 ▶ $ua_params{local_address} = $local_address if $local_address;
Branch: 1 branch
BranchTrueFalseTotal
if $local_address 0 0 0
147  
148 0 ▶ if ( $timeout ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
149 # LWP feature: first param for LWP, second - for IO::Socket
150 0 $ua_params{timeout} = $timeout;
151 0 $ua_params{Timeout} = $timeout;
152 }
153  
154 0 my $cookie;
155 0 ▶ if ( $params->{alien_conn} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{'alien_conn'}) { } 0 0 0
156 0 $cookie = HTTP::Cookies->new( autosave => 0 );
157  
158 0 ▶ unless ( $cookie->load( $params->{load_cook_from} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cookie->load($params->{"load_cook_from"})) 0 0 0
159 0 $msg = "load cooker is fail";
160 0 $code = 0;
161  
162 0 goto ERR;
163 }
164 }
165 else {
166 0 $cookie = HTTP::Cookies->new;
167 }
168  
169 0 my $ua = LWP::UserAgent->new(
170 agent => 'EppBot/7.02 (Perl; Linux i686; ru, en_US)',
171 parse_head => 0,
172 keep_alive => 30,
173 cookie_jar => $cookie,
174 %ua_params,
175 );
176  
177 0 ▶ unless ( $ua ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
178 0 $msg = "can not connect";
179 0 $code = 0;
180  
181 0 goto ERR;
182 }
183  
184 $self = bless {
185 sock => $ua,
186 user => $params->{user},
187 url => $url,
188 cookies => $cookie,
189 no_logs => delete $params->{no_logs},
190 0 ▶ alien => $params->{alien_conn} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$params->{'alien_conn'} ? : 0 0 0
191 };
192  
193 0 $self->set_urn();
194  
195 0 $self->set_log_vars( $params );
196  
197 0 ▶ if ( $self->{alien} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"alien"}) 0 0 0
198 0 ▶ return wantarray ? ( $self, 1000, 'ok' ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
199 }
200  
201 # Get HEADER only
202 0 $self->epp_log( "HEAD connect to $url from $local_address" );
203  
204 0 my $request = HTTP::Request->new( HEAD => $url ); # не POST
205 0 my $response = $ua->request( $request );
206  
207 0 my $rcode = $response->code;
208 0 $self->epp_log( "header answ code: $rcode" );
209  
210 0 ▶ unless ( $rcode == 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rcode == 200) 0 0 0
211 0 $code = 0;
212 0 $msg = "Can't open socket";
213  
214 0 goto ERR;
215 }
216  
217 0 my $headers = $response->headers;
218  
219 0 my $length = $headers->content_length;
220 0 $self->epp_log( "header content-length == $length" );
221  
222 0 ▶ if ( $length == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length == 0) 0 0 0
223 0 $code = 0;
224 0 $msg = "Can't open socket";
225  
226 0 goto ERR;
227 }
228  
229 0 my ( undef, $c0, $m0 ) = $self->hello();
230  
231 0 ▶ unless ( $c0 && $c0 == 1000 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($c0 and $c0 == 1000) 0 0 0
Condition0%0/3
$c0 and $c0 == 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$c0 and $c0 == 1000
$c0 $c0 == 1000
Truth table0%0/3
A and B
A= $c0B= $c0 == 1000
ABresult
0X0
100
111
232 0 $code = 0;
233 0 $msg = "Can't get greeting";
234 0 ▶ $msg .= '; ' . $self->{critical_error} if $self->{critical_error};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"critical_error"} 0 0 0
235  
236 0 goto ERR;
237 }
238  
239  
240 0 my ( undef, $c1, $m1 ) = $self->login( delete $params->{pass} ); # no password in object
241  
242 0 ▶ if ( $c1 && $c1 == 1000 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c1 and $c1 == 1000) 0 0 0
Condition0%0/3
$c1 and $c1 == 1000
!ll&&!rl&&r
000
MC/DC0%0/2
$c1 and $c1 == 1000
$c1 $c1 == 1000
Truth table0%0/3
A and B
A= $c1B= $c1 == 1000
ABresult
0X0
100
111
243 0 ▶ return wantarray ? ( $self, $c1, $m1 ) : $self;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
244 }
245  
246 0 ▶ $msg = ( $m1 || '' ) . $self->{critical_error};
Condition0%0/2
$m1 || ''
l!l
00
MC/DC0%0/1
$m1 || ''
$m1
Truth table0%0/2
A
A= $m1
Aresult
11
00
247 0 ▶ $code = $c1 || 0;
Condition0%0/2
$c1 || 0
l!l
00
MC/DC0%0/1
$c1 || 0
$c1
Truth table0%0/2
A
A= $c1
Aresult
11
00
248  
249 0 ▶ERR:
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
250 return wantarray ? ( 0, $code, $msg ) : 0;
251 }
252  
253 =head2 get_billing_info, get_limits_info, get_stat_info
254  
255 Not support
256  
257 =cut
258  
259 sub get_billing_info {
260 0 ▶ return wantarray ? ( 0, 0, 'not work' ) : 0;
Subroutine get_billing_info: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
261 }
262  
263  
264 sub get_limits_info {
265 0 ▶ return wantarray ? ( 0, 0, 'not work' ) : 0;
Subroutine get_limits_info: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
266 }
267  
268  
269 sub get_stat_info {
270 0 ▶ return wantarray ? ( 0, 0, 'not work' ) : 0;
Subroutine get_stat_info: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
271 }
272  
273  
274 1 1;
275  
276  
277 __END__
« EPP/TCI.pm ↑ Summary EPP/CNic.pm »