|
1
|
|
|
<?php |
|
2
|
|
|
// Copyright 1999-2021. Plesk International GmbH. |
|
3
|
|
|
|
|
4
|
|
|
namespace PleskX\Api\Operator; |
|
5
|
|
|
|
|
6
|
|
|
use PleskX\Api\Struct\Server as Struct; |
|
7
|
|
|
|
|
8
|
|
|
class Server extends \PleskX\Api\Operator |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @return array |
|
12
|
|
|
*/ |
|
13
|
|
View Code Duplication |
public function getProtos() |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
$packet = $this->_client->getPacket(); |
|
16
|
|
|
$packet->addChild($this->_wrapperTag)->addChild('get_protos'); |
|
17
|
|
|
$response = $this->_client->request($packet); |
|
18
|
|
|
|
|
19
|
|
|
return (array) $response->protos->proto; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function getGeneralInfo() |
|
23
|
|
|
{ |
|
24
|
|
|
return new Struct\GeneralInfo($this->_getInfo('gen_info')); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function getPreferences() |
|
28
|
|
|
{ |
|
29
|
|
|
return new Struct\Preferences($this->_getInfo('prefs')); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getAdmin() |
|
33
|
|
|
{ |
|
34
|
|
|
return new Struct\Admin($this->_getInfo('admin')); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getKeyInfo() |
|
41
|
|
|
{ |
|
42
|
|
|
$keyInfo = []; |
|
43
|
|
|
$keyInfoXml = $this->_getInfo('key'); |
|
44
|
|
|
|
|
45
|
|
|
foreach ($keyInfoXml->property as $property) { |
|
46
|
|
|
$keyInfo[(string) $property->name] = (string) $property->value; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
return $keyInfo; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return array |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getComponents() |
|
56
|
|
|
{ |
|
57
|
|
|
$components = []; |
|
58
|
|
|
$componentsXml = $this->_getInfo('components'); |
|
59
|
|
|
|
|
60
|
|
|
foreach ($componentsXml->component as $component) { |
|
61
|
|
|
$components[(string) $component->name] = (string) $component->version; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $components; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return array |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getServiceStates() |
|
71
|
|
|
{ |
|
72
|
|
|
$states = []; |
|
73
|
|
|
$statesXml = $this->_getInfo('services_state'); |
|
74
|
|
|
|
|
75
|
|
|
foreach ($statesXml->srv as $service) { |
|
76
|
|
|
$states[(string) $service->id] = [ |
|
77
|
|
|
'id' => (string) $service->id, |
|
78
|
|
|
'title' => (string) $service->title, |
|
79
|
|
|
'state' => (string) $service->state, |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return $states; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getSessionPreferences() |
|
87
|
|
|
{ |
|
88
|
|
|
return new Struct\SessionPreferences($this->_getInfo('session_setup')); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @return array |
|
93
|
|
|
*/ |
|
94
|
|
|
public function getShells() |
|
95
|
|
|
{ |
|
96
|
|
|
$shells = []; |
|
97
|
|
|
$shellsXml = $this->_getInfo('shells'); |
|
98
|
|
|
|
|
99
|
|
|
foreach ($shellsXml->shell as $shell) { |
|
100
|
|
|
$shells[(string) $shell->name] = (string) $shell->path; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return $shells; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getNetworkInterfaces() |
|
110
|
|
|
{ |
|
111
|
|
|
$interfacesXml = $this->_getInfo('interfaces'); |
|
112
|
|
|
|
|
113
|
|
|
return (array) $interfacesXml->interface; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function getStatistics() |
|
117
|
|
|
{ |
|
118
|
|
|
return new Struct\Statistics($this->_getInfo('stat')); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return array |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getSiteIsolationConfig() |
|
125
|
|
|
{ |
|
126
|
|
|
$config = []; |
|
127
|
|
|
$configXml = $this->_getInfo('site-isolation-config'); |
|
128
|
|
|
|
|
129
|
|
|
foreach ($configXml->property as $property) { |
|
130
|
|
|
$config[(string) $property->name] = (string) $property->value; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return $config; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getUpdatesInfo() |
|
137
|
|
|
{ |
|
138
|
|
|
return new Struct\UpdatesInfo($this->_getInfo('updates')); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param string $login |
|
143
|
|
|
* @param string $clientIp |
|
144
|
|
|
* |
|
145
|
|
|
* @return string |
|
146
|
|
|
*/ |
|
147
|
|
|
public function createSession($login, $clientIp) |
|
148
|
|
|
{ |
|
149
|
|
|
$packet = $this->_client->getPacket(); |
|
150
|
|
|
$sessionNode = $packet->addChild($this->_wrapperTag)->addChild('create_session'); |
|
151
|
|
|
$sessionNode->addChild('login', $login); |
|
152
|
|
|
$dataNode = $sessionNode->addChild('data'); |
|
153
|
|
|
$dataNode->addChild('user_ip', base64_encode($clientIp)); |
|
154
|
|
|
$dataNode->addChild('source_server'); |
|
155
|
|
|
$response = $this->_client->request($packet); |
|
156
|
|
|
|
|
157
|
|
|
return (string) $response->id; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param string $operation |
|
162
|
|
|
* |
|
163
|
|
|
* @return \SimpleXMLElement |
|
164
|
|
|
*/ |
|
165
|
|
View Code Duplication |
private function _getInfo($operation) |
|
|
|
|
|
|
166
|
|
|
{ |
|
167
|
|
|
$packet = $this->_client->getPacket(); |
|
168
|
|
|
$packet->addChild($this->_wrapperTag)->addChild('get')->addChild($operation); |
|
169
|
|
|
$response = $this->_client->request($packet); |
|
170
|
|
|
|
|
171
|
|
|
return $response->$operation; |
|
172
|
|
|
} |
|
173
|
|
|
} |
|
174
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.