| 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 | 2 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_upload: called CC=11 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | Carp::croak "Specified captcha file doesn't exist" | ||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | if defined($opts{file}) && ! -e $opts{file}; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $opts{"file"} and not -e $opts{"file"}
MC/DC0%0/2
defined $opts{"file"} and not -e $opts{"file"}
defined $opts{"file"}
not -e $opts{"file"}
Truth table66%2/3
A and not(B)
A= defined $opts{"file"}B= not -e $opts{"file"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my $file; | |||||||||||||||||||||||||||||||||||||||||||
| 34 | my $response = $self->{ua}->post | ||||||||||||||||||||||||||||||||||||||||||||
| 35 | ( | ||||||||||||||||||||||||||||||||||||||||||||
| 36 | "$self->{scheme}://$self->{subdomain}$self->{domain}/in.php", | ||||||||||||||||||||||||||||||||||||||||||||
| 37 | defined $opts{file} || defined $opts{content} | ||||||||||||||||||||||||||||||||||||||||||||
| 38 | ? ( | ||||||||||||||||||||||||||||||||||||||||||||
| 39 | Content_Type => "form-data", | ||||||||||||||||||||||||||||||||||||||||||||
| 40 | Content => | ||||||||||||||||||||||||||||||||||||||||||||
| 41 | [ | ||||||||||||||||||||||||||||||||||||||||||||
| 42 | key => $self->{key}, | ||||||||||||||||||||||||||||||||||||||||||||
| 43 | method => 'post', | ||||||||||||||||||||||||||||||||||||||||||||
| 44 | file => | ||||||||||||||||||||||||||||||||||||||||||||
| 45 | [ | ||||||||||||||||||||||||||||||||||||||||||||
| 46 | defined($opts{file}) ? | ||||||||||||||||||||||||||||||||||||||||||||
| 47 | ( | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | $file = delete $opts{file}, | ||||||||||||||||||||||||||||||||||||||||||||
| 49 | defined($opts{name}) ? | ||||||||||||||||||||||||||||||||||||||||||||
| 50 | delete $opts{name} | ||||||||||||||||||||||||||||||||||||||||||||
| 51 | : | ||||||||||||||||||||||||||||||||||||||||||||
| 52 | $file !~ /\..{1,5}$/ ? # filename without extension | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | $self->_name_by_file_signature($file) | ||||||||||||||||||||||||||||||||||||||||||||
| 54 | : | ||||||||||||||||||||||||||||||||||||||||||||
| 55 | undef | ||||||||||||||||||||||||||||||||||||||||||||
| 56 | ) | ||||||||||||||||||||||||||||||||||||||||||||
| 57 | : | ||||||||||||||||||||||||||||||||||||||||||||
| 58 | ( | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | undef, | ||||||||||||||||||||||||||||||||||||||||||||
| 60 | defined($opts{name}) ? | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | delete $opts{name} | ||||||||||||||||||||||||||||||||||||||||||||
| 62 | : | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | $self->_name_by_signature($opts{content}), | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | Content => delete $opts{content} | ||||||||||||||||||||||||||||||||||||||||||||
| 65 | ) | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | ], | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%2/3
defined $opts{"file"} or defined $opts{"content"}
MC/DC50%1/2
defined $opts{"file"} or defined $opts{"content"}
defined $opts{"file"}
defined $opts{"content"}
Truth table66%2/3
A or B
A= defined $opts{"file"}B= defined $opts{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 67 | %opts | ||||||||||||||||||||||||||||||||||||||||||||
| 68 | ] | ||||||||||||||||||||||||||||||||||||||||||||
| 69 | ) | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | : \%opts | ||||||||||||||||||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $captcha_id; | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | ▶ | unless(($captcha_id) = $response->content =~ /OK\|(\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | return $self->{last_captcha_id} = $captcha_id; | |||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub try_recognize { | ||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_recognize: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | Carp::croak "Captcha id should be specified" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=get&id=$id"); | |||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my $captcha_text; | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | unless(($captcha_text) = $response->content =~ /OK\|(.+)/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | return $captcha_text; | |||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | sub abuse { | ||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abuse: called CC=4 SCAR=14.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | ▶ | Carp::croak "Captcha id should be specified" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=reportbad&id=$id"); | |||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | unless($response->content eq 'OK_REPORT_RECORDED') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | sub balance { | ||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
balance: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my $response = $self->{ua}->get("$self->{scheme}://$self->{subdomain}$self->{domain}/res.php?key=$self->{key}&action=getbalance"); | |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | unless($response->is_success) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->{errno} = 'HTTP_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $self->{errstr} = $response->status_line; | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | if($response->content =~ /^ERROR_/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | $self->{errno} = $response->content; | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 1 | $self->{errstr} = $MESSAGES{ $self->{errno} }; | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | return undef; | |||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | return $response->content; | |||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||