-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathServer.php
143 lines (112 loc) · 3.91 KB
/
Server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
// Copyright 1999-2025. WebPros International GmbH.
namespace PleskX\Api\Operator;
use PleskX\Api\Struct\Server as Struct;
use PleskX\Api\XmlResponse;
class Server extends \PleskX\Api\Operator
{
public function getProtos(): array
{
$packet = $this->client->getPacket();
$packet->addChild($this->wrapperTag)->addChild('get_protos');
$response = $this->client->request($packet);
/** @psalm-suppress PossiblyNullPropertyFetch */
return (array) $response->protos->proto;
}
public function getGeneralInfo(): Struct\GeneralInfo
{
return new Struct\GeneralInfo($this->getInfo('gen_info'));
}
public function getPreferences(): Struct\Preferences
{
return new Struct\Preferences($this->getInfo('prefs'));
}
public function getAdmin(): Struct\Admin
{
return new Struct\Admin($this->getInfo('admin'));
}
public function getKeyInfo(): array
{
$keyInfo = [];
$keyInfoXml = $this->getInfo('key');
foreach ($keyInfoXml->property ?? [] as $property) {
$keyInfo[(string) $property->name] = (string) $property->value;
}
return $keyInfo;
}
public function getComponents(): array
{
$components = [];
$componentsXml = $this->getInfo('components');
foreach ($componentsXml->component ?? [] as $component) {
$components[(string) $component->name] = (string) $component->version;
}
return $components;
}
public function getServiceStates(): array
{
$states = [];
$statesXml = $this->getInfo('services_state');
foreach ($statesXml->srv ?? [] as $service) {
$states[(string) $service->id] = [
'id' => (string) $service->id,
'title' => (string) $service->title,
'state' => (string) $service->state,
];
}
return $states;
}
public function getSessionPreferences(): Struct\SessionPreferences
{
return new Struct\SessionPreferences($this->getInfo('session_setup'));
}
public function getShells(): array
{
$shells = [];
$shellsXml = $this->getInfo('shells');
foreach ($shellsXml->shell ?? [] as $shell) {
$shells[(string) $shell->name] = (string) $shell->path;
}
return $shells;
}
public function getNetworkInterfaces(): array
{
$interfacesXml = $this->getInfo('interfaces');
return (array) $interfacesXml->interface;
}
public function getStatistics(): Struct\Statistics
{
return new Struct\Statistics($this->getInfo('stat'));
}
public function getSiteIsolationConfig(): array
{
$config = [];
$configXml = $this->getInfo('site-isolation-config');
foreach ($configXml->property ?? [] as $property) {
$config[(string) $property->name] = (string) $property->value;
}
return $config;
}
public function getUpdatesInfo(): Struct\UpdatesInfo
{
return new Struct\UpdatesInfo($this->getInfo('updates'));
}
public function createSession(string $login, string $clientIp): string
{
$packet = $this->client->getPacket();
$sessionNode = $packet->addChild($this->wrapperTag)->addChild('create_session');
$sessionNode->addChild('login', $login);
$dataNode = $sessionNode->addChild('data');
$dataNode->addChild('user_ip', base64_encode($clientIp));
$dataNode->addChild('source_server');
$response = $this->client->request($packet);
return (string) $response->id;
}
private function getInfo(string $operation): XmlResponse
{
$packet = $this->client->getPacket();
$packet->addChild($this->wrapperTag)->addChild('get')->addChild($operation);
$response = $this->client->request($packet);
return $response->$operation;
}
}