line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package iRedAdmin; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13660
|
use Moo; |
|
1
|
|
|
|
|
9180
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
1560
|
use Email::Valid; |
|
1
|
|
|
|
|
83512
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
6
|
use Encode; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
65
|
|
6
|
1
|
|
|
1
|
|
636
|
use WWW::Mechanize; |
|
1
|
|
|
|
|
87476
|
|
|
1
|
|
|
|
|
34
|
|
7
|
1
|
|
|
1
|
|
484
|
use HTTP::Cookies; |
|
1
|
|
|
|
|
4801
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
367
|
use iRedAdmin::Admin; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
328
|
use iRedAdmin::Domain; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
10
|
1
|
|
|
1
|
|
321
|
use iRedAdmin::User; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
750
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'url' => ( |
15
|
|
|
|
|
|
|
is => 'ro', |
16
|
|
|
|
|
|
|
isa => sub { |
17
|
|
|
|
|
|
|
my $url = $_[0]; |
18
|
|
|
|
|
|
|
$url =~ s/^https?:\/\///; |
19
|
|
|
|
|
|
|
$url =~ s/\/.*$//; |
20
|
|
|
|
|
|
|
die "Domain is invalid! $url" unless Email::Valid->address('domain@'.$url) |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'username' => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
isa => sub { |
27
|
|
|
|
|
|
|
die "Username is invalid!" unless Email::Valid->address($_[0]) |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has 'password' => ( |
32
|
|
|
|
|
|
|
is => 'ro', |
33
|
|
|
|
|
|
|
isa => sub { |
34
|
|
|
|
|
|
|
die "Password this empty!" unless $_[0] =~ /.{1,}/ |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has 'cookie' => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
isa => sub { |
41
|
|
|
|
|
|
|
die "Cookie this empty!" unless $_[0] =~ /.{1,}/ |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
has 'lang' => ( |
46
|
|
|
|
|
|
|
is => 'ro', |
47
|
|
|
|
|
|
|
default => sub { |
48
|
|
|
|
|
|
|
'en_US' |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
has 'mech' => (is => 'ro', writer => 'set_mech'); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has 'error' => (is => 'ro', writer => 'set_error'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub BUILD { |
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $cookie_jar = HTTP::Cookies->new( |
60
|
|
|
|
|
|
|
file => $self->cookie, |
61
|
|
|
|
|
|
|
ignore_discard => 1, |
62
|
|
|
|
|
|
|
autosave => 1 |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new( |
66
|
|
|
|
|
|
|
autocheck => 0, |
67
|
|
|
|
|
|
|
cookie_jar => $cookie_jar, |
68
|
|
|
|
|
|
|
ssl_opts => { |
69
|
|
|
|
|
|
|
verify_hostname => 0 |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->set_mech($mech); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if (-e $self->cookie) { |
76
|
0
|
|
|
|
|
|
my $result = undef; |
77
|
0
|
0
|
|
|
|
|
open FILE, '<', $self->cookie or die $!; |
78
|
0
|
|
|
|
|
|
while () { |
79
|
0
|
|
|
|
|
|
chomp; |
80
|
0
|
0
|
|
|
|
|
$result = $_ unless $result; |
81
|
|
|
|
|
|
|
} |
82
|
0
|
|
|
|
|
|
close FILE; |
83
|
0
|
0
|
|
|
|
|
$result =~ s/\s//g if $result; |
84
|
0
|
0
|
|
|
|
|
unless($result){ |
85
|
0
|
|
|
|
|
|
$self->_connect; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
}else{ |
88
|
0
|
|
|
|
|
|
$self->_connect; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _connect { |
93
|
0
|
|
|
0
|
|
|
my $self = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
$self->mech->post($self->_address . '/login', |
96
|
|
|
|
|
|
|
[ |
97
|
|
|
|
|
|
|
username => $self->username, |
98
|
|
|
|
|
|
|
password => $self->password, |
99
|
|
|
|
|
|
|
login => 'Login', |
100
|
|
|
|
|
|
|
lang => $self->_lang($self->lang), |
101
|
|
|
|
|
|
|
save_pass => 'yes' |
102
|
|
|
|
|
|
|
] |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if($self->mech->content =~ /login_form/){ |
106
|
0
|
|
|
|
|
|
$self->mech->content =~ m! (.*?)!i; |
107
|
0
|
|
|
|
|
|
$self->set_error(encode('utf-8', $1)); |
108
|
0
|
|
|
|
|
|
return 0; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return 2; |
112
|
|
|
|
|
|
|
}; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _success { |
115
|
0
|
|
|
0
|
|
|
my $self = shift; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if($self->mech->content =~ /login_form/){ |
|
|
0
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$self->_connect; |
119
|
|
|
|
|
|
|
}elsif($self->mech->content =~ /error/i) { |
120
|
0
|
|
|
|
|
|
$self->mech->content =~ m! (.*?)!i; |
121
|
0
|
|
|
|
|
|
$self->set_error(encode('utf-8', $1)); |
122
|
0
|
|
|
|
|
|
return 0; |
123
|
|
|
|
|
|
|
}else{ |
124
|
0
|
|
|
|
|
|
return 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _address { |
129
|
0
|
|
|
0
|
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $url = $self->url; |
132
|
0
|
|
|
|
|
|
$url =~ s/\/$//; |
133
|
0
|
|
|
|
|
|
return $url; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _lang { |
137
|
0
|
|
|
0
|
|
|
my ($self, $value) = @_; |
138
|
|
|
|
|
|
|
|
139
|
0
|
|
|
|
|
|
my @lang = qw/ |
140
|
|
|
|
|
|
|
cs_CZ |
141
|
|
|
|
|
|
|
de_DE |
142
|
|
|
|
|
|
|
en_US |
143
|
|
|
|
|
|
|
es_ES |
144
|
|
|
|
|
|
|
fi_FI |
145
|
|
|
|
|
|
|
fr_FR |
146
|
|
|
|
|
|
|
hu_HU |
147
|
|
|
|
|
|
|
it_IT |
148
|
|
|
|
|
|
|
ko_KR |
149
|
|
|
|
|
|
|
nl_NL |
150
|
|
|
|
|
|
|
pl_PL |
151
|
|
|
|
|
|
|
pt_BR |
152
|
|
|
|
|
|
|
ru_RU |
153
|
|
|
|
|
|
|
sl_SI |
154
|
|
|
|
|
|
|
zh_CN |
155
|
|
|
|
|
|
|
zh_TW |
156
|
|
|
|
|
|
|
/; |
157
|
|
|
|
|
|
|
|
158
|
0
|
0
|
|
|
|
|
if ($value =~ /\d/) { |
|
|
0
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
return $lang[$value-1] if $lang[$value-1]; |
160
|
0
|
|
|
|
|
|
return 'en_US'; |
161
|
|
|
|
|
|
|
}elsif($value =~ /\w/){ |
162
|
0
|
0
|
|
|
|
|
return $value if grep(/^$value$/, @lang); |
163
|
0
|
|
|
|
|
|
return 'en_US'; |
164
|
|
|
|
|
|
|
}else{ |
165
|
0
|
|
|
|
|
|
return 'en_US'; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub Admin { |
170
|
0
|
|
|
0
|
1
|
|
return iRedAdmin::Admin->new(ref => shift); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub Domain { |
174
|
0
|
|
|
0
|
1
|
|
return iRedAdmin::Domain->new(ref => shift); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub User { |
178
|
0
|
|
|
0
|
1
|
|
return iRedAdmin::User->new(ref => shift); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub Logout { |
182
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
183
|
0
|
|
|
|
|
|
$self->mech->get($self->url . '/logout'); |
184
|
0
|
0
|
|
|
|
|
return 1 if $self->mech->content =~ /login_form/; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
1; |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
__END__ |