| 1 | package Mailru::Cloud::Auth; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use open qw(:std :utf8); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use JSON::XS; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $ua = LWP::UserAgent->new ( | |||||||||||||||||||||||||||||||||||||||||
| 20 | agent => 'Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | cookie_jar => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $self->{ua} = $ua; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | sub login { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | my ($self, %opt) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: called CC=9 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | $self->{login} = $opt{-login} || $self->{login} || croak "You must specify -login opt for 'login' method"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$opt{'-login'} || $self->{'login'} || croak(q[You must specify -login opt for 'login' method])
$opt{"-login"} or $self->{"login"}
MC/DC0%0/3
$opt{'-login'} || $self->{'login'} || croak(q[You must specify -login opt for 'login' method])
$opt{"-login"}
$self->{"login"}
croak(q[You must specify -login opt for 'login' method])
Truth table25%1/4
A or B || C
A= $opt{"-login"}B= $self->{"login"}C= croak(q[You must specify -login opt for 'login' method])
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | $self->{password} = $opt{-password} || $self->{password} || croak "You must specify -password opt for 'login' method"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$opt{'-password'} || $self->{'password'} || croak(q[You must specify -password opt for 'login' method])
$opt{"-password"} or $self->{"password"}
MC/DC0%0/3
$opt{'-password'} || $self->{'password'} || croak(q[You must specify -password opt for 'login' method])
$opt{"-password"}
$self->{"password"}
croak(q[You must specify -password opt for 'login' method])
Truth table25%1/4
A or B || C
A= $opt{"-password"}B= $self->{"password"}C= croak(q[You must specify -password opt for 'login' method])
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $ua = $self->{ua}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my %param; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | $param{Domain} = 'mail.ru'; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $param{FailPage} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $param{Login} = $self->{login}; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $param{Password} = $self->{password}; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $param{new_auth_form} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $param{page} ='https://cloud.mail.ru/?from=promo'; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 1 | $param{saveauth} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $res = $ua->post('https://auth.mail.ru/cgi-bin/auth?lang=ru_RU&from=authpopup', \%param); | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ($code eq '302' || $code eq '301' || $code eq '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$code eq 302 or $code eq 301 or $code eq 200
$code eq 302 or $code eq 301
MC/DC0%0/3
$code eq 302 or $code eq 301 or $code eq 200
$code eq 302
$code eq 301
$code eq 200
Truth table25%1/4
A or B or C
A= $code eq 302B= $code eq 301C= $code eq 200
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | $self->__getToken() or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | return $self->{authToken}; | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub __getToken { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__getToken: called CC=6 SCAR=31.6
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $ua = $self->{ua}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $res = $ua->get('https://cloud.mail.ru/?from=promo&from=authpopup'); | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ($res->is_success) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $content = $res->decoded_content; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($content =~ /"csrf":"(.+?)"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->{authToken} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($content =~ /"email":"(.+?)"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $self->{email} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | #Get BUILD | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{build} = 'hotfix_CLOUDWEB-7726_50-0-3.201710311503'; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($content =~ /"BUILD":"(.+?)"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $self->{build} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | #Get x-page-id | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $self->{'x-page-id'} = 'f9jfLFeHA5'; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($content =~ /"x-page-id":"(.+?)"/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->{'x-page-id'} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | #Parse free space info | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->{info} = __parseInfo(\$content); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | sub info { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($self->{info}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my %info = map {$_, $self->{info}->{$_}} keys %{$self->{info}}; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return \%info; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | sub __parseInfo { | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $content = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__parseInfo: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my %info = ( | |||||||||||||||||||||||||||||||||||||||||
| 99 | 'used_space' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 'total_space' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 'file_size_limit' => '', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($$content =~ /"space":[{].+?"used":(.+?),"total":(.+?)[}]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $info{used_space} = $1 * 1024 * 1024; # To bytes from Mbytes | |||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $info{total_space} = $2 * 1024 * 1024; # To bytes from Mbytes | |||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($$content =~ /"file_size_limit":(.+?),/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $info{file_size_limit} = $1; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return \%info; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | sub __isLogin { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__isLogin: called CC=5 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | if ($self->{authToken}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $ua = $self->{ua}; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $res = $ua->get('https://auth.mail.ru/cgi-bin/auth?mac=1&Login=' . uri_escape($self->{login})); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($code ne '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | croak "Can't get status about login"; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $json_res = decode_json($res->content); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $json_res->{status} eq 'ok' and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | $self->login() and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | croak "Not logined"; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | __END__ | ||||||||||||||||||||||||||||||||||||||||||