line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package cPanel::nginx; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
34649
|
use 5.008008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
45
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
1
|
|
|
1
|
|
938
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1819
|
|
|
1
|
|
|
|
|
6
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
13
|
|
|
|
|
|
|
getXMLAPIResponse |
14
|
|
|
|
|
|
|
getAuthHash |
15
|
|
|
|
|
|
|
) ] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw( |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
24
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
1191
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
98586
|
|
|
1
|
|
|
|
|
41
|
|
26
|
1
|
|
|
1
|
|
12
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
361
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub getAuthHash |
29
|
|
|
|
|
|
|
{ |
30
|
|
|
|
|
|
|
# Функция возвращает Hash для доступа к API cPanel |
31
|
|
|
|
|
|
|
# Hash предварительно должен быть сгенерирован в WHM |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
0
|
|
open HASHFILE, "
|
34
|
0
|
|
|
|
|
|
my $hash = ""; |
35
|
0
|
|
|
|
|
|
while () |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
|
|
|
$hash .= $_; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
close HASHFILE; |
40
|
0
|
|
|
|
|
|
$hash =~ s/\n//g; |
41
|
0
|
|
|
|
|
|
my $auth = "WHM root:" . $hash; |
42
|
0
|
|
|
|
|
|
return $auth; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub getXMLAPIResponse |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
# Первым аргументом функция принимает имя функции API |
48
|
|
|
|
|
|
|
# Во втором аргументе функции должен быть передан хэш аргументов |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
0
|
|
my ($function, %args) = @_; |
51
|
0
|
0
|
|
|
|
|
return 0 if (!$function =~ m/[a-z]+/); |
52
|
0
|
|
|
|
|
|
my $url = "https://127.0.0.1:2087/xml-api/$function"; |
53
|
0
|
|
|
|
|
|
my $args = ""; |
54
|
0
|
0
|
|
|
|
|
if (%args) |
55
|
|
|
|
|
|
|
{ |
56
|
0
|
|
|
|
|
|
foreach my $name (keys %args) |
57
|
|
|
|
|
|
|
{ |
58
|
0
|
|
|
|
|
|
$args .= "$name=$args{$name}&"; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
$url .= "?$args"; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
63
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new( GET => $url ); |
64
|
0
|
|
|
|
|
|
$request->header( Authorization => getAuthHash()); |
65
|
0
|
|
|
|
|
|
my $response = $ua->request($request); |
66
|
0
|
|
|
|
|
|
return $response->content; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |