File Coverage

blib/lib/IO/EPP/Taeping.pm
Criterion Covered Total %
statement 30 114 26.3
branch 0 48 0.0
condition 0 22 0.0
subroutine 10 15 66.6
pod 5 5 100.0
total 45 204 22.0


line stmt bran cond sub pod time code
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 => [ 'org.info' ] } );
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
47              
48             All documents -- L
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     1   2163 use IO::Socket::SSL;
  1         65288  
  1         7  
57 1     1   671 use LWP::UserAgent;
  1         37534  
  1         31  
58 1     1   7 use HTTP::Request;
  1         2  
  1         20  
59 1     1   403 use HTTP::Cookies;
  1         5614  
  1         27  
60 1     1   394 use Time::HiRes qw( time );
  1         1096  
  1         6  
61              
62 1     1   748 use IO::EPP::Base;
  1         2  
  1         41  
63 1     1   438 use IO::EPP::RIPN;
  1         2  
  1         33  
64 1     1   6 use parent qw( IO::EPP::RIPN );
  1         2  
  1         4  
65              
66 1     1   58 use strict;
  1         2  
  1         17  
67 1     1   4 use warnings;
  1         2  
  1         677  
68              
69              
70             sub make_request {
71 0     0 1   my ( $action, $params ) = @_;
72              
73             #$params = IO::EPP::Base::recursive_utf8_unflaged( $params );
74              
75 0           my ( $code, $msg, $answ, $self );
76              
77 0 0         unless ( $params->{conn} ) {
78             # Default:
79 0   0       $params->{sock_params}{PeerHost} ||= 'epp.nic.net.ru';
80 0   0       $params->{sock_params}{PeerPort} ||= 7080;
81              
82 0           ( $self, $code, $msg ) = __PACKAGE__->new( $params );
83              
84 0 0 0       unless ( $code and $code == 1000 ) {
85 0           goto END_MR;
86             }
87             }
88             else {
89 0           $self = $params->{conn};
90             }
91              
92 0           $self->{critical_error} = '';
93              
94 0 0         if ( $self->can( $action ) ) {
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 0         $msg .= ', ' . $self->{critical_error} if $self->{critical_error};
105              
106 0           my $full_answ = "code: $code\nmsg: $msg";
107              
108 0 0 0       $answ = {} unless $answ && ref $answ;
109              
110 0           $answ->{code} = $code;
111 0           $answ->{msg} = $msg;
112              
113 0 0         return wantarray ? ( $answ, $full_answ, $self ) : $answ;
114             }
115              
116              
117             =head1 METHODS
118              
119             =head2 new
120              
121             Method is rewritten because of verify mode/hostname
122              
123             =cut
124              
125             sub new {
126 0     0 1   my ( $package, $params ) = @_;
127              
128 0           my ( $self, $code, $msg );
129              
130 0           my $sock_params = delete $params->{sock_params};
131              
132 0           $sock_params->{SSL_verify_mode} = SSL_VERIFY_NONE; # there are no words
133 0           $sock_params->{verify_hostname} = 0;
134              
135             # Further all as in the RIPN
136              
137 0           my $host = $sock_params->{PeerHost};
138 0           my $port = $sock_params->{PeerPort};
139 0           my $url = "https://$host:$port";
140 0           my $local_address = $sock_params->{LocalAddr};
141 0   0       my $timeout = $sock_params->{Timeout} || 5;
142              
143 0           my %ua_params = ( ssl_opts => $sock_params );
144 0 0         $ua_params{local_address} = $local_address if $local_address;
145              
146 0 0         if ( $timeout ) {
147             # LWP feature: first param for LWP, second - for IO::Socket
148 0           $ua_params{timeout} = $timeout;
149 0           $ua_params{Timeout} = $timeout;
150             }
151              
152 0           my $cookie;
153 0 0         if ( $params->{alien_conn} ) {
154 0           $cookie = HTTP::Cookies->new( autosave => 0 );
155              
156 0 0         unless ( $cookie->load( $params->{load_cook_from} ) ) {
157 0           $msg = "load cooker is fail";
158 0           $code = 0;
159              
160 0           goto ERR;
161             }
162             }
163             else {
164 0           $cookie = HTTP::Cookies->new;
165             }
166              
167 0           my $ua = LWP::UserAgent->new(
168             agent => 'EppBot/7.02 (Perl; Linux i686; ru, en_US)',
169             parse_head => 0,
170             keep_alive => 30,
171             cookie_jar => $cookie,
172             %ua_params,
173             );
174              
175 0 0         unless ( $ua ) {
176 0           $msg = "can not connect";
177 0           $code = 0;
178              
179 0           goto ERR;
180             }
181              
182             $self = bless {
183             sock => $ua,
184             user => $params->{user},
185             url => $url,
186             cookies => $cookie,
187             no_logs => delete $params->{no_logs},
188 0 0         alien => $params->{alien_conn} ? 1 : 0,
189             };
190              
191 0           $self->set_urn();
192              
193 0           $self->set_log_vars( $params );
194              
195 0 0         if ( $self->{alien} ) {
196 0 0         return wantarray ? ( $self, 1000, 'ok' ) : $self;
197             }
198              
199             # Get HEADER only
200 0           $self->epp_log( "HEAD connect to $url from $local_address" );
201              
202 0           my $request = HTTP::Request->new( HEAD => $url ); # не POST
203 0           my $response = $ua->request( $request );
204              
205 0           my $rcode = $response->code;
206 0           $self->epp_log( "header answ code: $rcode" );
207              
208 0 0         unless ( $rcode == 200 ) {
209 0           $code = 0;
210 0           $msg = "Can't open socket";
211              
212 0           goto ERR;
213             }
214              
215 0           my $headers = $response->headers;
216              
217 0           my $length = $headers->content_length;
218 0           $self->epp_log( "header content-length == $length" );
219              
220 0 0         if ( $length == 0 ) {
221 0           $code = 0;
222 0           $msg = "Can't open socket";
223              
224 0           goto ERR;
225             }
226              
227 0           my ( undef, $c0, $m0 ) = $self->hello();
228              
229 0 0 0       unless ( $c0 && $c0 == 1000 ) {
230 0           $code = 0;
231 0           $msg = "Can't get greeting";
232 0 0         $msg .= '; ' . $self->{critical_error} if $self->{critical_error};
233              
234 0           goto ERR;
235             }
236              
237              
238 0           my ( undef, $c1, $m1 ) = $self->login( delete $params->{pass} ); # no password in object
239              
240 0 0 0       if ( $c1 && $c1 == 1000 ) {
241 0 0         return wantarray ? ( $self, $c1, $m1 ) : $self;
242             }
243              
244 0   0       $msg = ( $m1 || '' ) . $self->{critical_error};
245 0   0       $code = $c1 || 0;
246              
247 0 0         ERR:
248             return wantarray ? ( 0, $code, $msg ) : 0;
249             }
250              
251             =head2 get_billing_info, get_limits_info, get_stat_info
252              
253             Not support
254              
255             =cut
256              
257             sub get_billing_info {
258 0 0   0 1   return wantarray ? ( 0, 0, 'not work' ) : 0;
259             }
260              
261              
262             sub get_limits_info {
263 0 0   0 1   return wantarray ? ( 0, 0, 'not work' ) : 0;
264             }
265              
266              
267             sub get_stat_info {
268 0 0   0 1   return wantarray ? ( 0, 0, 'not work' ) : 0;
269             }
270              
271              
272             1;
273              
274              
275             __END__