| 1 | package WebService::Antigate::V1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use parent 'WebService::Antigate'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | my %MESSAGES = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 'ERROR_KEY_DOES_NOT_EXIST' => 'wrong service key used', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 'ERROR_WRONG_USER_KEY' => 'wrong service key used', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 'ERROR_NO_SLOT_AVAILABLE' => 'all recognizers are busy, try later', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 'ERROR_ZERO_CAPTCHA_FILESIZE' => 'uploaded captcha size is zero', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 'ERROR_TOO_BIG_CAPTCHA_FILESIZE' => 'uploaded captcha size is grater than 90 Kb', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 'ERROR_WRONG_FILE_EXTENSION' => 'wrong extension of the uploaded captcha, allowed extensions are gif, jpg, png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 'ERROR_IP_NOT_ALLOWED' => 'this ip not allowed to use this account', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 'ERROR_WRONG_ID_FORMAT' => 'captcha id should be number', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 'ERROR_NO_SUCH_CAPCHA_ID' => 'no such captcha id in the database', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 'ERROR_URL_METHOD_FORBIDDEN' => 'this upload method is already not supported', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 'ERROR_IMAGE_IS_NOT_PNG' => 'captcha is not correct png file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 'ERROR_IMAGE_IS_NOT_JPEG' => 'captcha is not correct jpeg file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 'ERROR_IMAGE_IS_NOT_GIF' => 'captcha is not correct gif file', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 'ERROR_ZERO_BALANCE' => 'you have a zero balance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 'CAPCHA_NOT_READY' => 'captcha is not recognized yet', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 'OK_REPORT_RECORDED' => 'your abuse recorded', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 'ERROR_CAPTCHA_UNSOLVABLE' => 'captcha can\'t be recognized', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 'ERROR_BAD_DUPLICATES' => 'captcha duplicates limit reached' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub try_upload { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_upload: called CC=11 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Carp::croak "Captcha file or content should be specified and exists" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | if (!defined($opts{file}) && !defined($opts{content})) || (defined($opts{file}) && ! -e $opts{file}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $opts{"file"} || defined $opts{"content"} or defined $opts{"file"} and not -e $opts{"file"}
defined $opts{'file'} || defined $opts{'content'}
defined $opts{"file"} and not -e $opts{"file"}
MC/DC0%0/4
not defined $opts{"file"} || defined $opts{"content"} or defined $opts{"file"} and not -e $opts{"file"}
defined $opts{'file'}
defined $opts{'content'}
defined $opts{"file"}
not -e $opts{"file"}
Truth table14%1/7
not(A || B) or C and not(D)
A= defined $opts{'file'}B= defined $opts{'content'}C= defined $opts{"file"}D= not -e $opts{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $file; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | my $response = $self->{ua}->post | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | "$self->{scheme}://$self->{subdomain}$self->{domain}/in.php", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | Content_Type => "form-data", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | Content => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | key => $self->{key}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | method => 'post', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | file => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | defined($opts{file}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | $file = delete $opts{file}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | defined($opts{name}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | delete $opts{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | $file !~ /\..{1,5}$/ ? # filename without extension | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | $self->_name_by_file_signature($file) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | defined($opts{name}) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | delete $opts{name} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | $self->_name_by_signature($opts{content}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | Content => delete $opts{content} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | ▶ | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | %opts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | my $captcha_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | unless(($captcha_id) = $response->content =~ /OK\|(\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | return $self->{last_captcha_id} = $captcha_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | sub try_recognize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_recognize: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 2 | ▶ | Carp::croak "Captcha id should be specified" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=get&id=$id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my $captcha_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | unless(($captcha_text) = $response->content =~ /OK\|(.+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | return $captcha_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | sub abuse { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abuse: called CC=4 SCAR=14.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | Carp::croak "Captcha id should be specified" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=reportbad&id=$id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | ▶ | unless($response->content eq 'OK_REPORT_RECORDED') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | sub balance { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
balance: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=getbalance"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | if($response->content =~ /^ERROR_/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | return $response->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||