| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Google::reCAPTCHA; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20887
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
25
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
74
|
|
|
7
|
1
|
|
|
1
|
|
1152
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
50681
|
|
|
|
1
|
|
|
|
|
36
|
|
|
8
|
1
|
|
|
1
|
|
1165
|
use JSON qw( decode_json ); |
|
|
1
|
|
|
|
|
13070
|
|
|
|
1
|
|
|
|
|
6
|
|
|
9
|
1
|
|
|
1
|
|
1021
|
use Params::Validate qw( validate SCALAR ); |
|
|
1
|
|
|
|
|
9961
|
|
|
|
1
|
|
|
|
|
93
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use constant URL => 'https://www.google.com/recaptcha/api/siteverify'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
440
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
17
|
|
|
|
|
|
|
my $self = validate( @_, { |
|
18
|
|
|
|
|
|
|
secret => { |
|
19
|
|
|
|
|
|
|
type => SCALAR, |
|
20
|
|
|
|
|
|
|
callbacks => { |
|
21
|
|
|
|
|
|
|
'is a secret key' => |
|
22
|
0
|
|
|
0
|
|
|
sub { $_[0] ne '' } |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
} |
|
25
|
0
|
|
|
|
|
|
} ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
bless $self, $class; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return $self; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub siteverify { |
|
33
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
34
|
|
|
|
|
|
|
my $pd = validate( @_, { |
|
35
|
|
|
|
|
|
|
response => { |
|
36
|
|
|
|
|
|
|
type => SCALAR, |
|
37
|
|
|
|
|
|
|
callbacks => { |
|
38
|
|
|
|
|
|
|
'is a response code' => |
|
39
|
0
|
|
|
0
|
|
|
sub { $_[0] ne '' } |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
remoteip => { |
|
43
|
|
|
|
|
|
|
type => SCALAR, |
|
44
|
|
|
|
|
|
|
optional => 1, |
|
45
|
|
|
|
|
|
|
callbacks => { |
|
46
|
|
|
|
|
|
|
'is a remote ipv4 address' => |
|
47
|
0
|
|
|
0
|
|
|
sub { $_[0] =~ /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ } |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
}, |
|
50
|
0
|
|
|
|
|
|
} ); |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$pd->{secret} = $self->{secret}; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
|
55
|
0
|
|
|
|
|
|
$ua->ssl_opts( verify_hostname => 0 ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $response = $ua->post( URL , $pd ); |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ( $response->is_success) { |
|
60
|
0
|
|
|
|
|
|
my $data = decode_json( $response->decoded_content ); |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ( exists ( $data->{'error-codes'} ) ) { |
|
63
|
0
|
|
|
|
|
|
croak( 'API Error: ' . join( ', ', @{ $data->{'error-codes'} } ) ); |
|
|
0
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
return $data->{success} ? 1 : 0; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
else { |
|
69
|
0
|
0
|
|
|
|
|
my $content = $response->decoded_content ? $response->decoded_content : ''; |
|
70
|
0
|
|
|
|
|
|
my $message = 'HTTP Request failed with status ' . $response->code . ' : ' . $content; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
croak( $message ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
|
77
|
|
|
|
|
|
|
__END__ |