├── .github
├── dependabot.yml
└── workflows
│ └── test.yml
├── .gitignore
├── Dockerfile
├── LICENSE
├── README.md
├── composer.json
├── composer.lock
├── docker-compose.yml
├── phpcs.xml.dist
├── phpunit-watcher.yml
├── phpunit.xml.dist
├── psalm.xml
├── src
└── Api
│ ├── AbstractStruct.php
│ ├── Client.php
│ ├── Client
│ └── Exception.php
│ ├── Exception.php
│ ├── InternalClient.php
│ ├── Operator.php
│ ├── Operator
│ ├── Aps.php
│ ├── Certificate.php
│ ├── Customer.php
│ ├── Database.php
│ ├── DatabaseServer.php
│ ├── Dns.php
│ ├── DnsTemplate.php
│ ├── EventLog.php
│ ├── Ip.php
│ ├── Locale.php
│ ├── LogRotation.php
│ ├── Mail.php
│ ├── PhpHandler.php
│ ├── ProtectedDirectory.php
│ ├── Reseller.php
│ ├── ResellerPlan.php
│ ├── SecretKey.php
│ ├── Server.php
│ ├── ServicePlan.php
│ ├── ServicePlanAddon.php
│ ├── Session.php
│ ├── Site.php
│ ├── SiteAlias.php
│ ├── Subdomain.php
│ ├── Ui.php
│ ├── VirtualDirectory.php
│ └── Webspace.php
│ ├── Struct
│ ├── Certificate
│ │ └── Info.php
│ ├── Customer
│ │ ├── GeneralInfo.php
│ │ └── Info.php
│ ├── Database
│ │ ├── Info.php
│ │ └── UserInfo.php
│ ├── DatabaseServer
│ │ └── Info.php
│ ├── Dns
│ │ └── Info.php
│ ├── EventLog
│ │ ├── DetailedEvent.php
│ │ └── Event.php
│ ├── Ip
│ │ └── Info.php
│ ├── Locale
│ │ └── Info.php
│ ├── Mail
│ │ ├── GeneralInfo.php
│ │ └── Info.php
│ ├── PhpHandler
│ │ └── Info.php
│ ├── ProtectedDirectory
│ │ ├── DataInfo.php
│ │ ├── Info.php
│ │ └── UserInfo.php
│ ├── Reseller
│ │ ├── GeneralInfo.php
│ │ └── Info.php
│ ├── SecretKey
│ │ └── Info.php
│ ├── Server
│ │ ├── Admin.php
│ │ ├── GeneralInfo.php
│ │ ├── Preferences.php
│ │ ├── SessionPreferences.php
│ │ ├── Statistics.php
│ │ ├── Statistics
│ │ │ ├── DiskSpace.php
│ │ │ ├── LoadAverage.php
│ │ │ ├── Memory.php
│ │ │ ├── Objects.php
│ │ │ ├── Other.php
│ │ │ ├── Swap.php
│ │ │ └── Version.php
│ │ └── UpdatesInfo.php
│ ├── ServicePlan
│ │ └── Info.php
│ ├── ServicePlanAddon
│ │ └── Info.php
│ ├── Session
│ │ └── Info.php
│ ├── Site
│ │ ├── GeneralInfo.php
│ │ ├── HostingInfo.php
│ │ └── Info.php
│ ├── SiteAlias
│ │ ├── GeneralInfo.php
│ │ └── Info.php
│ ├── Subdomain
│ │ └── Info.php
│ ├── Ui
│ │ └── CustomButton.php
│ └── Webspace
│ │ ├── DiskUsage.php
│ │ ├── GeneralInfo.php
│ │ ├── HostingPropertyInfo.php
│ │ ├── Info.php
│ │ ├── Limit.php
│ │ ├── LimitDescriptor.php
│ │ ├── LimitInfo.php
│ │ ├── Limits.php
│ │ ├── PermissionDescriptor.php
│ │ ├── PermissionInfo.php
│ │ ├── PhpSettings.php
│ │ └── PhysicalHostingDescriptor.php
│ └── XmlResponse.php
├── tests
├── AbstractTestCase.php
├── ApiClientTest.php
├── CertificateTest.php
├── CustomerTest.php
├── DatabaseServerTest.php
├── DatabaseTest.php
├── DnsTemplateTest.php
├── DnsTest.php
├── EventLogTest.php
├── IpTest.php
├── LocaleTest.php
├── MailTest.php
├── PhpHandlerTest.php
├── ProtectedDirectoryTest.php
├── ResellerTest.php
├── SecretKeyTest.php
├── ServerTest.php
├── ServicePlanAddonTest.php
├── ServicePlanTest.php
├── SessionTest.php
├── SiteAliasTest.php
├── SiteTest.php
├── SubdomainTest.php
├── UiTest.php
├── Utility
│ ├── KeyLimitChecker.php
│ └── PasswordProvider.php
└── WebspaceTest.php
└── wait-for-plesk.sh
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "composer"
4 | directory: "/"
5 | schedule:
6 | interval: "weekly"
7 | commit-message:
8 | prefix: "TECH "
9 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: test
2 |
3 | on: [push]
4 |
5 | jobs:
6 | test:
7 | runs-on: ubuntu-24.04
8 | steps:
9 | - uses: actions/checkout@v4
10 | - run: docker compose run tests
11 | - uses: codecov/codecov-action@v4
12 | with:
13 | token: ${{ secrets.CODECOV_TOKEN }}
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.env
2 | /vendor/
3 | /phpunit.xml
4 | /.phpunit.result.cache
5 | /coverage.xml
6 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:8.2-cli
2 |
3 | RUN apt-get update \
4 | && apt-get install -y unzip \
5 | && docker-php-ext-install pcntl \
6 | && pecl install xdebug \
7 | && echo "zend_extension=xdebug.so" > /usr/local/etc/php/conf.d/xdebug.ini \
8 | && echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini \
9 | && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
10 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 1999-2025. WebPros International GmbH.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## PHP library for Plesk XML-RPC API
2 |
3 | [](https://github.com/plesk/api-php-lib/actions/workflows/test.yml)
4 | [](https://scrutinizer-ci.com/g/plesk/api-php-lib/?branch=master)
5 | [](https://codecov.io/gh/plesk/api-php-lib)
6 |
7 | PHP object-oriented library for Plesk XML-RPC API.
8 |
9 | ## Install Via Composer
10 |
11 | [Composer](https://getcomposer.org/) is a preferable way to install the library:
12 |
13 | `composer require plesk/api-php-lib`
14 |
15 | ## Usage Examples
16 |
17 | Here is an example on how to use the library and create a customer with desired properties:
18 | ```php
19 | $client = new \PleskX\Api\Client($host);
20 | $client->setCredentials($login, $password);
21 |
22 | $client->customer()->create([
23 | 'cname' => 'Plesk',
24 | 'pname' => 'John Smith',
25 | 'login' => 'john',
26 | 'passwd' => 'secret',
27 | 'email' => 'john@smith.com',
28 | ]);
29 | ```
30 |
31 | It is possible to use a secret key instead of password for authentication.
32 |
33 | ```php
34 | $client = new \PleskX\Api\Client($host);
35 | $client->setSecretKey($secretKey)
36 | ```
37 |
38 | In case of Plesk extension creation one can use an internal mechanism to access XML-RPC API. It does not require to pass authentication because the extension works in the context of Plesk.
39 |
40 | ```php
41 | $client = new \PleskX\Api\InternalClient();
42 | $protocols = $client->server()->getProtos();
43 | ```
44 |
45 | For additional examples see tests/ directory.
46 |
47 | ## How to Run Unit Tests
48 |
49 | One the possible ways to become familiar with the library is to check the unit tests.
50 |
51 | To run the unit tests use the following command:
52 |
53 | `REMOTE_HOST=your-plesk-host.dom REMOTE_PASSWORD=password composer test`
54 |
55 | To use custom port one can provide a URL (e.g. for Docker container):
56 |
57 | `REMOTE_URL=https://your-plesk-host.dom:port REMOTE_PASSWORD=password composer test`
58 |
59 | One more way to run tests is to use Docker:
60 |
61 | `docker-compose run tests`
62 |
63 | ## Continuous Testing
64 |
65 | During active development it could be more convenient to run tests in continuous manner. Here is the way how to achieve it:
66 |
67 | `REMOTE_URL=https://your-plesk-host.dom:port REMOTE_PASSWORD=password composer test:watch`
68 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "plesk/api-php-lib",
3 | "type": "library",
4 | "description": "PHP object-oriented library for Plesk XML-RPC API",
5 | "license": "Apache-2.0",
6 | "authors": [
7 | {
8 | "name": "Alexei Yuzhakov",
9 | "email": "sibprogrammer@gmail.com"
10 | },
11 | {
12 | "name": "WebPros International GmbH.",
13 | "email": "plesk-dev-leads@plesk.com"
14 | }
15 | ],
16 | "require": {
17 | "php": "^7.4 || ^8.0",
18 | "ext-curl": "*",
19 | "ext-xml": "*",
20 | "ext-simplexml": "*",
21 | "ext-dom": "*"
22 | },
23 | "require-dev": {
24 | "phpunit/phpunit": "^9",
25 | "spatie/phpunit-watcher": "^1.22",
26 | "vimeo/psalm": "^4.10 || ^5.0",
27 | "squizlabs/php_codesniffer": "^3.6"
28 | },
29 | "config": {
30 | "process-timeout": 0,
31 | "platform": {
32 | "php": "7.4.27"
33 | }
34 | },
35 | "scripts": {
36 | "test": "phpunit",
37 | "test:watch": "phpunit-watcher watch",
38 | "lint": [
39 | "psalm",
40 | "phpcs"
41 | ]
42 | },
43 | "autoload": {
44 | "psr-4": {
45 | "PleskX\\": "src/"
46 | }
47 | },
48 | "autoload-dev": {
49 | "psr-4": {
50 | "PleskXTest\\": "tests/"
51 | }
52 | },
53 | "extra": {
54 | "branch-alias": {
55 | "dev-master": "2.0.x-dev"
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | # Copyright 1999-2025. WebPros International GmbH.
2 | version: '3'
3 | services:
4 | plesk:
5 | image: plesk/plesk:latest
6 | logging:
7 | driver: none
8 | ports:
9 | ["8443:8443"]
10 | tmpfs:
11 | - /tmp
12 | - /run
13 | - /run/lock
14 | volumes:
15 | - /sys/fs/cgroup:/sys/fs/cgroup
16 | cgroup: host
17 | tests:
18 | build: .
19 | environment:
20 | REMOTE_URL: https://plesk:8443
21 | REMOTE_PASSWORD: changeme1Q**
22 | command: >
23 | bash -c "cd /opt/api-php-lib
24 | && composer install
25 | && ./wait-for-plesk.sh
26 | && composer lint
27 | && composer test -- --testdox"
28 | depends_on:
29 | - plesk
30 | links:
31 | - plesk
32 | volumes:
33 | - .:/opt/api-php-lib
34 |
--------------------------------------------------------------------------------
/phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | src
5 | tests
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/phpunit-watcher.yml:
--------------------------------------------------------------------------------
1 | # Copyright 1999-2025. WebPros International GmbH.
2 | phpunit:
3 | arguments: '--stop-on-failure'
4 | timeout: 0
5 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ./src
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | ./tests
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/psalm.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Api/AbstractStruct.php:
--------------------------------------------------------------------------------
1 | {key($property)};
33 | } else {
34 | /** @psalm-suppress PossiblyInvalidArgument */
35 | $classPropertyName = $this->underToCamel(str_replace('-', '_', $property));
36 | $value = $apiResponse->$property;
37 | }
38 |
39 | $reflectionProperty = new \ReflectionProperty($this, $classPropertyName);
40 | $propertyType = $reflectionProperty->getType();
41 | if (is_null($propertyType)) {
42 | $docBlock = $reflectionProperty->getDocComment();
43 | $propertyType = preg_replace('/^.+ @var ([a-z]+) .+$/', '\1', $docBlock);
44 | } else {
45 | /** @psalm-suppress UndefinedMethod */
46 | $propertyType = $propertyType->getName();
47 | }
48 |
49 | if ('string' == $propertyType) {
50 | $value = (string) $value;
51 | } elseif ('int' == $propertyType) {
52 | $value = (int) $value;
53 | } elseif ('bool' == $propertyType) {
54 | $value = in_array((string) $value, ['true', 'on', 'enabled']);
55 | } else {
56 | throw new \Exception("Unknown property type '$propertyType'.");
57 | }
58 |
59 | $this->$classPropertyName = $value;
60 | }
61 | }
62 |
63 | /**
64 | * Convert underscore separated words into camel case.
65 | *
66 | * @param string $under
67 | *
68 | * @return string
69 | */
70 | private function underToCamel(string $under): string
71 | {
72 | $under = '_' . str_replace('_', ' ', strtolower($under));
73 |
74 | return ltrim(str_replace(' ', '', ucwords($under)), '_');
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/Api/Client/Exception.php:
--------------------------------------------------------------------------------
1 | login = $login;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Api/Operator.php:
--------------------------------------------------------------------------------
1 | client = $client;
14 |
15 | if ('' === $this->wrapperTag) {
16 | $classNameParts = explode('\\', get_class($this));
17 | $this->wrapperTag = end($classNameParts);
18 | $this->wrapperTag = strtolower(preg_replace('/([a-z])([A-Z])/', '\1-\2', $this->wrapperTag));
19 | }
20 | }
21 |
22 | /**
23 | * Perform plain API request.
24 | *
25 | * @param string|array $request
26 | * @param int $mode
27 | *
28 | * @return XmlResponse
29 | */
30 | public function request($request, $mode = Client::RESPONSE_SHORT): XmlResponse
31 | {
32 | $wrapperTag = $this->wrapperTag;
33 |
34 | if (is_array($request)) {
35 | $request = [$wrapperTag => $request];
36 | } elseif (preg_match('/^[a-z]/', $request)) {
37 | $request = "$wrapperTag.$request";
38 | } else {
39 | $request = "<$wrapperTag>$request$wrapperTag>";
40 | }
41 |
42 | return $this->client->request($request, $mode);
43 | }
44 |
45 | /**
46 | * @param string $field
47 | * @param int|string $value
48 | * @param string $deleteMethodName
49 | *
50 | * @return bool
51 | */
52 | protected function deleteBy(string $field, $value, string $deleteMethodName = 'del'): bool
53 | {
54 | $response = $this->request([
55 | $deleteMethodName => [
56 | 'filter' => [
57 | $field => $value,
58 | ],
59 | ],
60 | ]);
61 |
62 | return 'ok' === (string) $response->status;
63 | }
64 |
65 | /**
66 | * @param string $structClass
67 | * @param string $infoTag
68 | * @param string|null $field
69 | * @param int|string|null $value
70 | * @param callable|null $filter
71 | *
72 | * @return array
73 | */
74 | protected function getItems($structClass, $infoTag, $field = null, $value = null, ?callable $filter = null): array
75 | {
76 | $packet = $this->client->getPacket();
77 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
78 |
79 | $filterTag = $getTag->addChild('filter');
80 | if (!is_null($field)) {
81 | $filterTag->{$field} = (string) $value;
82 | }
83 |
84 | $getTag->addChild('dataset')->addChild($infoTag);
85 |
86 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
87 |
88 | $items = [];
89 | foreach ((array) $response->xpath('//result') as $xmlResult) {
90 | if (!$xmlResult || !isset($xmlResult->data) || !isset($xmlResult->data->$infoTag)) {
91 | continue;
92 | }
93 | if (!is_null($filter) && !$filter($xmlResult->data->$infoTag)) {
94 | continue;
95 | }
96 | /** @psalm-suppress InvalidStringClass */
97 | $item = new $structClass($xmlResult->data->$infoTag);
98 | if (isset($xmlResult->id) && property_exists($item, 'id')) {
99 | $item->id = (int) $xmlResult->id;
100 | }
101 | $items[] = $item;
102 | }
103 |
104 | return $items;
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/src/Api/Operator/Aps.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('generate')->addChild('info');
14 |
15 | foreach ($properties as $name => $value) {
16 | $info->{$name} = $value;
17 | }
18 |
19 | $response = $this->client->request($packet);
20 |
21 | return new Struct\Info($response);
22 | }
23 |
24 | /**
25 | * @param array $properties
26 | * @param string|Struct\Info $certificate
27 | * @param string|null $privateKey
28 | */
29 | public function install(array $properties, $certificate, ?string $privateKey = null): bool
30 | {
31 | return $this->callApi('install', $properties, $certificate, $privateKey);
32 | }
33 |
34 | /**
35 | * @param array $properties
36 | * @param Struct\Info $certificate
37 | */
38 | public function update(array $properties, Struct\Info $certificate): bool
39 | {
40 | return $this->callApi('update', $properties, $certificate);
41 | }
42 |
43 | /**
44 | * @param string $method
45 | * @param array $properties
46 | * @param string|Struct\Info $certificate
47 | * @param string|null $privateKey
48 | */
49 | private function callApi(string $method, array $properties, $certificate, ?string $privateKey = null): bool
50 | {
51 | $packet = $this->client->getPacket();
52 |
53 | $installTag = $packet->addChild($this->wrapperTag)->addChild($method);
54 | foreach ($properties as $name => $value) {
55 | $installTag->{$name} = $value;
56 | }
57 |
58 | $contentTag = $installTag->addChild('content');
59 | if (is_string($certificate)) {
60 | $contentTag->addChild('csr', $certificate);
61 | $contentTag->addChild('pvt', $privateKey);
62 | } elseif ($certificate instanceof \PleskX\Api\Struct\Certificate\Info) {
63 | foreach ($certificate->getMapping() as $name => $value) {
64 | $contentTag->{$name} = $value;
65 | }
66 | }
67 | $result = $this->client->request($packet);
68 |
69 | return 'ok' == (string) $result->status;
70 | }
71 |
72 | public function delete(string $name, array $properties): bool
73 | {
74 | $packet = $this->client->getPacket();
75 |
76 | $removeTag = $packet->addChild($this->wrapperTag)->addChild('remove');
77 | $removeTag->addChild('filter')->addChild('name', $name);
78 |
79 | foreach ($properties as $name => $value) {
80 | $removeTag->{$name} = $value;
81 | }
82 |
83 | $result = $this->client->request($packet);
84 |
85 | return 'ok' == (string) $result->status;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/Api/Operator/Customer.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('add')->addChild('gen_info');
14 |
15 | foreach ($properties as $name => $value) {
16 | $info->{$name} = $value;
17 | }
18 |
19 | $response = $this->client->request($packet);
20 |
21 | return new Struct\Info($response);
22 | }
23 |
24 | /**
25 | * @param string $field
26 | * @param int|string $value
27 | *
28 | * @return bool
29 | */
30 | public function delete(string $field, $value): bool
31 | {
32 | return $this->deleteBy($field, $value);
33 | }
34 |
35 | /**
36 | * @param string $field
37 | * @param int|string $value
38 | *
39 | * @return Struct\GeneralInfo
40 | */
41 | public function get(string $field, $value): Struct\GeneralInfo
42 | {
43 | $items = $this->getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
44 |
45 | return reset($items);
46 | }
47 |
48 | /**
49 | * @return Struct\GeneralInfo[]
50 | */
51 | public function getAll(): array
52 | {
53 | return $this->getItems(Struct\GeneralInfo::class, 'gen_info');
54 | }
55 |
56 | /**
57 | * @param string $field
58 | * @param int|string $value
59 | *
60 | * @return bool
61 | */
62 | public function enable(string $field, $value): bool
63 | {
64 | return $this->setProperties($field, $value, ['status' => 0]);
65 | }
66 |
67 | /**
68 | * @param string $field
69 | * @param int|string $value
70 | *
71 | * @return bool
72 | */
73 | public function disable(string $field, $value): bool
74 | {
75 | return $this->setProperties($field, $value, ['status' => 16]);
76 | }
77 |
78 | /**
79 | * @param string $field
80 | * @param int|string $value
81 | * @param array $properties
82 | *
83 | * @return bool
84 | */
85 | public function setProperties(string $field, $value, array $properties): bool
86 | {
87 | $packet = $this->client->getPacket();
88 | $setTag = $packet->addChild($this->wrapperTag)->addChild('set');
89 | $setTag->addChild('filter')->addChild($field, (string) $value);
90 | $genInfoTag = $setTag->addChild('values')->addChild('gen_info');
91 | foreach ($properties as $property => $propertyValue) {
92 | $genInfoTag->addChild($property, (string) $propertyValue);
93 | }
94 |
95 | $response = $this->client->request($packet);
96 |
97 | return 'ok' === (string) $response->status;
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/Api/Operator/Database.php:
--------------------------------------------------------------------------------
1 | process('add-db', $properties));
14 | }
15 |
16 | public function createUser(array $properties): Struct\UserInfo
17 | {
18 | return new Struct\UserInfo($this->process('add-db-user', $properties));
19 | }
20 |
21 | private function process(string $command, array $properties): XmlResponse
22 | {
23 | $packet = $this->client->getPacket();
24 | $info = $packet->addChild($this->wrapperTag)->addChild($command);
25 |
26 | foreach ($properties as $name => $value) {
27 | if (false !== strpos($value, '&')) {
28 | $info->$name = $value;
29 | continue;
30 | }
31 | $info->{$name} = $value;
32 | }
33 |
34 | return $this->client->request($packet);
35 | }
36 |
37 | public function updateUser(array $properties): bool
38 | {
39 | $response = $this->process('set-db-user', $properties);
40 |
41 | return 'ok' === (string) $response->status;
42 | }
43 |
44 | /**
45 | * @param string $field
46 | * @param int|string $value
47 | *
48 | * @return Struct\Info
49 | */
50 | public function get(string $field, $value): Struct\Info
51 | {
52 | $items = $this->getAll($field, $value);
53 |
54 | return reset($items);
55 | }
56 |
57 | /**
58 | * @param string $field
59 | * @param int|string $value
60 | *
61 | * @return Struct\UserInfo
62 | */
63 | public function getUser(string $field, $value): Struct\UserInfo
64 | {
65 | $items = $this->getAllUsers($field, $value);
66 |
67 | return reset($items);
68 | }
69 |
70 | /**
71 | * @param string|null $field
72 | * @param int|string $value
73 | *
74 | * @return Struct\Info[]
75 | */
76 | public function getAll(?string $field, $value): array
77 | {
78 | $response = $this->getBy('get-db', $field, $value);
79 | $items = [];
80 | foreach ((array) $response->xpath('//result') as $xmlResult) {
81 | if ($xmlResult) {
82 | $items[] = new Struct\Info($xmlResult);
83 | }
84 | }
85 |
86 | return $items;
87 | }
88 |
89 | /**
90 | * @param string $field
91 | * @param int|string $value
92 | *
93 | * @return Struct\UserInfo[]
94 | */
95 | public function getAllUsers(string $field, $value): array
96 | {
97 | $response = $this->getBy('get-db-users', $field, $value);
98 | $items = [];
99 | foreach ((array) $response->xpath('//result') as $xmlResult) {
100 | if ($xmlResult) {
101 | $items[] = new Struct\UserInfo($xmlResult);
102 | }
103 | }
104 |
105 | return $items;
106 | }
107 |
108 | /**
109 | * @param string $command
110 | * @param string|null $field
111 | * @param int|string $value
112 | *
113 | * @return XmlResponse
114 | */
115 | private function getBy(string $command, ?string $field, $value): XmlResponse
116 | {
117 | $packet = $this->client->getPacket();
118 | $getTag = $packet->addChild($this->wrapperTag)->addChild($command);
119 |
120 | $filterTag = $getTag->addChild('filter');
121 | if (!is_null($field)) {
122 | $filterTag->{$field} = (string) $value;
123 | }
124 |
125 | return $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
126 | }
127 |
128 | /**
129 | * @param string $field
130 | * @param int|string $value
131 | *
132 | * @return bool
133 | */
134 | public function delete(string $field, $value): bool
135 | {
136 | return $this->deleteBy($field, $value, 'del-db');
137 | }
138 |
139 | /**
140 | * @param string $field
141 | * @param int|string $value
142 | *
143 | * @return bool
144 | */
145 | public function deleteUser(string $field, $value): bool
146 | {
147 | return $this->deleteBy($field, $value, 'del-db-user');
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/src/Api/Operator/DatabaseServer.php:
--------------------------------------------------------------------------------
1 | request('get-supported-types');
15 |
16 | return (array) $response->type;
17 | }
18 |
19 | /**
20 | * @param string $field
21 | * @param int|string $value
22 | *
23 | * @return Struct\Info
24 | */
25 | public function get(string $field, $value): Struct\Info
26 | {
27 | $items = $this->getBy($field, $value);
28 |
29 | return reset($items);
30 | }
31 |
32 | /**
33 | * @return Struct\Info[]
34 | */
35 | public function getAll(): array
36 | {
37 | return $this->getBy();
38 | }
39 |
40 | public function getDefault(string $type): Struct\Info
41 | {
42 | $packet = $this->client->getPacket();
43 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get-default');
44 | $filterTag = $getTag->addChild('filter');
45 | /** @psalm-suppress UndefinedPropertyAssignment */
46 | $filterTag->type = $type;
47 |
48 | $response = $this->client->request($packet);
49 |
50 | return new Struct\Info($response);
51 | }
52 |
53 | /**
54 | * @param string|null $field
55 | * @param int|string|null $value
56 | *
57 | * @return Struct\Info[]
58 | */
59 | private function getBy($field = null, $value = null): array
60 | {
61 | $packet = $this->client->getPacket();
62 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
63 |
64 | $filterTag = $getTag->addChild('filter');
65 | if (!is_null($field)) {
66 | $filterTag->{$field} = (string) $value;
67 | }
68 |
69 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
70 |
71 | $items = [];
72 | foreach ((array) $response->xpath('//result') as $xmlResult) {
73 | if (!$xmlResult) {
74 | continue;
75 | }
76 | if (!is_null($xmlResult->data)) {
77 | $item = new Struct\Info($xmlResult->data);
78 | $item->id = (int) $xmlResult->id;
79 | $items[] = $item;
80 | }
81 | }
82 |
83 | return $items;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/Api/Operator/Dns.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('add_rec');
14 |
15 | foreach ($properties as $name => $value) {
16 | $info->{$name} = $value;
17 | }
18 |
19 | return new Struct\Info($this->client->request($packet));
20 | }
21 |
22 | /**
23 | * Send multiply records by one request.
24 | *
25 | * @param array $records
26 | *
27 | * @return \SimpleXMLElement[]
28 | */
29 | public function bulkCreate(array $records): array
30 | {
31 | $packet = $this->client->getPacket();
32 |
33 | foreach ($records as $properties) {
34 | $info = $packet->addChild($this->wrapperTag)->addChild('add_rec');
35 |
36 | foreach ($properties as $name => $value) {
37 | $info->{$name} = $value;
38 | }
39 | }
40 |
41 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
42 | $items = [];
43 | foreach ((array) $response->xpath('//result') as $xmlResult) {
44 | if ($xmlResult) {
45 | $items[] = $xmlResult;
46 | }
47 | }
48 |
49 | return $items;
50 | }
51 |
52 | /**
53 | * @param string $field
54 | * @param int|string $value
55 | *
56 | * @return Struct\Info
57 | */
58 | public function get(string $field, $value): Struct\Info
59 | {
60 | $items = $this->getAll($field, $value);
61 |
62 | return reset($items);
63 | }
64 |
65 | /**
66 | * @param string $field
67 | * @param int|string $value
68 | *
69 | * @return Struct\Info[]
70 | */
71 | public function getAll(string $field, $value): array
72 | {
73 | $packet = $this->client->getPacket();
74 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get_rec');
75 |
76 | $filterTag = $getTag->addChild('filter');
77 | $filterTag->addChild($field, (string) $value);
78 |
79 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
80 | $items = [];
81 | foreach ((array) $response->xpath('//result') as $xmlResult) {
82 | if (!$xmlResult) {
83 | continue;
84 | }
85 | if (!is_null($xmlResult->data)) {
86 | $item = new Struct\Info($xmlResult->data);
87 | $item->id = (int) $xmlResult->id;
88 | $items[] = $item;
89 | }
90 | }
91 |
92 | return $items;
93 | }
94 |
95 | /**
96 | * @param string $field
97 | * @param int|string $value
98 | *
99 | * @return bool
100 | */
101 | public function delete(string $field, $value): bool
102 | {
103 | return $this->deleteBy($field, $value, 'del_rec');
104 | }
105 |
106 | /**
107 | * Delete multiply records by one request.
108 | *
109 | * @param array $recordIds
110 | *
111 | * @return \SimpleXMLElement[]
112 | */
113 | public function bulkDelete(array $recordIds): array
114 | {
115 | $packet = $this->client->getPacket();
116 |
117 | foreach ($recordIds as $recordId) {
118 | $packet->addChild($this->wrapperTag)->addChild('del_rec')
119 | ->addChild('filter')->addChild('id', $recordId);
120 | }
121 |
122 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
123 | $items = [];
124 | foreach ((array) $response->xpath('//result') as $xmlResult) {
125 | if ($xmlResult) {
126 | $items[] = $xmlResult;
127 | }
128 | }
129 |
130 | return $items;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/Api/Operator/DnsTemplate.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
20 | $info = $packet->addChild($this->wrapperTag)->addChild('add_rec');
21 |
22 | unset($properties['site-id'], $properties['site-alias-id']);
23 | foreach ($properties as $name => $value) {
24 | $info->{$name} = $value;
25 | }
26 |
27 | return new Struct\Info($this->client->request($packet));
28 | }
29 |
30 | /**
31 | * @param string $field
32 | * @param int|string $value
33 | *
34 | * @return Struct\Info
35 | */
36 | public function get(string $field, $value): Struct\Info
37 | {
38 | $items = $this->getAll($field, $value);
39 |
40 | return reset($items);
41 | }
42 |
43 | /**
44 | * @param string $field
45 | * @param int|string $value
46 | *
47 | * @return Struct\Info[]
48 | */
49 | public function getAll($field = null, $value = null): array
50 | {
51 | $packet = $this->client->getPacket();
52 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get_rec');
53 |
54 | $filterTag = $getTag->addChild('filter');
55 | if (!is_null($field)) {
56 | $filterTag->{$field} = (string) $value;
57 | }
58 | $getTag->addChild('template');
59 |
60 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
61 | $items = [];
62 | foreach ((array) $response->xpath('//result') as $xmlResult) {
63 | if (!$xmlResult) {
64 | continue;
65 | }
66 | if (!is_null($xmlResult->data)) {
67 | $item = new Struct\Info($xmlResult->data);
68 | $item->id = (int) $xmlResult->id;
69 | $items[] = $item;
70 | }
71 | }
72 |
73 | return $items;
74 | }
75 |
76 | /**
77 | * @param string $field
78 | * @param int|string $value
79 | *
80 | * @return bool
81 | */
82 | public function delete(string $field, $value): bool
83 | {
84 | $packet = $this->client->getPacket();
85 | $delTag = $packet->addChild($this->wrapperTag)->addChild('del_rec');
86 | $delTag->addChild('filter')->addChild($field, (string) $value);
87 | $delTag->addChild('template');
88 |
89 | $response = $this->client->request($packet);
90 |
91 | return 'ok' === (string) $response->status;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/Api/Operator/EventLog.php:
--------------------------------------------------------------------------------
1 | request('get');
19 |
20 | foreach ($response->event ?? [] as $eventInfo) {
21 | $records[] = new Struct\Event($eventInfo);
22 | }
23 |
24 | return $records;
25 | }
26 |
27 | /**
28 | * @return Struct\DetailedEvent[]
29 | */
30 | public function getDetailedLog(): array
31 | {
32 | $records = [];
33 | $response = $this->request('get_events');
34 |
35 | foreach ($response->event ?? [] as $eventInfo) {
36 | $records[] = new Struct\DetailedEvent($eventInfo);
37 | }
38 |
39 | return $records;
40 | }
41 |
42 | public function getLastId(): int
43 | {
44 | return (int) $this->request('get-last-id')->getValue('id');
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/Api/Operator/Ip.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
17 | $packet->addChild($this->wrapperTag)->addChild('get');
18 | $response = $this->client->request($packet);
19 |
20 | foreach ($response->addresses->ip_info ?? [] as $ipInfo) {
21 | $ips[] = new Struct\Info($ipInfo);
22 | }
23 |
24 | return $ips;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Api/Operator/Locale.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
19 | $filter = $packet->addChild($this->wrapperTag)->addChild('get')->addChild('filter');
20 |
21 | if (!is_null($id)) {
22 | $filter->addChild('id', $id);
23 | }
24 |
25 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
26 |
27 | foreach ($response->locale->get->result ?? [] as $localeInfo) {
28 | if (!is_null($localeInfo->info)) {
29 | $locales[(string) $localeInfo->info->id] = new Struct\Info($localeInfo->info);
30 | }
31 | }
32 |
33 | return !is_null($id) ? reset($locales) : $locales;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Api/Operator/LogRotation.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
15 | $info = $packet->addChild($this->wrapperTag)->addChild('create');
16 |
17 | $filter = $info->addChild('filter');
18 | $filter->addChild('site-id', (string) $siteId);
19 | $mailname = $filter->addChild('mailname');
20 | $mailname->addChild('name', $name);
21 | if ($mailbox) {
22 | $mailname->addChild('mailbox')->addChild('enabled', 'true');
23 | }
24 | if (!empty($password)) {
25 | /** @psalm-suppress UndefinedPropertyAssignment */
26 | $mailname->addChild('password')->value = $password;
27 | }
28 |
29 | $response = $this->client->request($packet);
30 |
31 | /** @psalm-suppress PossiblyNullArgument */
32 | return new Struct\Info($response->mailname);
33 | }
34 |
35 | /**
36 | * @param string $field
37 | * @param int|string $value
38 | * @param int $siteId
39 | *
40 | * @return bool
41 | */
42 | public function delete(string $field, $value, int $siteId): bool
43 | {
44 | $packet = $this->client->getPacket();
45 | $filter = $packet->addChild($this->wrapperTag)->addChild('remove')->addChild('filter');
46 |
47 | $filter->addChild('site-id', (string) $siteId);
48 | $filter->{$field} = (string) $value;
49 |
50 | $response = $this->client->request($packet);
51 |
52 | return 'ok' === (string) $response->status;
53 | }
54 |
55 | public function get(string $name, int $siteId): Struct\GeneralInfo
56 | {
57 | $items = $this->getAll($siteId, $name);
58 |
59 | return reset($items);
60 | }
61 |
62 | /**
63 | * @param int $siteId
64 | * @param string|null $name
65 | *
66 | * @return Struct\GeneralInfo[]
67 | */
68 | public function getAll(int $siteId, $name = null): array
69 | {
70 | $packet = $this->client->getPacket();
71 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get_info');
72 |
73 | $filterTag = $getTag->addChild('filter');
74 | $filterTag->addChild('site-id', (string) $siteId);
75 | if (!is_null($name)) {
76 | $filterTag->addChild('name', $name);
77 | }
78 |
79 | $response = $this->client->request($packet, Client::RESPONSE_FULL);
80 | $items = [];
81 | foreach ((array) $response->xpath('//result') as $xmlResult) {
82 | if (!$xmlResult || !isset($xmlResult->mailname)) {
83 | continue;
84 | }
85 | $item = new Struct\GeneralInfo($xmlResult->mailname);
86 | $items[] = $item;
87 | }
88 |
89 | return $items;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/Api/Operator/PhpHandler.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
21 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
22 | $filterTag = $getTag->addChild('filter');
23 |
24 | if (!is_null($field)) {
25 | $filterTag->addChild($field, (string) $value);
26 | }
27 |
28 | $response = $this->client->request($packet, Client::RESPONSE_FULL);
29 | $xmlResult = ($response->xpath('//result') ?: [null])[0];
30 |
31 | return $xmlResult ? new Info($xmlResult) : null;
32 | }
33 |
34 | /**
35 | * @param string|null $field
36 | * @param int|string $value
37 | *
38 | * @return Info[]
39 | */
40 | public function getAll($field = null, $value = null): array
41 | {
42 | $packet = $this->client->getPacket();
43 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
44 |
45 | $filterTag = $getTag->addChild('filter');
46 | if (!is_null($field)) {
47 | $filterTag->addChild($field, (string) $value);
48 | }
49 |
50 | $response = $this->client->request($packet, Client::RESPONSE_FULL);
51 | $items = [];
52 | foreach ((array) $response->xpath('//result') as $xmlResult) {
53 | if (!$xmlResult) {
54 | continue;
55 | }
56 | $item = new Info($xmlResult);
57 | $items[] = $item;
58 | }
59 |
60 | return $items;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Api/Operator/ProtectedDirectory.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
17 | $info = $packet->addChild($this->wrapperTag)->addChild('add');
18 |
19 | $info->addChild('site-id', (string) $siteId);
20 | $info->addChild('name', $name);
21 | $info->addChild('header', $header);
22 |
23 | return new Struct\Info($this->client->request($packet));
24 | }
25 |
26 | /**
27 | * @param string $field
28 | * @param int|string $value
29 | *
30 | * @return bool
31 | */
32 | public function delete(string $field, $value): bool
33 | {
34 | return $this->deleteBy($field, $value, 'delete');
35 | }
36 |
37 | /**
38 | * @param string $field
39 | * @param int|string $value
40 | *
41 | * @return Struct\DataInfo
42 | */
43 | public function get(string $field, $value): Struct\DataInfo
44 | {
45 | $items = $this->getAll($field, $value);
46 |
47 | return reset($items);
48 | }
49 |
50 | /**
51 | * @param string $field
52 | * @param int|string $value
53 | *
54 | * @return Struct\DataInfo[]
55 | */
56 | public function getAll(string $field, $value): array
57 | {
58 | $response = $this->getBy('get', $field, $value);
59 | $items = [];
60 | foreach ((array) $response->xpath('//result/data') as $xmlResult) {
61 | if (!$xmlResult) {
62 | continue;
63 | }
64 | $items[] = new Struct\DataInfo($xmlResult);
65 | }
66 |
67 | return $items;
68 | }
69 |
70 | /**
71 | * @param Struct\Info $protectedDirectory
72 | * @param string $login
73 | * @param string $password
74 | *
75 | * @return Struct\UserInfo
76 | * @psalm-suppress UndefinedPropertyAssignment
77 | */
78 | public function addUser($protectedDirectory, $login, $password)
79 | {
80 | $packet = $this->client->getPacket();
81 | $info = $packet->addChild($this->wrapperTag)->addChild('add-user');
82 |
83 | $info->{'pd-id'} = (string) $protectedDirectory->id;
84 | $info->login = $login;
85 | $info->password = $password;
86 |
87 | return new Struct\UserInfo($this->client->request($packet));
88 | }
89 |
90 | /**
91 | * @param string $field
92 | * @param int|string $value
93 | *
94 | * @return bool
95 | */
96 | public function deleteUser($field, $value)
97 | {
98 | return $this->deleteBy($field, $value, 'delete-user');
99 | }
100 |
101 | /**
102 | * @param string $command
103 | * @param string $field
104 | * @param int|string $value
105 | *
106 | * @return \PleskX\Api\XmlResponse
107 | */
108 | private function getBy(string $command, string $field, $value)
109 | {
110 | $packet = $this->client->getPacket();
111 | $getTag = $packet->addChild($this->wrapperTag)->addChild($command);
112 |
113 | $filterTag = $getTag->addChild('filter');
114 | $filterTag->{$field} = (string) $value;
115 |
116 | return $this->client->request($packet, Client::RESPONSE_FULL);
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/src/Api/Operator/Reseller.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('add')->addChild('gen-info');
14 |
15 | foreach ($properties as $name => $value) {
16 | $info->{$name} = $value;
17 | }
18 |
19 | $response = $this->client->request($packet);
20 |
21 | return new Struct\Info($response);
22 | }
23 |
24 | /**
25 | * @param string $field
26 | * @param int|string $value
27 | *
28 | * @return bool
29 | */
30 | public function delete(string $field, $value): bool
31 | {
32 | return $this->deleteBy($field, $value);
33 | }
34 |
35 | /**
36 | * @param string $field
37 | * @param int|string $value
38 | *
39 | * @return Struct\GeneralInfo
40 | */
41 | public function get(string $field, $value): Struct\GeneralInfo
42 | {
43 | $items = $this->getAll($field, $value);
44 |
45 | return reset($items);
46 | }
47 |
48 | /**
49 | * @param string $field
50 | * @param int|string $value
51 | *
52 | * @return Struct\GeneralInfo[]
53 | */
54 | public function getAll($field = null, $value = null): array
55 | {
56 | $packet = $this->client->getPacket();
57 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
58 |
59 | $filterTag = $getTag->addChild('filter');
60 | if (!is_null($field)) {
61 | $filterTag->addChild($field, (string) $value);
62 | }
63 |
64 | $datasetTag = $getTag->addChild('dataset');
65 | $datasetTag->addChild('gen-info');
66 | $datasetTag->addChild('permissions');
67 |
68 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
69 |
70 | $items = [];
71 | foreach ((array) $response->xpath('//result') as $xmlResult) {
72 | if (!$xmlResult || !$xmlResult->data) {
73 | continue;
74 | }
75 |
76 | $item = new Struct\GeneralInfo($xmlResult->data);
77 | $item->id = (int) $xmlResult->id;
78 | $items[] = $item;
79 | }
80 |
81 | return $items;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/Api/Operator/ResellerPlan.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
15 | $createTag = $packet->addChild($this->wrapperTag)->addChild('create');
16 |
17 | if ('' !== $ipAddress) {
18 | $createTag->addChild('ip_address', $ipAddress);
19 | }
20 |
21 | if ('' !== $description) {
22 | $createTag->addChild('description', $description);
23 | }
24 |
25 | $response = $this->client->request($packet);
26 |
27 | return (string) $response->key;
28 | }
29 |
30 | public function delete(string $keyId): bool
31 | {
32 | return $this->deleteBy('key', $keyId, 'delete');
33 | }
34 |
35 | public function get(string $keyId): Struct\Info
36 | {
37 | $items = $this->getBy($keyId);
38 |
39 | return reset($items);
40 | }
41 |
42 | /**
43 | * @return Struct\Info[]
44 | */
45 | public function getAll(): array
46 | {
47 | return $this->getBy();
48 | }
49 |
50 | /**
51 | * @param string|null $keyId
52 | *
53 | * @return Struct\Info[]
54 | */
55 | public function getBy($keyId = null): array
56 | {
57 | $packet = $this->client->getPacket();
58 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get_info');
59 |
60 | $filterTag = $getTag->addChild('filter');
61 | if (!is_null($keyId)) {
62 | $filterTag->addChild('key', $keyId);
63 | }
64 |
65 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
66 |
67 | $items = [];
68 | foreach ((array) $response->xpath('//result/key_info') as $keyInfo) {
69 | if (!$keyInfo) {
70 | continue;
71 | }
72 | $items[] = new Struct\Info($keyInfo);
73 | }
74 |
75 | return $items;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Api/Operator/Server.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
14 | $packet->addChild($this->wrapperTag)->addChild('get_protos');
15 | $response = $this->client->request($packet);
16 |
17 | /** @psalm-suppress PossiblyNullPropertyFetch */
18 | return (array) $response->protos->proto;
19 | }
20 |
21 | public function getGeneralInfo(): Struct\GeneralInfo
22 | {
23 | return new Struct\GeneralInfo($this->getInfo('gen_info'));
24 | }
25 |
26 | public function getPreferences(): Struct\Preferences
27 | {
28 | return new Struct\Preferences($this->getInfo('prefs'));
29 | }
30 |
31 | public function getAdmin(): Struct\Admin
32 | {
33 | return new Struct\Admin($this->getInfo('admin'));
34 | }
35 |
36 | public function getKeyInfo(): array
37 | {
38 | $keyInfo = [];
39 | $keyInfoXml = $this->getInfo('key');
40 |
41 | foreach ($keyInfoXml->property ?? [] as $property) {
42 | $keyInfo[(string) $property->name] = (string) $property->value;
43 | }
44 |
45 | return $keyInfo;
46 | }
47 |
48 | public function getComponents(): array
49 | {
50 | $components = [];
51 | $componentsXml = $this->getInfo('components');
52 |
53 | foreach ($componentsXml->component ?? [] as $component) {
54 | $components[(string) $component->name] = (string) $component->version;
55 | }
56 |
57 | return $components;
58 | }
59 |
60 | public function getServiceStates(): array
61 | {
62 | $states = [];
63 | $statesXml = $this->getInfo('services_state');
64 |
65 | foreach ($statesXml->srv ?? [] as $service) {
66 | $states[(string) $service->id] = [
67 | 'id' => (string) $service->id,
68 | 'title' => (string) $service->title,
69 | 'state' => (string) $service->state,
70 | ];
71 | }
72 |
73 | return $states;
74 | }
75 |
76 | public function getSessionPreferences(): Struct\SessionPreferences
77 | {
78 | return new Struct\SessionPreferences($this->getInfo('session_setup'));
79 | }
80 |
81 | public function getShells(): array
82 | {
83 | $shells = [];
84 | $shellsXml = $this->getInfo('shells');
85 |
86 | foreach ($shellsXml->shell ?? [] as $shell) {
87 | $shells[(string) $shell->name] = (string) $shell->path;
88 | }
89 |
90 | return $shells;
91 | }
92 |
93 | public function getNetworkInterfaces(): array
94 | {
95 | $interfacesXml = $this->getInfo('interfaces');
96 |
97 | return (array) $interfacesXml->interface;
98 | }
99 |
100 | public function getStatistics(): Struct\Statistics
101 | {
102 | return new Struct\Statistics($this->getInfo('stat'));
103 | }
104 |
105 | public function getSiteIsolationConfig(): array
106 | {
107 | $config = [];
108 | $configXml = $this->getInfo('site-isolation-config');
109 |
110 | foreach ($configXml->property ?? [] as $property) {
111 | $config[(string) $property->name] = (string) $property->value;
112 | }
113 |
114 | return $config;
115 | }
116 |
117 | public function getUpdatesInfo(): Struct\UpdatesInfo
118 | {
119 | return new Struct\UpdatesInfo($this->getInfo('updates'));
120 | }
121 |
122 | public function createSession(string $login, string $clientIp): string
123 | {
124 | $packet = $this->client->getPacket();
125 | $sessionNode = $packet->addChild($this->wrapperTag)->addChild('create_session');
126 | $sessionNode->addChild('login', $login);
127 | $dataNode = $sessionNode->addChild('data');
128 | $dataNode->addChild('user_ip', base64_encode($clientIp));
129 | $dataNode->addChild('source_server');
130 | $response = $this->client->request($packet);
131 |
132 | return (string) $response->id;
133 | }
134 |
135 | private function getInfo(string $operation): XmlResponse
136 | {
137 | $packet = $this->client->getPacket();
138 | $packet->addChild($this->wrapperTag)->addChild('get')->addChild($operation);
139 | $response = $this->client->request($packet);
140 |
141 | return $response->$operation;
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/src/Api/Operator/ServicePlan.php:
--------------------------------------------------------------------------------
1 | request(['add' => $properties]);
13 |
14 | return new Struct\Info($response);
15 | }
16 |
17 | /**
18 | * @param string $field
19 | * @param int|string $value
20 | *
21 | * @return bool
22 | */
23 | public function delete(string $field, $value): bool
24 | {
25 | return $this->deleteBy($field, $value);
26 | }
27 |
28 | /**
29 | * @param string $field
30 | * @param int|string $value
31 | *
32 | * @return Struct\Info
33 | */
34 | public function get(string $field, $value): Struct\Info
35 | {
36 | $items = $this->getBy($field, $value);
37 |
38 | return reset($items);
39 | }
40 |
41 | /**
42 | * @return Struct\Info[]
43 | */
44 | public function getAll(): array
45 | {
46 | return $this->getBy();
47 | }
48 |
49 | /**
50 | * @param string|null $field
51 | * @param int|string|null $value
52 | *
53 | * @return Struct\Info[]
54 | */
55 | private function getBy($field = null, $value = null): array
56 | {
57 | $packet = $this->client->getPacket();
58 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
59 |
60 | $filterTag = $getTag->addChild('filter');
61 | if (!is_null($field)) {
62 | $filterTag->addChild($field, (string) $value);
63 | }
64 |
65 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
66 |
67 | $items = [];
68 | foreach ((array) $response->xpath('//result') as $xmlResult) {
69 | if (!$xmlResult) {
70 | continue;
71 | }
72 | $items[] = new Struct\Info($xmlResult);
73 | }
74 |
75 | return $items;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Api/Operator/ServicePlanAddon.php:
--------------------------------------------------------------------------------
1 | request(['add' => $properties]);
13 |
14 | return new Struct\Info($response);
15 | }
16 |
17 | /**
18 | * @param string $field
19 | * @param int|string $value
20 | *
21 | * @return bool
22 | */
23 | public function delete(string $field, $value): bool
24 | {
25 | return $this->deleteBy($field, $value);
26 | }
27 |
28 | /**
29 | * @param string $field
30 | * @param int|string $value
31 | *
32 | * @return Struct\Info
33 | */
34 | public function get(string $field, $value): Struct\Info
35 | {
36 | $items = $this->getBy($field, $value);
37 |
38 | return reset($items);
39 | }
40 |
41 | /**
42 | * @return Struct\Info[]
43 | */
44 | public function getAll(): array
45 | {
46 | return $this->getBy();
47 | }
48 |
49 | /**
50 | * @param string|null $field
51 | * @param int|string|null $value
52 | *
53 | * @return Struct\Info[]
54 | */
55 | private function getBy($field = null, $value = null): array
56 | {
57 | $packet = $this->client->getPacket();
58 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
59 |
60 | $filterTag = $getTag->addChild('filter');
61 | if (!is_null($field)) {
62 | $filterTag->addChild($field, (string) $value);
63 | }
64 |
65 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
66 |
67 | $items = [];
68 | foreach ((array) $response->xpath('//result') as $xmlResult) {
69 | if (!$xmlResult) {
70 | continue;
71 | }
72 | $items[] = new Struct\Info($xmlResult);
73 | }
74 |
75 | return $items;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Api/Operator/Session.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $creator = $packet->addChild('server')->addChild('create_session');
14 |
15 | $creator->addChild('login', $username);
16 | $loginData = $creator->addChild('data');
17 |
18 | $loginData->addChild('user_ip', base64_encode($userIp));
19 | $loginData->addChild('source_server', '');
20 |
21 | $response = $this->client->request($packet);
22 |
23 | return (string) $response->id;
24 | }
25 |
26 | /**
27 | * @return Struct\Info[]
28 | */
29 | public function get(): array
30 | {
31 | $sessions = [];
32 | $response = $this->request('get');
33 |
34 | foreach ($response->session ?? [] as $sessionInfo) {
35 | $sessions[(string) $sessionInfo->id] = new Struct\Info($sessionInfo);
36 | }
37 |
38 | return $sessions;
39 | }
40 |
41 | public function terminate(string $sessionId): bool
42 | {
43 | $response = $this->request("terminate.session-id=$sessionId");
44 |
45 | return 'ok' === (string) $response->status;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Api/Operator/Site.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
15 | $info = $packet->addChild($this->wrapperTag)->addChild('add');
16 |
17 | $infoGeneral = $info->addChild('gen_setup');
18 | foreach ($properties as $name => $value) {
19 | if (!is_scalar($value)) {
20 | continue;
21 | }
22 | $infoGeneral->{$name} = (string) $value;
23 | }
24 |
25 | // set hosting properties
26 | if (isset($properties[static::PROPERTIES_HOSTING]) && is_array($properties[static::PROPERTIES_HOSTING])) {
27 | $hostingNode = $info->addChild('hosting')->addChild('vrt_hst');
28 | foreach ($properties[static::PROPERTIES_HOSTING] as $name => $value) {
29 | $propertyNode = $hostingNode->addChild('property');
30 | /** @psalm-suppress UndefinedPropertyAssignment */
31 | $propertyNode->name = $name;
32 | /** @psalm-suppress UndefinedPropertyAssignment */
33 | $propertyNode->value = $value;
34 | }
35 | }
36 |
37 | $response = $this->client->request($packet);
38 |
39 | return new Struct\Info($response);
40 | }
41 |
42 | /**
43 | * @param string $field
44 | * @param int|string $value
45 | *
46 | * @return bool
47 | */
48 | public function delete(string $field, $value): bool
49 | {
50 | return $this->deleteBy($field, $value);
51 | }
52 |
53 | /**
54 | * @param string $field
55 | * @param int|string $value
56 | *
57 | * @return ?Struct\GeneralInfo
58 | */
59 | public function get(string $field, $value): ?Struct\GeneralInfo
60 | {
61 | $items = $this->getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
62 |
63 | return reset($items) ?: null;
64 | }
65 |
66 | /**
67 | * @param string $field
68 | * @param int|string $value
69 | *
70 | * @return Struct\HostingInfo|null
71 | */
72 | public function getHosting(string $field, $value): ?Struct\HostingInfo
73 | {
74 | $items = $this->getItems(
75 | Struct\HostingInfo::class,
76 | 'hosting',
77 | $field,
78 | $value,
79 | function (\SimpleXMLElement $node) {
80 | return isset($node->vrt_hst);
81 | }
82 | );
83 |
84 | return empty($items) ? null : reset($items);
85 | }
86 |
87 | /**
88 | * @return Struct\GeneralInfo[]
89 | */
90 | public function getAll(): array
91 | {
92 | return $this->getItems(Struct\GeneralInfo::class, 'gen_info');
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/Api/Operator/SiteAlias.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('create');
14 |
15 | if (count($preferences) > 0) {
16 | $prefs = $info->addChild('pref');
17 |
18 | foreach ($preferences as $key => $value) {
19 | $prefs->addChild($key, is_bool($value) ? ($value ? '1' : '0') : $value);
20 | }
21 | }
22 |
23 | $info->addChild('site-id', $properties['site-id']);
24 | $info->addChild('name', $properties['name']);
25 |
26 | $response = $this->client->request($packet);
27 |
28 | return new Struct\Info($response);
29 | }
30 |
31 | /**
32 | * @param string $field
33 | * @param int|string $value
34 | *
35 | * @return bool
36 | */
37 | public function delete(string $field, $value): bool
38 | {
39 | return $this->deleteBy($field, $value, 'delete');
40 | }
41 |
42 | /**
43 | * @param string $field
44 | * @param int|string $value
45 | *
46 | * @return Struct\GeneralInfo
47 | */
48 | public function get(string $field, $value): Struct\GeneralInfo
49 | {
50 | $items = $this->getAll($field, $value);
51 |
52 | return reset($items);
53 | }
54 |
55 | /**
56 | * @param string $field
57 | * @param int|string $value
58 | *
59 | * @return Struct\GeneralInfo[]
60 | */
61 | public function getAll($field = null, $value = null): array
62 | {
63 | $packet = $this->client->getPacket();
64 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
65 |
66 | $filterTag = $getTag->addChild('filter');
67 | if (!is_null($field)) {
68 | $filterTag->{$field} = (string) $value;
69 | }
70 |
71 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
72 | $items = [];
73 | foreach ((array) $response->xpath('//result') as $xmlResult) {
74 | if (!$xmlResult) {
75 | continue;
76 | }
77 | if (!is_null($xmlResult->info)) {
78 | $item = new Struct\GeneralInfo($xmlResult->info);
79 | $items[] = $item;
80 | }
81 | }
82 |
83 | return $items;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/Api/Operator/Subdomain.php:
--------------------------------------------------------------------------------
1 | client->getPacket();
13 | $info = $packet->addChild($this->wrapperTag)->addChild('add');
14 |
15 | foreach ($properties as $name => $value) {
16 | if (is_array($value)) {
17 | foreach ($value as $propertyName => $propertyValue) {
18 | $property = $info->addChild($name);
19 | /** @psalm-suppress UndefinedPropertyAssignment */
20 | $property->name = $propertyName;
21 | /** @psalm-suppress UndefinedPropertyAssignment */
22 | $property->value = $propertyValue;
23 | }
24 | continue;
25 | }
26 | $info->{$name} = $value;
27 | }
28 |
29 | $response = $this->client->request($packet);
30 |
31 | return new Struct\Info($response);
32 | }
33 |
34 | /**
35 | * @param string $field
36 | * @param int|string $value
37 | *
38 | * @return bool
39 | */
40 | public function delete(string $field, $value): bool
41 | {
42 | return $this->deleteBy($field, $value);
43 | }
44 |
45 | /**
46 | * @param string $field
47 | * @param int|string $value
48 | *
49 | * @return Struct\Info
50 | */
51 | public function get(string $field, $value): Struct\Info
52 | {
53 | $items = $this->getAll($field, $value);
54 |
55 | return reset($items);
56 | }
57 |
58 | /**
59 | * @param string $field
60 | * @param int|string $value
61 | *
62 | * @return Struct\Info[]
63 | */
64 | public function getAll($field = null, $value = null): array
65 | {
66 | $packet = $this->client->getPacket();
67 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
68 |
69 | $filterTag = $getTag->addChild('filter');
70 | if (!is_null($field)) {
71 | $filterTag->addChild($field, (string) $value);
72 | }
73 |
74 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
75 |
76 | $items = [];
77 | foreach ((array) $response->xpath('//result') as $xmlResult) {
78 | if (!$xmlResult || empty($xmlResult->data)) {
79 | continue;
80 | }
81 | $item = new Struct\Info($xmlResult->data);
82 | $item->id = (int) $xmlResult->id;
83 | $items[] = $item;
84 | }
85 |
86 | return $items;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/Api/Operator/Ui.php:
--------------------------------------------------------------------------------
1 | request('get-navigation');
13 |
14 | /** @psalm-suppress ImplicitToStringCast, PossiblyNullArgument */
15 | return unserialize(base64_decode($response->navigation));
16 | }
17 |
18 | public function createCustomButton(string $owner, array $properties): int
19 | {
20 | $packet = $this->client->getPacket();
21 | $buttonNode = $packet->addChild($this->wrapperTag)->addChild('create-custombutton');
22 | $buttonNode->addChild('owner')->addChild($owner);
23 | $propertiesNode = $buttonNode->addChild('properties');
24 |
25 | foreach ($properties as $name => $value) {
26 | $propertiesNode->{$name} = $value;
27 | }
28 |
29 | $response = $this->client->request($packet);
30 |
31 | return (int) $response->id;
32 | }
33 |
34 | public function getCustomButton(int $id): Struct\CustomButton
35 | {
36 | $response = $this->request("get-custombutton.filter.custombutton-id=$id");
37 |
38 | return new Struct\CustomButton($response);
39 | }
40 |
41 | public function deleteCustomButton(int $id): bool
42 | {
43 | return $this->deleteBy('custombutton-id', $id, 'delete-custombutton');
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Api/Operator/VirtualDirectory.php:
--------------------------------------------------------------------------------
1 | request('get-permission-descriptor.filter');
14 |
15 | return new Struct\PermissionDescriptor($response);
16 | }
17 |
18 | public function getLimitDescriptor(): Struct\LimitDescriptor
19 | {
20 | $response = $this->request('get-limit-descriptor.filter');
21 |
22 | return new Struct\LimitDescriptor($response);
23 | }
24 |
25 | public function getPhysicalHostingDescriptor(): Struct\PhysicalHostingDescriptor
26 | {
27 | $response = $this->request('get-physical-hosting-descriptor.filter');
28 |
29 | return new Struct\PhysicalHostingDescriptor($response);
30 | }
31 |
32 | /**
33 | * @param string $field
34 | * @param int|string $value
35 | *
36 | * @return Struct\PhpSettings
37 | */
38 | public function getPhpSettings(string $field, $value): Struct\PhpSettings
39 | {
40 | $packet = $this->client->getPacket();
41 | $getTag = $packet->addChild($this->wrapperTag)->addChild('get');
42 |
43 | $getTag->addChild('filter')->addChild($field, (string) $value);
44 | $getTag->addChild('dataset')->addChild('php-settings');
45 |
46 | $response = $this->client->request($packet, \PleskX\Api\Client::RESPONSE_FULL);
47 |
48 | return new Struct\PhpSettings($response);
49 | }
50 |
51 | /**
52 | * @param string $field
53 | * @param int|string $value
54 | *
55 | * @return Struct\Limits
56 | */
57 | public function getLimits(string $field, $value): Struct\Limits
58 | {
59 | $items = $this->getItems(Struct\Limits::class, 'limits', $field, $value);
60 |
61 | return reset($items);
62 | }
63 |
64 | /**
65 | * @param array $properties
66 | * @param array|null $hostingProperties
67 | * @param string $planName
68 | *
69 | * @return Struct\Info
70 | */
71 | public function create(array $properties, ?array $hostingProperties = null, string $planName = ''): Struct\Info
72 | {
73 | $packet = $this->client->getPacket();
74 | $info = $packet->addChild($this->wrapperTag)->addChild('add');
75 |
76 | $infoGeneral = $info->addChild('gen_setup');
77 | foreach ($properties as $name => $value) {
78 | if (is_array($value)) {
79 | continue;
80 | } else {
81 | $infoGeneral->addChild($name, (string) $value);
82 | }
83 | }
84 |
85 | if ($hostingProperties) {
86 | $infoHosting = $info->addChild('hosting')->addChild('vrt_hst');
87 | foreach ($hostingProperties as $name => $value) {
88 | $property = $infoHosting->addChild('property');
89 | /** @psalm-suppress UndefinedPropertyAssignment */
90 | $property->name = $name;
91 | /** @psalm-suppress UndefinedPropertyAssignment */
92 | $property->value = $value;
93 | }
94 |
95 | if (isset($properties['ip_address'])) {
96 | foreach ((array) $properties['ip_address'] as $ipAddress) {
97 | $infoHosting->addChild('ip_address', $ipAddress);
98 | }
99 | }
100 | }
101 |
102 | if ('' !== $planName) {
103 | $info->addChild('plan-name', $planName);
104 | }
105 |
106 | $response = $this->client->request($packet);
107 |
108 | return new Struct\Info($response, $properties['name'] ?? '');
109 | }
110 |
111 | /**
112 | * @param string $field
113 | * @param int|string $value
114 | *
115 | * @return bool
116 | */
117 | public function delete(string $field, $value): bool
118 | {
119 | return $this->deleteBy($field, $value);
120 | }
121 |
122 | /**
123 | * @param string $field
124 | * @param int|string $value
125 | *
126 | * @return Struct\GeneralInfo
127 | */
128 | public function get(string $field, $value): Struct\GeneralInfo
129 | {
130 | $items = $this->getItems(Struct\GeneralInfo::class, 'gen_info', $field, $value);
131 |
132 | return reset($items);
133 | }
134 |
135 | /**
136 | * @return Struct\GeneralInfo[]
137 | */
138 | public function getAll(): array
139 | {
140 | return $this->getItems(Struct\GeneralInfo::class, 'gen_info');
141 | }
142 |
143 | /**
144 | * @param string $field
145 | * @param int|string $value
146 | *
147 | * @return Struct\DiskUsage
148 | */
149 | public function getDiskUsage(string $field, $value): Struct\DiskUsage
150 | {
151 | $items = $this->getItems(Struct\DiskUsage::class, 'disk_usage', $field, $value);
152 |
153 | return reset($items);
154 | }
155 |
156 | /**
157 | * @param string $field
158 | * @param int|string $value
159 | *
160 | * @return bool
161 | */
162 | public function enable(string $field, $value): bool
163 | {
164 | return $this->setProperties($field, $value, ['status' => 0]);
165 | }
166 |
167 | /**
168 | * @param string $field
169 | * @param int|string $value
170 | *
171 | * @return bool
172 | */
173 | public function disable(string $field, $value): bool
174 | {
175 | return $this->setProperties($field, $value, ['status' => 16]);
176 | }
177 |
178 | /**
179 | * @param string $field
180 | * @param int|string $value
181 | * @param array $properties
182 | *
183 | * @return bool
184 | */
185 | public function setProperties(string $field, $value, array $properties): bool
186 | {
187 | $packet = $this->client->getPacket();
188 | $setTag = $packet->addChild($this->wrapperTag)->addChild('set');
189 | $setTag->addChild('filter')->addChild($field, (string) $value);
190 | $genInfoTag = $setTag->addChild('values')->addChild('gen_setup');
191 | foreach ($properties as $property => $propertyValue) {
192 | $genInfoTag->addChild($property, (string) $propertyValue);
193 | }
194 |
195 | $response = $this->client->request($packet);
196 |
197 | return 'ok' === (string) $response->status;
198 | }
199 | }
200 |
--------------------------------------------------------------------------------
/src/Api/Struct/Certificate/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($input, [
19 | ['csr' => 'request'],
20 | ['pvt' => 'privateKey'],
21 | ]);
22 | } else {
23 | foreach ($input as $name => $value) {
24 | $this->$name = $value;
25 | }
26 | }
27 | }
28 |
29 | public function getMapping(): array
30 | {
31 | return array_filter([
32 | 'csr' => $this->request,
33 | 'pvt' => $this->privateKey,
34 | 'cert' => $this->publicKey,
35 | 'ca' => $this->publicKeyCA,
36 | ]);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Api/Struct/Customer/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
30 | ['cname' => 'company'],
31 | ['pname' => 'personalName'],
32 | 'login',
33 | 'guid',
34 | 'email',
35 | 'phone',
36 | 'fax',
37 | 'address',
38 | ['pcode' => 'postalCode'],
39 | 'city',
40 | 'state',
41 | 'country',
42 | 'external-id',
43 | 'description',
44 | ]);
45 |
46 | $this->enabled = '0' === (string) $apiResponse->status;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Api/Struct/Customer/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'id',
17 | 'guid',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Database/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
20 | 'id',
21 | 'name',
22 | 'type',
23 | 'webspace-id',
24 | 'db-server-id',
25 | 'default-user-id',
26 | ]);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Api/Struct/Database/UserInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'id',
18 | 'login',
19 | 'db-id',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/DatabaseServer/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'id',
19 | 'host',
20 | 'port',
21 | 'type',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/Dns/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
21 | 'id',
22 | 'site-id',
23 | 'site-alias-id',
24 | 'type',
25 | 'host',
26 | 'value',
27 | 'opt',
28 | ]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Api/Struct/EventLog/DetailedEvent.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
21 | 'id',
22 | 'type',
23 | 'time',
24 | 'class',
25 | ['obj_id' => 'objectId'],
26 | 'user',
27 | 'host',
28 | ]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Api/Struct/EventLog/Event.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'type',
19 | 'time',
20 | 'class',
21 | 'id',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/Ip/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'ip_address',
19 | 'netmask',
20 | 'type',
21 | 'interface',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/Locale/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'id',
18 | ['lang' => 'language'],
19 | 'country',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Mail/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'id',
18 | 'name',
19 | 'description',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Mail/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'id',
17 | 'name',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/PhpHandler/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
24 | 'id',
25 | 'display-name',
26 | 'full-version',
27 | 'version',
28 | 'type',
29 | 'path',
30 | 'clipath',
31 | 'phpini',
32 | 'custom',
33 | 'handler-status',
34 | ]);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Api/Struct/ProtectedDirectory/DataInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'name',
17 | 'header',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/ProtectedDirectory/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
15 | 'id',
16 | ]);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Api/Struct/ProtectedDirectory/UserInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
15 | 'id',
16 | ]);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Api/Struct/Reseller/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | {'gen-info'})) {
18 | $this->initScalarProperties($apiResponse->{'gen-info'}, [
19 | ['pname' => 'personalName'],
20 | 'login',
21 | ]);
22 | }
23 |
24 | $this->permissions = [];
25 | foreach ($apiResponse->permissions->permission ?? [] as $permissionInfo) {
26 | $this->permissions[(string) $permissionInfo->name] = (string) $permissionInfo->value;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Api/Struct/Reseller/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'id',
17 | 'guid',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/SecretKey/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'key',
19 | 'ip_address',
20 | 'description',
21 | 'login',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Admin.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | ['admin_cname' => 'companyName'],
18 | ['admin_pname' => 'name'],
19 | ['admin_email' => 'email'],
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'server_name',
18 | 'server_guid',
19 | 'mode',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Preferences.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'stat_ttl',
18 | 'traffic_accounting',
19 | 'restart_apache_interval',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/SessionPreferences.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
15 | 'login_timeout',
16 | ]);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics.php:
--------------------------------------------------------------------------------
1 | objects = new Statistics\Objects($apiResponse->objects);
38 | $this->version = new Statistics\Version($apiResponse->version);
39 | $this->other = new Statistics\Other($apiResponse->other);
40 | $this->loadAverage = new Statistics\LoadAverage($apiResponse->load_avg);
41 | $this->memory = new Statistics\Memory($apiResponse->mem);
42 | $this->swap = new Statistics\Swap($apiResponse->swap);
43 |
44 | $this->diskSpace = [];
45 | foreach ($apiResponse->diskspace ?? [] as $disk) {
46 | $this->diskSpace[(string) $disk->device->name] = new Statistics\DiskSpace($disk->device);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/DiskSpace.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'total',
18 | 'used',
19 | 'free',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/LoadAverage.php:
--------------------------------------------------------------------------------
1 | load1min = (float) $apiResponse->l1 / 100.0;
17 | $this->load5min = (float) $apiResponse->l5 / 100.0;
18 | $this->load15min = (float) $apiResponse->l15 / 100.0;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/Memory.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
20 | 'total',
21 | 'used',
22 | 'free',
23 | 'shared',
24 | 'buffer',
25 | 'cached',
26 | ]);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/Objects.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
25 | 'clients',
26 | 'domains',
27 | 'databases',
28 | ['active_domains' => 'activeDomains'],
29 | ['mail_boxes' => 'mailBoxes'],
30 | ['mail_redirects' => 'mailRedirects'],
31 | ['mail_groups' => 'mailGroups'],
32 | ['mail_responders' => 'mailResponders'],
33 | ['database_users' => 'databaseUsers'],
34 | ['problem_clients' => 'problemClients'],
35 | ['problem_domains' => 'problemDomains'],
36 | ]);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/Other.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'cpu',
18 | 'uptime',
19 | ['inside_vz' => 'insideVz'],
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/Swap.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'total',
18 | 'used',
19 | 'free',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/Statistics/Version.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
20 | ['plesk_name' => 'internalName'],
21 | ['plesk_version' => 'version'],
22 | ['plesk_build' => 'build'],
23 | ['plesk_os' => 'osName'],
24 | ['plesk_os_version' => 'osVersion'],
25 | ['os_release' => 'osRelease'],
26 | ]);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Api/Struct/Server/UpdatesInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'last_installed_update',
17 | 'install_updates_automatically',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/ServicePlan/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'id',
19 | 'name',
20 | 'guid',
21 | 'external-id',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/ServicePlanAddon/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
18 | 'id',
19 | 'name',
20 | 'guid',
21 | 'external-id',
22 | ]);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Api/Struct/Session/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
20 | 'id',
21 | 'type',
22 | 'ip-address',
23 | 'login',
24 | 'login-time',
25 | 'idle',
26 | ]);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Api/Struct/Site/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
25 | ['cr_date' => 'creationDate'],
26 | 'name',
27 | 'ascii-name',
28 | 'status',
29 | 'real_size',
30 | 'guid',
31 | 'description',
32 | 'webspace-guid',
33 | 'webspace-id',
34 | ]);
35 |
36 | foreach ($apiResponse->dns_ip_address ?? [] as $ip) {
37 | $this->ipAddresses[] = (string) $ip;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Api/Struct/Site/HostingInfo.php:
--------------------------------------------------------------------------------
1 | vrt_hst->property ?? [] as $property) {
16 | $this->properties[(string) $property->name] = (string) $property->value;
17 | }
18 |
19 | if (!is_null($apiResponse->vrt_hst)) {
20 | $this->initScalarProperties($apiResponse->vrt_hst, [
21 | 'ip_address',
22 | ]);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Api/Struct/Site/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'id',
17 | 'guid',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/SiteAlias/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'name',
18 | 'ascii-name',
19 | 'status',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/SiteAlias/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'id',
17 | 'status',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Subdomain/Info.php:
--------------------------------------------------------------------------------
1 | properties = [];
18 | $this->initScalarProperties($apiResponse, [
19 | 'id',
20 | 'parent',
21 | 'name',
22 | ]);
23 | foreach ($apiResponse->property ?? [] as $propertyInfo) {
24 | $this->properties[(string) $propertyInfo->name] = (string) $propertyInfo->value;
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Api/Struct/Ui/CustomButton.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, ['id']);
22 |
23 | if (!is_null($apiResponse->properties)) {
24 | $this->initScalarProperties($apiResponse->properties, [
25 | 'sort_key',
26 | 'public',
27 | 'internal',
28 | ['noframe' => 'noFrame'],
29 | 'place',
30 | 'url',
31 | 'text',
32 | ]);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/DiskUsage.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
25 | 'httpdocs',
26 | 'httpsdocs',
27 | 'subdomains',
28 | 'anonftp',
29 | 'logs',
30 | 'dbases',
31 | 'mailboxes',
32 | 'maillists',
33 | 'domaindumps',
34 | 'configs',
35 | 'chroot',
36 | ]);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/GeneralInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
27 | ['cr_date' => 'creationDate'],
28 | 'name',
29 | 'ascii-name',
30 | 'status',
31 | 'real_size',
32 | 'owner-id',
33 | 'guid',
34 | 'vendor-guid',
35 | 'description',
36 | 'admin-description',
37 | ]);
38 |
39 | foreach ($apiResponse->dns_ip_address ?? [] as $ip) {
40 | $this->ipAddresses[] = (string) $ip;
41 | }
42 |
43 | $this->enabled = '0' === (string) $apiResponse->status;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/HostingPropertyInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'name',
18 | 'type',
19 | 'label',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/Info.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'id',
18 | 'guid',
19 | ]);
20 | $this->name = $name;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/Limit.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
16 | 'name',
17 | 'value',
18 | ]);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/LimitDescriptor.php:
--------------------------------------------------------------------------------
1 | limits = [];
15 |
16 | foreach ($apiResponse->descriptor->property ?? [] as $propertyInfo) {
17 | $this->limits[(string) $propertyInfo->name] = new LimitInfo($propertyInfo);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/LimitInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'name',
18 | 'type',
19 | 'label',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/Limits.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, ['overuse']);
16 | $this->limits = [];
17 |
18 | foreach ($apiResponse->limit ?? [] as $limit) {
19 | $this->limits[(string) $limit->name] = new Limit($limit);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/PermissionDescriptor.php:
--------------------------------------------------------------------------------
1 | permissions = [];
15 |
16 | foreach ($apiResponse->descriptor->property ?? [] as $propertyInfo) {
17 | $this->permissions[(string) $propertyInfo->name] = new PermissionInfo($propertyInfo);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/PermissionInfo.php:
--------------------------------------------------------------------------------
1 | initScalarProperties($apiResponse, [
17 | 'name',
18 | 'type',
19 | 'label',
20 | ]);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/PhpSettings.php:
--------------------------------------------------------------------------------
1 | properties = [];
15 |
16 | foreach ($apiResponse->webspace->get->result->data->{'php-settings'}->setting ?? [] as $setting) {
17 | $this->properties[(string) $setting->name] = (string) $setting->value;
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/Struct/Webspace/PhysicalHostingDescriptor.php:
--------------------------------------------------------------------------------
1 | properties = [];
15 |
16 | foreach ($apiResponse->descriptor->property ?? [] as $propertyInfo) {
17 | $this->properties[(string) $propertyInfo->name] = new HostingPropertyInfo($propertyInfo);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Api/XmlResponse.php:
--------------------------------------------------------------------------------
1 | xpath('//' . $node);
21 | if (is_array($result) && isset($result[0])) {
22 | return (string) $result[0];
23 | }
24 |
25 | return '';
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/AbstractTestCase.php:
--------------------------------------------------------------------------------
1 | setCredentials($login, $password);
34 |
35 | $proxy = getenv('REMOTE_PROXY');
36 | if ($proxy) {
37 | static::$client->setProxy($proxy);
38 | }
39 | }
40 |
41 | public static function tearDownAfterClass(): void
42 | {
43 | foreach (self::$webspaces as $webspace) {
44 | try {
45 | static::$client->webspace()->delete('id', $webspace->id);
46 | // phpcs:ignore
47 | } catch (\Exception $e) {
48 | }
49 | }
50 |
51 | foreach (self::$servicePlans as $servicePlan) {
52 | try {
53 | static::$client->servicePlan()->delete('id', $servicePlan->id);
54 | // phpcs:ignore
55 | } catch (\Exception $e) {
56 | }
57 | }
58 |
59 | foreach (self::$servicePlanAddons as $servicePlanAddon) {
60 | try {
61 | static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
62 | // phpcs:ignore
63 | } catch (\Exception $e) {
64 | }
65 | }
66 | }
67 |
68 | protected static function getIpAddress(): string
69 | {
70 | $ips = static::$client->ip()->get();
71 | $ipInfo = reset($ips);
72 |
73 | return $ipInfo->ipAddress;
74 | }
75 |
76 | protected static function createWebspace(): \PleskX\Api\Struct\Webspace\Info
77 | {
78 | $id = uniqid();
79 | $webspace = static::$client->webspace()->create(
80 | [
81 | 'name' => "test{$id}.test",
82 | 'ip_address' => static::getIpAddress(),
83 | ],
84 | [
85 | 'ftp_login' => "u{$id}",
86 | 'ftp_password' => PasswordProvider::STRONG_PASSWORD,
87 | ]
88 | );
89 | self::$webspaces[] = $webspace;
90 |
91 | return $webspace;
92 | }
93 |
94 | protected static function createServicePlan(): \PleskX\Api\Struct\ServicePlan\Info
95 | {
96 | $id = uniqid();
97 | $servicePlan = static::$client->servicePlan()->create(['name' => "test{$id}plan"]);
98 |
99 | self::$servicePlans[] = $servicePlan;
100 |
101 | return $servicePlan;
102 | }
103 |
104 | protected static function createServicePlanAddon(): \PleskX\Api\Struct\ServicePlanAddon\Info
105 | {
106 | $id = uniqid();
107 | $servicePlanAddon = static::$client->servicePlanAddon()->create(['name' => "test{$id}planaddon"]);
108 |
109 | self::$servicePlanAddons[] = $servicePlanAddon;
110 |
111 | return $servicePlanAddon;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/tests/ApiClientTest.php:
--------------------------------------------------------------------------------
1 | expectException(\PleskX\Api\Exception::class);
13 | $this->expectExceptionCode(1005);
14 |
15 | $packet = static::$client->getPacket('100.0.0');
16 | $packet->addChild('server')->addChild('get_protos');
17 | static::$client->request($packet);
18 | }
19 |
20 | public function testUnknownOperator()
21 | {
22 | $this->expectException(\PleskX\Api\Exception::class);
23 | $this->expectExceptionCode(1014);
24 |
25 | $packet = static::$client->getPacket();
26 | $packet->addChild('unknown');
27 | static::$client->request($packet);
28 | }
29 |
30 | public function testInvalidXmlRequest()
31 | {
32 | $this->expectException(\PleskX\Api\Exception::class);
33 | $this->expectExceptionCode(1014);
34 |
35 | static::$client->request('');
36 | }
37 |
38 | public function testInvalidCredentials()
39 | {
40 | $this->expectException(\PleskX\Api\Exception::class);
41 | $this->expectExceptionCode(1001);
42 |
43 | $host = static::$client->getHost();
44 | $port = static::$client->getPort();
45 | $protocol = static::$client->getProtocol();
46 | $client = new \PleskX\Api\Client($host, $port, $protocol);
47 | $client->setCredentials('bad-login', 'bad-password');
48 | $packet = static::$client->getPacket();
49 | $packet->addChild('server')->addChild('get_protos');
50 | $client->request($packet);
51 | }
52 |
53 | public function testInvalidSecretKey()
54 | {
55 | $this->expectException(\PleskX\Api\Exception::class);
56 | $this->expectExceptionCode(11003);
57 |
58 | $host = static::$client->getHost();
59 | $port = static::$client->getPort();
60 | $protocol = static::$client->getProtocol();
61 | $client = new \PleskX\Api\Client($host, $port, $protocol);
62 | $client->setSecretKey('bad-key');
63 | $packet = static::$client->getPacket();
64 | $packet->addChild('server')->addChild('get_protos');
65 | $client->request($packet);
66 | }
67 |
68 | public function testLatestMajorProtocol()
69 | {
70 | $packet = static::$client->getPacket('1.6');
71 | $packet->addChild('server')->addChild('get_protos');
72 | $result = static::$client->request($packet);
73 | $this->assertEquals('ok', $result->status);
74 | }
75 |
76 | public function testLatestMinorProtocol()
77 | {
78 | $packet = static::$client->getPacket('1.6.5');
79 | $packet->addChild('server')->addChild('get_protos');
80 | $result = static::$client->request($packet);
81 | $this->assertEquals('ok', $result->status);
82 | }
83 |
84 | public function testRequestShortSyntax()
85 | {
86 | $response = static::$client->request('server.get.gen_info');
87 | $this->assertGreaterThan(0, strlen($response->gen_info->server_name));
88 | }
89 |
90 | public function testOperatorPlainRequest()
91 | {
92 | $response = static::$client->server()->request('get.gen_info');
93 | $this->assertGreaterThan(0, strlen($response->gen_info->server_name));
94 | $this->assertEquals(36, strlen($response->getValue('server_guid')));
95 | }
96 |
97 | public function testRequestArraySyntax()
98 | {
99 | $response = static::$client->request([
100 | 'server' => [
101 | 'get' => [
102 | 'gen_info' => '',
103 | ],
104 | ],
105 | ]);
106 | $this->assertGreaterThan(0, strlen($response->gen_info->server_name));
107 | }
108 |
109 | public function testOperatorArraySyntax()
110 | {
111 | $response = static::$client->server()->request(['get' => ['gen_info' => '']]);
112 | $this->assertGreaterThan(0, strlen($response->gen_info->server_name));
113 | }
114 |
115 | public function testMultiRequest()
116 | {
117 | $responses = static::$client->multiRequest([
118 | 'server.get_protos',
119 | 'server.get.gen_info',
120 | ]);
121 |
122 | $this->assertCount(2, $responses);
123 |
124 | $protos = (array) $responses[0]->protos->proto;
125 | $generalInfo = $responses[1];
126 |
127 | $this->assertContains('1.6.6.0', $protos);
128 | $this->assertGreaterThan(0, strlen($generalInfo->gen_info->server_name));
129 | }
130 |
131 | public function testConnectionError()
132 | {
133 | $this->expectException(\PleskX\Api\Client\Exception::class);
134 |
135 | $client = new \PleskX\Api\Client('invalid-host.dom');
136 | $client->server()->getProtos();
137 | }
138 |
139 | public function testGetHost()
140 | {
141 | $client = new \PleskX\Api\Client('example.dom');
142 | $this->assertEquals('example.dom', $client->getHost());
143 | }
144 |
145 | public function testGetPort()
146 | {
147 | $client = new \PleskX\Api\Client('example.dom', 12345);
148 | $this->assertEquals(12345, $client->getPort());
149 | }
150 |
151 | public function testGetProtocol()
152 | {
153 | $client = new \PleskX\Api\Client('example.dom', 8880, 'http');
154 | $this->assertEquals('http', $client->getProtocol());
155 | }
156 |
157 | public function testSetVerifyResponse()
158 | {
159 | static::$client->setVerifyResponse(function ($xml) {
160 | if ($xml->xpath('//proto')) {
161 | throw new Exception('proto');
162 | }
163 | });
164 |
165 | try {
166 | static::$client->server()->getProtos();
167 | } catch (Exception $e) {
168 | $this->assertEquals('proto', $e->getMessage());
169 | } finally {
170 | static::$client->setVerifyResponse();
171 | }
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/tests/CertificateTest.php:
--------------------------------------------------------------------------------
1 | 2048,
12 | 'country' => 'CH',
13 | 'state' => 'Schaffhausen',
14 | 'location' => 'Schaffhausen',
15 | 'company' => 'Plesk',
16 | 'email' => 'info@plesk.com',
17 | 'name' => 'plesk.com',
18 | ];
19 | private array $distinguishedNames = [
20 | "countryName" => "CH",
21 | "stateOrProvinceName" => "Schaffhausen",
22 | "localityName" => "Schaffhausen",
23 | "organizationName" => "Plesk",
24 | "emailAddress" => "info@plesk.com"
25 | ];
26 |
27 | public function testGenerate()
28 | {
29 | $certificate = static::$client->certificate()->generate($this->certificateProperties);
30 | $this->assertGreaterThan(0, strlen($certificate->request));
31 | $this->assertStringStartsWith('-----BEGIN CERTIFICATE REQUEST-----', $certificate->request);
32 | $this->assertGreaterThan(0, strlen($certificate->privateKey));
33 | $this->assertStringStartsWith('-----BEGIN PRIVATE KEY-----', $certificate->privateKey);
34 | }
35 |
36 | public function testInstall()
37 | {
38 | $certificate = static::$client->certificate()->generate($this->certificateProperties);
39 |
40 | $result = static::$client->certificate()->install([
41 | 'name' => 'test',
42 | 'admin' => true,
43 | ], $certificate->request, $certificate->privateKey);
44 | $this->assertTrue($result);
45 |
46 | static::$client->certificate()->delete('test', ['admin' => true]);
47 | }
48 |
49 | public function testUpdate()
50 | {
51 | $payLoad = [
52 | 'name' => 'test',
53 | 'admin' => true,
54 | ];
55 | $certificate = static::$client->certificate()->generate($this->certificateProperties);
56 | static::$client->certificate()->install($payLoad, $certificate);
57 |
58 | $certificate = $this->generateCertificateOpenSsl($this->distinguishedNames);
59 | $result = static::$client->certificate()->update($payLoad, $certificate);
60 | $this->assertTrue($result);
61 |
62 | static::$client->certificate()->delete('test', ['admin' => true]);
63 | }
64 |
65 | public function testDelete()
66 | {
67 | $certificate = static::$client->certificate()->generate($this->certificateProperties);
68 |
69 | static::$client->certificate()->install([
70 | 'name' => 'test',
71 | 'admin' => true,
72 | ], $certificate);
73 |
74 | $result = static::$client->certificate()->delete('test', ['admin' => true]);
75 | $this->assertTrue($result);
76 | }
77 |
78 | private function generateCertificateOpenSsl(array $dn): Struct\Info
79 | {
80 | $privkey = openssl_pkey_new([
81 | "private_key_bits" => 2048,
82 | "private_key_type" => OPENSSL_KEYTYPE_RSA,
83 | ]);
84 | $csr = openssl_csr_new($dn, $privkey, ['digest_alg' => 'sha256']);
85 | $x509 = openssl_csr_sign($csr, null, $privkey, $days = 365, ['digest_alg' => 'sha256']);
86 |
87 | openssl_csr_export($csr, $csrout);
88 | openssl_x509_export($x509, $certout);
89 | openssl_pkey_export($privkey, $pkeyout);
90 |
91 | return new Struct\Info([
92 | 'publicKey' => $certout,
93 | 'request' => $csrout,
94 | 'privateKey' => $pkeyout
95 | ]);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/tests/CustomerTest.php:
--------------------------------------------------------------------------------
1 | customerProperties = [
16 | 'cname' => 'Plesk',
17 | 'pname' => 'John Smith',
18 | 'login' => 'john-unit-test',
19 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
20 | 'email' => 'john@smith.com',
21 | 'external-id' => 'link:12345',
22 | 'description' => 'Good guy',
23 | ];
24 | }
25 |
26 | public function testCreate()
27 | {
28 | $customer = static::$client->customer()->create($this->customerProperties);
29 | $this->assertIsInt($customer->id);
30 | $this->assertGreaterThan(0, $customer->id);
31 |
32 | static::$client->customer()->delete('id', $customer->id);
33 | }
34 |
35 | public function testDelete()
36 | {
37 | $customer = static::$client->customer()->create($this->customerProperties);
38 | $result = static::$client->customer()->delete('id', $customer->id);
39 | $this->assertTrue($result);
40 | }
41 |
42 | public function testGet()
43 | {
44 | $customer = static::$client->customer()->create($this->customerProperties);
45 | $customerInfo = static::$client->customer()->get('id', $customer->id);
46 | $this->assertEquals('Plesk', $customerInfo->company);
47 | $this->assertEquals('John Smith', $customerInfo->personalName);
48 | $this->assertEquals('john-unit-test', $customerInfo->login);
49 | $this->assertEquals('john@smith.com', $customerInfo->email);
50 | $this->assertEquals('Good guy', $customerInfo->description);
51 | $this->assertEquals('link:12345', $customerInfo->externalId);
52 | $this->assertEquals($customer->id, $customerInfo->id);
53 |
54 | static::$client->customer()->delete('id', $customer->id);
55 | }
56 |
57 | public function testGetAll()
58 | {
59 | $keyInfo = static::$client->server()->getKeyInfo();
60 |
61 | if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_CLIENTS, 2)) {
62 | $this->markTestSkipped('License does not allow to create more than 1 customer.');
63 | }
64 |
65 | static::$client->customer()->create([
66 | 'pname' => 'John Smith',
67 | 'login' => 'customer-a',
68 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
69 | ]);
70 | static::$client->customer()->create([
71 | 'pname' => 'Mike Black',
72 | 'login' => 'customer-b',
73 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
74 | ]);
75 |
76 | $customersInfo = static::$client->customer()->getAll();
77 | $this->assertIsArray($customersInfo);
78 |
79 | $customersCheck = array_filter($customersInfo, function ($value) {
80 | return $value->personalName === 'John Smith' || $value->personalName === 'Mike Black';
81 | });
82 | $this->assertCount(2, $customersCheck);
83 |
84 | static::$client->customer()->delete('login', 'customer-a');
85 | static::$client->customer()->delete('login', 'customer-b');
86 | }
87 |
88 | public function testGetAllEmpty()
89 | {
90 | $customersInfo = static::$client->customer()->getAll();
91 | $this->assertCount(0, $customersInfo);
92 | }
93 |
94 | public function testEnable()
95 | {
96 | $customer = static::$client->customer()->create($this->customerProperties);
97 | static::$client->customer()->disable('id', $customer->id);
98 | static::$client->customer()->enable('id', $customer->id);
99 | $customerInfo = static::$client->customer()->get('id', $customer->id);
100 | $this->assertTrue($customerInfo->enabled);
101 |
102 | static::$client->customer()->delete('id', $customer->id);
103 | }
104 |
105 | public function testDisable()
106 | {
107 | $customer = static::$client->customer()->create($this->customerProperties);
108 | static::$client->customer()->disable('id', $customer->id);
109 | $customerInfo = static::$client->customer()->get('id', $customer->id);
110 | $this->assertFalse($customerInfo->enabled);
111 |
112 | static::$client->customer()->delete('id', $customer->id);
113 | }
114 |
115 | public function testSetProperties()
116 | {
117 | $customer = static::$client->customer()->create($this->customerProperties);
118 | static::$client->customer()->setProperties('id', $customer->id, [
119 | 'pname' => 'Mike Black',
120 | 'email' => 'mike@black.com',
121 | ]);
122 | $customerInfo = static::$client->customer()->get('id', $customer->id);
123 | $this->assertEquals('Mike Black', $customerInfo->personalName);
124 | $this->assertEquals('mike@black.com', $customerInfo->email);
125 |
126 | static::$client->customer()->delete('id', $customer->id);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/tests/DatabaseServerTest.php:
--------------------------------------------------------------------------------
1 | databaseServer()->getSupportedTypes();
11 | $this->assertGreaterThan(0, count($types));
12 | $this->assertContains('mysql', $types);
13 | }
14 |
15 | public function testGet()
16 | {
17 | $dbServer = static::$client->databaseServer()->get('id', 1);
18 | $this->assertEquals('localhost', $dbServer->host);
19 | $this->assertGreaterThan(0, $dbServer->port);
20 | }
21 |
22 | public function testGetAll()
23 | {
24 | $dbServers = static::$client->databaseServer()->getAll();
25 | $this->assertIsArray($dbServers);
26 | $this->assertGreaterThan(0, count($dbServers));
27 | $this->assertEquals('localhost', $dbServers[0]->host);
28 | }
29 |
30 | public function testGetDefault()
31 | {
32 | $dbServer = static::$client->databaseServer()->getDefault('mysql');
33 | $this->assertEquals('mysql', $dbServer->type);
34 | $this->assertGreaterThan(0, $dbServer->id);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/DatabaseTest.php:
--------------------------------------------------------------------------------
1 | databaseServer()->getDefault('mysql');
18 | }
19 |
20 | public function testCreate()
21 | {
22 | $database = $this->createDatabase([
23 | 'webspace-id' => static::$webspace->id,
24 | 'name' => 'test1',
25 | 'type' => static::$databaseServer->type,
26 | 'db-server-id' => static::$databaseServer->id,
27 | ]);
28 | static::$client->database()->delete('id', $database->id);
29 | }
30 |
31 | public function testCreateUser()
32 | {
33 | $database = $this->createDatabase([
34 | 'webspace-id' => static::$webspace->id,
35 | 'name' => 'test1',
36 | 'type' => static::$databaseServer->type,
37 | 'db-server-id' => static::$databaseServer->id,
38 | ]);
39 | $user = $this->createUser([
40 | 'db-id' => $database->id,
41 | 'login' => 'test_user1',
42 | 'password' => PasswordProvider::STRONG_PASSWORD,
43 | ]);
44 | static::$client->database()->deleteUser('id', $user->id);
45 | static::$client->database()->delete('id', $database->id);
46 | }
47 |
48 | public function testUpdateUser()
49 | {
50 | $database = $this->createDatabase([
51 | 'webspace-id' => static::$webspace->id,
52 | 'name' => 'test1',
53 | 'type' => static::$databaseServer->type,
54 | 'db-server-id' => static::$databaseServer->id,
55 | ]);
56 | $user = $this->createUser([
57 | 'db-id' => $database->id,
58 | 'login' => 'test_user1',
59 | 'password' => PasswordProvider::STRONG_PASSWORD,
60 | ]);
61 | $updatedUser = static::$client->database()->updateUser([
62 | 'id' => $user->id,
63 | 'login' => 'test_user2',
64 | 'password' => PasswordProvider::STRONG_PASSWORD,
65 | ]);
66 | $this->assertEquals(true, $updatedUser);
67 | static::$client->database()->deleteUser('id', $user->id);
68 | static::$client->database()->delete('id', $database->id);
69 | }
70 |
71 | public function testGetById()
72 | {
73 | $database = $this->createDatabase([
74 | 'webspace-id' => static::$webspace->id,
75 | 'name' => 'test1',
76 | 'type' => static::$databaseServer->type,
77 | 'db-server-id' => static::$databaseServer->id,
78 | ]);
79 |
80 | $db = static::$client->database()->get('id', $database->id);
81 | $this->assertEquals('test1', $db->name);
82 | $this->assertEquals(static::$databaseServer->type, $db->type);
83 | $this->assertEquals(static::$webspace->id, $db->webspaceId);
84 | $this->assertEquals(static::$databaseServer->id, $db->dbServerId);
85 |
86 | static::$client->database()->delete('id', $database->id);
87 | }
88 |
89 | public function testGetAllByWebspaceId()
90 | {
91 | $db1 = $this->createDatabase([
92 | 'webspace-id' => static::$webspace->id,
93 | 'name' => 'test1',
94 | 'type' => static::$databaseServer->type,
95 | 'db-server-id' => static::$databaseServer->id,
96 | ]);
97 | $db2 = $this->createDatabase([
98 | 'webspace-id' => static::$webspace->id,
99 | 'name' => 'test2',
100 | 'type' => static::$databaseServer->type,
101 | 'db-server-id' => static::$databaseServer->id,
102 | ]);
103 | $databases = static::$client->database()->getAll('webspace-id', static::$webspace->id);
104 | $this->assertEquals('test1', $databases[0]->name);
105 | $this->assertEquals('test2', $databases[1]->name);
106 | $this->assertEquals(static::$webspace->id, $databases[0]->webspaceId);
107 | $this->assertEquals(static::$databaseServer->id, $databases[1]->dbServerId);
108 |
109 | static::$client->database()->delete('id', $db1->id);
110 | static::$client->database()->delete('id', $db2->id);
111 | }
112 |
113 | public function testGetUserById()
114 | {
115 | $database = $this->createDatabase([
116 | 'webspace-id' => static::$webspace->id,
117 | 'name' => 'test1',
118 | 'type' => static::$databaseServer->type,
119 | 'db-server-id' => static::$databaseServer->id,
120 | ]);
121 |
122 | $user = $this->createUser([
123 | 'db-id' => $database->id,
124 | 'login' => 'test_user1',
125 | 'password' => PasswordProvider::STRONG_PASSWORD,
126 | ]);
127 |
128 | $dbUser = static::$client->database()->getUser('id', $user->id);
129 | $this->assertEquals('test_user1', $dbUser->login);
130 | $this->assertEquals($database->id, $dbUser->dbId);
131 |
132 | static::$client->database()->deleteUser('id', $user->id);
133 | static::$client->database()->delete('id', $database->id);
134 | }
135 |
136 | public function testGetAllUsersByDbId()
137 | {
138 | $db1 = $this->createDatabase([
139 | 'webspace-id' => static::$webspace->id,
140 | 'name' => 'test1',
141 | 'type' => static::$databaseServer->type,
142 | 'db-server-id' => static::$databaseServer->id,
143 | ]);
144 | $db2 = $this->createDatabase([
145 | 'webspace-id' => static::$webspace->id,
146 | 'name' => 'test2',
147 | 'type' => static::$databaseServer->type,
148 | 'db-server-id' => static::$databaseServer->id,
149 | ]);
150 | $user1 = $this->createUser([
151 | 'db-id' => $db1->id,
152 | 'login' => 'test_user1',
153 | 'password' => PasswordProvider::STRONG_PASSWORD,
154 | ]);
155 |
156 | $user2 = $this->createUser([
157 | 'db-id' => $db1->id,
158 | 'login' => 'test_user2',
159 | 'password' => PasswordProvider::STRONG_PASSWORD,
160 | ]);
161 |
162 | $user3 = $this->createUser([
163 | 'db-id' => $db2->id,
164 | 'login' => 'test_user3',
165 | 'password' => PasswordProvider::STRONG_PASSWORD,
166 | ]);
167 |
168 | $dbUsers = static::$client->database()->getAllUsers('db-id', $db1->id);
169 | $this->assertEquals(2, count($dbUsers));
170 | $this->assertEquals('test_user1', $dbUsers[0]->login);
171 | $this->assertEquals('test_user2', $dbUsers[1]->login);
172 |
173 | static::$client->database()->deleteUser('id', $user1->id);
174 | static::$client->database()->deleteUser('id', $user2->id);
175 | static::$client->database()->deleteUser('id', $user3->id);
176 | static::$client->database()->delete('id', $db1->id);
177 | static::$client->database()->delete('id', $db2->id);
178 | }
179 |
180 | public function testDelete()
181 | {
182 | $database = $this->createDatabase([
183 | 'webspace-id' => static::$webspace->id,
184 | 'name' => 'test1',
185 | 'type' => static::$databaseServer->type,
186 | 'db-server-id' => static::$databaseServer->id,
187 | ]);
188 | $result = static::$client->database()->delete('id', $database->id);
189 | $this->assertTrue($result);
190 | }
191 |
192 | public function testDeleteUser()
193 | {
194 | $database = $this->createDatabase([
195 | 'webspace-id' => static::$webspace->id,
196 | 'name' => 'test1',
197 | 'type' => static::$databaseServer->type,
198 | 'db-server-id' => static::$databaseServer->id,
199 | ]);
200 | $user = $this->createUser([
201 | 'db-id' => $database->id,
202 | 'login' => 'test_user1',
203 | 'password' => PasswordProvider::STRONG_PASSWORD,
204 | ]);
205 |
206 | $result = static::$client->database()->deleteUser('id', $user->id);
207 | $this->assertTrue($result);
208 | static::$client->database()->delete('id', $database->id);
209 | }
210 |
211 | private function createDatabase(array $params): \PleskX\Api\Struct\Database\Info
212 | {
213 | $database = static::$client->database()->create($params);
214 | $this->assertIsInt($database->id);
215 | $this->assertGreaterThan(0, $database->id);
216 |
217 | return $database;
218 | }
219 |
220 | private function createUser(array $params): \PleskX\Api\Struct\Database\UserInfo
221 | {
222 | $user = static::$client->database()->createUser($params);
223 | $this->assertIsInt($user->id);
224 | $this->assertGreaterThan(0, $user->id);
225 |
226 | return $user;
227 | }
228 | }
229 |
--------------------------------------------------------------------------------
/tests/DnsTemplateTest.php:
--------------------------------------------------------------------------------
1 | server()->getServiceStates();
15 | static::$isDnsSupported = $serviceStates['dns'] && ('running' == $serviceStates['dns']['state']);
16 | }
17 |
18 | protected function setUp(): void
19 | {
20 | parent::setUp();
21 |
22 | if (!static::$isDnsSupported) {
23 | $this->markTestSkipped('DNS system is not supported.');
24 | }
25 | }
26 |
27 | public function testCreate()
28 | {
29 | $dns = static::$client->dnsTemplate()->create([
30 | 'type' => 'TXT',
31 | 'host' => 'test.create',
32 | 'value' => 'value',
33 | ]);
34 | $this->assertIsInt($dns->id);
35 | $this->assertGreaterThan(0, $dns->id);
36 | $this->assertEquals(0, $dns->siteId);
37 | $this->assertEquals(0, $dns->siteAliasId);
38 | static::$client->dnsTemplate()->delete('id', $dns->id);
39 | }
40 |
41 | public function testGetById()
42 | {
43 | $dns = static::$client->dnsTemplate()->create([
44 | 'type' => 'TXT',
45 | 'host' => 'test.get.by.id',
46 | 'value' => 'value',
47 | ]);
48 |
49 | $dnsInfo = static::$client->dnsTemplate()->get('id', $dns->id);
50 | $this->assertEquals('TXT', $dnsInfo->type);
51 | $this->assertEquals('value', $dnsInfo->value);
52 |
53 | static::$client->dnsTemplate()->delete('id', $dns->id);
54 | }
55 |
56 | public function testGetAll()
57 | {
58 | $dns = static::$client->dnsTemplate()->create([
59 | 'type' => 'TXT',
60 | 'host' => 'test.get.all',
61 | 'value' => 'value',
62 | ]);
63 | $dns2 = static::$client->dnsTemplate()->create([
64 | 'type' => 'TXT',
65 | 'host' => 'test.get.all',
66 | 'value' => 'value2',
67 | ]);
68 | $dnsInfo = static::$client->dnsTemplate()->getAll();
69 | $dsRecords = [];
70 | foreach ($dnsInfo as $dnsRec) {
71 | if ('TXT' === $dnsRec->type && 0 === strpos($dnsRec->host, 'test.get.all')) {
72 | $dsRecords[] = $dnsRec;
73 | }
74 | }
75 | $this->assertCount(2, $dsRecords);
76 |
77 | static::$client->dnsTemplate()->delete('id', $dns->id);
78 | static::$client->dnsTemplate()->delete('id', $dns2->id);
79 | }
80 |
81 | public function testDelete()
82 | {
83 | $dns = static::$client->dnsTemplate()->create([
84 | 'type' => 'TXT',
85 | 'host' => 'test.delete',
86 | 'value' => 'value',
87 | ]);
88 | $result = static::$client->dnsTemplate()->delete('id', $dns->id);
89 | $this->assertTrue($result);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/tests/DnsTest.php:
--------------------------------------------------------------------------------
1 | server()->getServiceStates();
16 | static::$isDnsSupported = isset($serviceStates['dns']) && ('running' == $serviceStates['dns']['state']);
17 |
18 | if (static::$isDnsSupported) {
19 | static::$webspace = static::createWebspace();
20 | }
21 | }
22 |
23 | protected function setUp(): void
24 | {
25 | parent::setUp();
26 |
27 | if (!static::$isDnsSupported) {
28 | $this->markTestSkipped('DNS system is not supported.');
29 | }
30 | }
31 |
32 | public function testCreate()
33 | {
34 | $dns = static::$client->dns()->create([
35 | 'site-id' => static::$webspace->id,
36 | 'type' => 'TXT',
37 | 'host' => 'host',
38 | 'value' => 'value',
39 | ]);
40 | $this->assertIsInt($dns->id);
41 | $this->assertGreaterThan(0, $dns->id);
42 | static::$client->dns()->delete('id', $dns->id);
43 | }
44 |
45 | /**
46 | * @return \SimpleXMLElement[]
47 | */
48 | public function testBulkCreate(): array
49 | {
50 | $response = static::$client->dns()->bulkCreate([
51 | [
52 | 'site-id' => static::$webspace->id,
53 | 'type' => 'TXT',
54 | 'host' => 'host',
55 | 'value' => 'value',
56 | ],
57 | [
58 | 'site-id' => static::$webspace->id,
59 | 'type' => 'A',
60 | 'host' => 'host',
61 | 'value' => '1.1.1.1',
62 | ],
63 | [
64 | 'site-id' => static::$webspace->id,
65 | 'type' => 'MX',
66 | 'host' => 'custom-mail',
67 | 'value' => '1.1.1.1',
68 | 'opt' => '10',
69 | ],
70 | ]);
71 |
72 | $this->assertCount(3, $response);
73 |
74 | foreach ($response as $xml) {
75 | $this->assertEquals('ok', (string) $xml->status);
76 | $this->assertGreaterThan(0, (int) $xml->id);
77 | }
78 |
79 | return $response;
80 | }
81 |
82 | /**
83 | * @depends testBulkCreate
84 | *
85 | * @param \SimpleXMLElement[] $createdRecords
86 | */
87 | public function testBulkDelete(array $createdRecords)
88 | {
89 | $createdRecordIds = array_map(function ($record) {
90 | return (int) $record->id;
91 | }, $createdRecords);
92 |
93 | $response = static::$client->dns()->bulkDelete($createdRecordIds);
94 |
95 | $this->assertCount(3, $response);
96 |
97 | foreach ($response as $xml) {
98 | $this->assertEquals('ok', (string) $xml->status);
99 | $this->assertGreaterThan(0, (int) $xml->id);
100 | }
101 | }
102 |
103 | public function testGetById()
104 | {
105 | $dns = static::$client->dns()->create([
106 | 'site-id' => static::$webspace->id,
107 | 'type' => 'TXT',
108 | 'host' => '',
109 | 'value' => 'value',
110 | ]);
111 |
112 | $dnsInfo = static::$client->dns()->get('id', $dns->id);
113 | $this->assertEquals('TXT', $dnsInfo->type);
114 | $this->assertEquals(static::$webspace->id, $dnsInfo->siteId);
115 | $this->assertEquals('value', $dnsInfo->value);
116 |
117 | static::$client->dns()->delete('id', $dns->id);
118 | }
119 |
120 | public function testGetAllByWebspaceId()
121 | {
122 | $dns = static::$client->dns()->create([
123 | 'site-id' => static::$webspace->id,
124 | 'type' => 'DS',
125 | 'host' => 'host',
126 | 'value' => '60485 5 1 2BB183AF5F22588179A53B0A98631FAD1A292118',
127 | ]);
128 | $dns2 = static::$client->dns()->create([
129 | 'site-id' => static::$webspace->id,
130 | 'type' => 'DS',
131 | 'host' => 'host',
132 | 'value' => '60485 5 1 2BB183AF5F22588179A53B0A98631FAD1A292119',
133 | ]);
134 | $dnsInfo = static::$client->dns()->getAll('site-id', static::$webspace->id);
135 | $dsRecords = [];
136 | foreach ($dnsInfo as $dnsRec) {
137 | if ('DS' == $dnsRec->type) {
138 | $dsRecords[] = $dnsRec;
139 | }
140 | }
141 | $this->assertEquals(2, count($dsRecords));
142 | foreach ($dsRecords as $dsRecord) {
143 | $this->assertEquals(static::$webspace->id, $dsRecord->siteId);
144 | }
145 |
146 | static::$client->dns()->delete('id', $dns->id);
147 | static::$client->dns()->delete('id', $dns2->id);
148 | }
149 |
150 | public function testDelete()
151 | {
152 | $dns = static::$client->dns()->create([
153 | 'site-id' => static::$webspace->id,
154 | 'type' => 'TXT',
155 | 'host' => 'host',
156 | 'value' => 'value',
157 | ]);
158 | $result = static::$client->dns()->delete('id', $dns->id);
159 | $this->assertTrue($result);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/tests/EventLogTest.php:
--------------------------------------------------------------------------------
1 | eventLog()->get();
11 | $this->assertGreaterThan(0, $events);
12 |
13 | $event = reset($events);
14 | $this->assertGreaterThan(0, $event->time);
15 | }
16 |
17 | public function testGetDetailedLog()
18 | {
19 | $events = static::$client->eventLog()->getDetailedLog();
20 | $this->assertGreaterThan(0, $events);
21 |
22 | $event = reset($events);
23 | $this->assertGreaterThan(0, $event->time);
24 | }
25 |
26 | public function testGetLastId()
27 | {
28 | $lastId = static::$client->eventLog()->getLastId();
29 | $this->assertGreaterThan(0, $lastId);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/IpTest.php:
--------------------------------------------------------------------------------
1 | ip()->get();
11 | $this->assertGreaterThan(0, count($ips));
12 |
13 | $ip = reset($ips);
14 | $this->assertMatchesRegularExpression('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $ip->ipAddress);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/LocaleTest.php:
--------------------------------------------------------------------------------
1 | locale()->get();
11 | $this->assertGreaterThan(0, count($locales));
12 |
13 | $locale = $locales['en-US'];
14 | $this->assertEquals('en-US', $locale->id);
15 | }
16 |
17 | public function testGetById()
18 | {
19 | $locale = static::$client->locale()->get('en-US');
20 | $this->assertEquals('en-US', $locale->id);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/tests/MailTest.php:
--------------------------------------------------------------------------------
1 | server()->getServiceStates();
18 | static::$isMailSupported = isset($serviceStates['smtp']) && ('running' == $serviceStates['smtp']['state']);
19 |
20 | if (static::$isMailSupported) {
21 | static::$webspace = static::createWebspace();
22 | }
23 | }
24 |
25 | protected function setUp(): void
26 | {
27 | parent::setUp();
28 |
29 | if (!static::$isMailSupported) {
30 | $this->markTestSkipped('Mail system is not supported.');
31 | }
32 | }
33 |
34 | public function testCreate()
35 | {
36 | $mailname = static::$client->mail()->create(
37 | 'test',
38 | static::$webspace->id,
39 | true,
40 | PasswordProvider::STRONG_PASSWORD
41 | );
42 |
43 | $this->assertIsInt($mailname->id);
44 | $this->assertGreaterThan(0, $mailname->id);
45 | $this->assertEquals('test', $mailname->name);
46 |
47 | static::$client->mail()->delete('name', $mailname->name, static::$webspace->id);
48 | }
49 |
50 | public function testCreateMultiForwarding()
51 | {
52 | $mailname = static::$client->request([
53 | 'mail' => [
54 | 'create' => [
55 | 'filter' => [
56 | 'site-id' => static::$webspace->id,
57 | 'mailname' => [
58 | 'name' => 'test',
59 | 'mailbox' => [
60 | 'enabled' => true,
61 | ],
62 | 'forwarding' => [
63 | 'enabled' => true,
64 | 'address' => [
65 | 'user1@example.com',
66 | 'user2@example.com',
67 | ],
68 | ],
69 | 'alias' => [
70 | 'test1',
71 | 'test2',
72 | ],
73 | 'password' => [
74 | 'value' => PasswordProvider::STRONG_PASSWORD,
75 | ],
76 | ],
77 | ],
78 | ],
79 | ],
80 | ]);
81 |
82 | $mailnameInfo = static::$client->request([
83 | 'mail' => [
84 | 'get_info' => [
85 | 'filter' => [
86 | 'site-id' => static::$webspace->id,
87 | 'name' => 'test',
88 | ],
89 | 'forwarding' => null,
90 | 'aliases' => null,
91 | ],
92 | ],
93 | ]);
94 |
95 | $this->assertSame(2, count($mailnameInfo->mailname->forwarding->address));
96 | $this->assertSame(2, count($mailnameInfo->mailname->alias));
97 |
98 | static::$client->mail()->delete('name', 'test', static::$webspace->id);
99 | }
100 |
101 | public function testDelete()
102 | {
103 | $mailname = static::$client->mail()->create('test', static::$webspace->id);
104 |
105 | $result = static::$client->mail()->delete('name', $mailname->name, static::$webspace->id);
106 | $this->assertTrue($result);
107 | }
108 |
109 | public function testGet()
110 | {
111 | $mailname = static::$client->mail()->create('test', static::$webspace->id);
112 |
113 | $mailnameInfo = static::$client->mail()->get('test', static::$webspace->id);
114 | $this->assertEquals('test', $mailnameInfo->name);
115 | $this->assertEquals($mailname->id, $mailnameInfo->id);
116 |
117 | static::$client->mail()->delete('name', $mailname->name, static::$webspace->id);
118 | }
119 |
120 | public function testGetAll()
121 | {
122 | $mailname = static::$client->mail()->create('test', static::$webspace->id);
123 |
124 | $mailnamesInfo = static::$client->mail()->getAll(static::$webspace->id);
125 | $this->assertCount(1, $mailnamesInfo);
126 | $this->assertEquals('test', $mailnamesInfo[0]->name);
127 |
128 | static::$client->mail()->delete('name', $mailname->name, static::$webspace->id);
129 | }
130 |
131 | public function testGetAllWithoutMailnames()
132 | {
133 | $mailnamesInfo = static::$client->mail()->getAll(static::$webspace->id);
134 | $this->assertCount(0, $mailnamesInfo);
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/tests/PhpHandlerTest.php:
--------------------------------------------------------------------------------
1 | phpHandler()->get();
11 |
12 | $this->assertTrue(property_exists($handler, 'type'));
13 | }
14 |
15 | public function testGetAll()
16 | {
17 | $handlers = static::$client->phpHandler()->getAll();
18 |
19 | $this->assertIsArray($handlers);
20 | $this->assertNotEmpty($handlers);
21 |
22 | $handler = current($handlers);
23 |
24 | $this->assertIsObject($handler);
25 | $this->assertTrue(property_exists($handler, 'type'));
26 | }
27 |
28 | public function testGetUnknownHandlerThrowsException()
29 | {
30 | $this->expectException(\PleskX\Api\Exception::class);
31 | $this->expectExceptionMessage('Php handler does not exists');
32 |
33 | static::$client->phpHandler()->get('id', 'this-handler-does-not-exist');
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/ProtectedDirectoryTest.php:
--------------------------------------------------------------------------------
1 | protectedDirectory()->add('/', static::$webspace->id);
21 |
22 | $this->assertIsObject($protectedDirectory);
23 | $this->assertGreaterThan(0, $protectedDirectory->id);
24 |
25 | static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
26 | }
27 |
28 | public function testAddInvalidDirectory()
29 | {
30 | $this->expectException(\PleskX\Api\Exception::class);
31 | $this->expectExceptionCode(1019);
32 |
33 | static::$client->protectedDirectory()->add('', static::$webspace->id);
34 | }
35 |
36 | public function testDelete()
37 | {
38 | $protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
39 |
40 | $result = static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
41 | $this->assertTrue($result);
42 | }
43 |
44 | public function testGetById()
45 | {
46 | $protectedDirectory = static::$client->protectedDirectory()->add('test', static::$webspace->id);
47 |
48 | $foundDirectory = static::$client->protectedDirectory()->get('id', $protectedDirectory->id);
49 | $this->assertEquals('test', $foundDirectory->name);
50 |
51 | static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
52 | }
53 |
54 | public function testGetUnknownDirectory()
55 | {
56 | $this->expectException(\PleskX\Api\Exception::class);
57 | $this->expectExceptionCode(1013);
58 |
59 | $nonExistentDirectoryId = 99999999;
60 | static::$client->protectedDirectory()->get('id', $nonExistentDirectoryId);
61 | }
62 |
63 | public function testAddUser()
64 | {
65 | $protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
66 |
67 | $user = static::$client->protectedDirectory()->addUser(
68 | $protectedDirectory,
69 | 'john',
70 | PasswordProvider::STRONG_PASSWORD
71 | );
72 | $this->assertGreaterThan(0, $user->id);
73 |
74 | static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
75 | }
76 |
77 | public function testDeleteUser()
78 | {
79 | $protectedDirectory = static::$client->protectedDirectory()->add('/', static::$webspace->id);
80 |
81 | $user = static::$client->protectedDirectory()->addUser(
82 | $protectedDirectory,
83 | 'john',
84 | PasswordProvider::STRONG_PASSWORD
85 | );
86 | $result = static::$client->protectedDirectory()->deleteUser('id', $user->id);
87 | $this->assertTrue($result);
88 |
89 | static::$client->protectedDirectory()->delete('id', $protectedDirectory->id);
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/tests/ResellerTest.php:
--------------------------------------------------------------------------------
1 | resellerProperties = [
16 | 'pname' => 'John Reseller',
17 | 'login' => 'reseller-unit-test',
18 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
19 | ];
20 | }
21 |
22 | public function testCreate()
23 | {
24 | $reseller = static::$client->reseller()->create($this->resellerProperties);
25 | $this->assertIsInt($reseller->id);
26 | $this->assertGreaterThan(0, $reseller->id);
27 |
28 | static::$client->reseller()->delete('id', $reseller->id);
29 | }
30 |
31 | public function testDelete()
32 | {
33 | $reseller = static::$client->reseller()->create($this->resellerProperties);
34 | $result = static::$client->reseller()->delete('id', $reseller->id);
35 | $this->assertTrue($result);
36 | }
37 |
38 | public function testGet()
39 | {
40 | $reseller = static::$client->reseller()->create($this->resellerProperties);
41 | $resellerInfo = static::$client->reseller()->get('id', $reseller->id);
42 | $this->assertEquals('John Reseller', $resellerInfo->personalName);
43 | $this->assertEquals('reseller-unit-test', $resellerInfo->login);
44 | $this->assertGreaterThan(0, count($resellerInfo->permissions));
45 | $this->assertEquals($reseller->id, $resellerInfo->id);
46 |
47 | static::$client->reseller()->delete('id', $reseller->id);
48 | }
49 |
50 | public function testGetAll()
51 | {
52 | $keyInfo = static::$client->server()->getKeyInfo();
53 |
54 | if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_RESELLERS, 2)) {
55 | $this->markTestSkipped('License does not allow to create more than 1 reseller.');
56 | }
57 |
58 | static::$client->reseller()->create([
59 | 'pname' => 'John Reseller',
60 | 'login' => 'reseller-a',
61 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
62 | ]);
63 | static::$client->reseller()->create([
64 | 'pname' => 'Mike Reseller',
65 | 'login' => 'reseller-b',
66 | 'passwd' => PasswordProvider::STRONG_PASSWORD,
67 | ]);
68 |
69 | $resellersInfo = static::$client->reseller()->getAll();
70 | $this->assertCount(2, $resellersInfo);
71 | $this->assertEquals('John Reseller', $resellersInfo[0]->personalName);
72 | $this->assertEquals('reseller-a', $resellersInfo[0]->login);
73 |
74 | static::$client->reseller()->delete('login', 'reseller-a');
75 | static::$client->reseller()->delete('login', 'reseller-b');
76 | }
77 |
78 | public function testGetAllEmpty()
79 | {
80 | $resellersInfo = static::$client->reseller()->getAll();
81 | $this->assertCount(0, $resellersInfo);
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/tests/SecretKeyTest.php:
--------------------------------------------------------------------------------
1 | secretKey()->create('192.168.0.1');
13 | $this->assertMatchesRegularExpression(
14 | '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
15 | $keyId
16 | );
17 | static::$client->secretKey()->delete($keyId);
18 | }
19 |
20 | public function testCreateAutoIp()
21 | {
22 | $keyId = static::$client->secretKey()->create();
23 | $this->assertNotEmpty($keyId);
24 | static::$client->secretKey()->delete($keyId);
25 | }
26 |
27 | public function testCreateMultiIps()
28 | {
29 | $keyId = static::$client->secretKey()->create(join(',', ['192.168.0.1', '192.168.0.2']));
30 | $this->assertMatchesRegularExpression(
31 | '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
32 | $keyId
33 | );
34 | static::$client->secretKey()->delete($keyId);
35 | }
36 |
37 | public function testCreateWithDescription()
38 | {
39 | $keyId = static::$client->secretKey()->create('192.168.0.1', 'test key');
40 | $keyInfo = static::$client->secretKey()->get($keyId);
41 |
42 | $this->assertEquals('test key', $keyInfo->description);
43 |
44 | static::$client->secretKey()->delete($keyId);
45 | }
46 |
47 | public function testGet()
48 | {
49 | $keyId = static::$client->secretKey()->create('192.168.0.1');
50 | $keyInfo = static::$client->secretKey()->get($keyId);
51 |
52 | $this->assertNotEmpty($keyInfo->key);
53 | $this->assertEquals('192.168.0.1', $keyInfo->ipAddress);
54 | $this->assertEquals('admin', $keyInfo->login);
55 |
56 | static::$client->secretKey()->delete($keyId);
57 | }
58 |
59 | public function testGetAll()
60 | {
61 | $keyIds = [];
62 | $keyIds[] = static::$client->secretKey()->create('192.168.0.1');
63 | $keyIds[] = static::$client->secretKey()->create('192.168.0.2');
64 |
65 | $keys = static::$client->secretKey()->getAll();
66 | $this->assertGreaterThanOrEqual(2, count($keys));
67 |
68 | $keyIpAddresses = array_map(function ($key) {
69 | return $key->ipAddress;
70 | }, $keys);
71 | $this->assertContains('192.168.0.1', $keyIpAddresses);
72 | $this->assertContains('192.168.0.2', $keyIpAddresses);
73 |
74 | foreach ($keyIds as $keyId) {
75 | static::$client->secretKey()->delete($keyId);
76 | }
77 | }
78 |
79 | public function testDelete()
80 | {
81 | $keyId = static::$client->secretKey()->create('192.168.0.1');
82 | static::$client->secretKey()->delete($keyId);
83 |
84 | try {
85 | static::$client->secretKey()->get($keyId);
86 | $this->fail("Secret key $keyId was not deleted.");
87 | } catch (Exception $exception) {
88 | $this->assertEquals(1013, $exception->getCode());
89 | }
90 | }
91 |
92 | public function testListEmpty()
93 | {
94 | $keys = static::$client->secretKey()->getAll();
95 | foreach ($keys as $key) {
96 | static::$client->secretKey()->delete($key->key);
97 | }
98 |
99 | $keys = static::$client->secretKey()->getAll();
100 | $this->assertEquals(0, count($keys));
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/tests/ServerTest.php:
--------------------------------------------------------------------------------
1 | server()->getProtos();
11 | $this->assertIsArray($protos);
12 | $this->assertContains('1.6.3.0', $protos);
13 | }
14 |
15 | public function testGetGenInfo()
16 | {
17 | $generalInfo = static::$client->server()->getGeneralInfo();
18 | $this->assertGreaterThan(0, strlen($generalInfo->serverName));
19 | $this->assertMatchesRegularExpression(
20 | '/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/',
21 | strtolower($generalInfo->serverGuid)
22 | );
23 | $this->assertEquals('standard', $generalInfo->mode);
24 | }
25 |
26 | public function testGetPreferences()
27 | {
28 | $preferences = static::$client->server()->getPreferences();
29 | $this->assertIsNumeric($preferences->statTtl);
30 | $this->assertGreaterThan(0, $preferences->statTtl);
31 | $this->assertEquals(0, $preferences->restartApacheInterval);
32 | }
33 |
34 | public function testGetAdmin()
35 | {
36 | $admin = static::$client->server()->getAdmin();
37 | $this->assertGreaterThan(0, strlen($admin->name));
38 | $this->assertStringContainsString('@', $admin->email);
39 | }
40 |
41 | public function testGetKeyInfo()
42 | {
43 | $keyInfo = static::$client->server()->getKeyInfo();
44 | $this->assertIsArray($keyInfo);
45 | $this->assertGreaterThan(0, count($keyInfo));
46 | $this->assertArrayHasKey('plesk_key_id', $keyInfo);
47 | $this->assertArrayHasKey('lim_date', $keyInfo);
48 | }
49 |
50 | public function testGetComponents()
51 | {
52 | $components = static::$client->server()->getComponents();
53 | $this->assertIsArray($components);
54 | $this->assertGreaterThan(0, count($components));
55 | $this->assertArrayHasKey('psa', $components);
56 | }
57 |
58 | public function testGetServiceStates()
59 | {
60 | $serviceStates = static::$client->server()->getServiceStates();
61 |
62 | $this->assertIsArray($serviceStates);
63 | $this->assertGreaterThan(0, count($serviceStates));
64 |
65 | $service = current($serviceStates);
66 | $this->assertIsArray($service);
67 | $this->assertArrayHasKey('id', $service);
68 | $this->assertArrayHasKey('title', $service);
69 | $this->assertArrayHasKey('state', $service);
70 | }
71 |
72 | public function testGetSessionPreferences()
73 | {
74 | $preferences = static::$client->server()->getSessionPreferences();
75 | $this->assertIsNumeric($preferences->loginTimeout);
76 | $this->assertGreaterThan(0, $preferences->loginTimeout);
77 | }
78 |
79 | public function testGetShells()
80 | {
81 | $shells = static::$client->server()->getShells();
82 |
83 | $this->assertIsArray($shells);
84 | $this->assertGreaterThan(0, count($shells));
85 | }
86 |
87 | public function testGetNetworkInterfaces()
88 | {
89 | $netInterfaces = static::$client->server()->getNetworkInterfaces();
90 | $this->assertIsArray($netInterfaces);
91 | $this->assertGreaterThan(0, count($netInterfaces));
92 | }
93 |
94 | public function testGetStatistics()
95 | {
96 | $stats = static::$client->server()->getStatistics();
97 | $this->assertIsNumeric($stats->objects->clients);
98 | $this->assertIsNumeric($stats->objects->domains);
99 | $this->assertIsNumeric($stats->objects->databases);
100 | $this->assertEquals('psa', $stats->version->internalName);
101 | $this->assertNotEmpty($stats->version->osName);
102 | $this->assertNotEmpty($stats->version->osVersion);
103 | $this->assertGreaterThan(0, $stats->other->uptime);
104 | $this->assertGreaterThan(0, strlen($stats->other->cpu));
105 | $this->assertIsFloat($stats->loadAverage->load1min);
106 | $this->assertGreaterThan(0, $stats->memory->total);
107 | $this->assertGreaterThan($stats->memory->free, $stats->memory->total);
108 | $this->assertIsNumeric($stats->swap->total);
109 | $this->assertIsArray($stats->diskSpace);
110 | }
111 |
112 | public function testGetSiteIsolationConfig()
113 | {
114 | $config = static::$client->server()->getSiteIsolationConfig();
115 | $this->assertIsArray($config);
116 | $this->assertGreaterThan(0, count($config));
117 | $this->assertArrayHasKey('php', $config);
118 | }
119 |
120 | public function testGetUpdatesInfo()
121 | {
122 | $updatesInfo = static::$client->server()->getUpdatesInfo();
123 | $this->assertIsBool($updatesInfo->installUpdatesAutomatically);
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/tests/ServicePlanAddonTest.php:
--------------------------------------------------------------------------------
1 | servicePlanAddon()->get('id', $servicePlanAddon->id);
12 |
13 | $this->assertNotEmpty($servicePlanAddonInfo->name);
14 | $this->assertSame($servicePlanAddon->id, $servicePlanAddonInfo->id);
15 | }
16 |
17 | public function testGetAll()
18 | {
19 | static::createServicePlanAddon();
20 | static::createServicePlanAddon();
21 | static::createServicePlanAddon();
22 |
23 | $servicePlanAddons = static::$client->servicePlanAddon()->getAll();
24 | $this->assertIsArray($servicePlanAddons);
25 | $this->assertGreaterThan(2, count($servicePlanAddons));
26 | $this->assertNotEmpty($servicePlanAddons[0]->name);
27 | }
28 |
29 | public function testCreate()
30 | {
31 | $servicePlanAddon = static::createServicePlanAddon();
32 | $this->assertGreaterThan(0, $servicePlanAddon->id);
33 |
34 | static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
35 | }
36 |
37 | public function testDelete()
38 | {
39 | $servicePlanAddon = static::createServicePlanAddon();
40 | $result = static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
41 |
42 | $this->assertTrue($result);
43 | }
44 |
45 | public function testCreateComplex()
46 | {
47 | $properties = [
48 | 'name' => 'Complex Service Plan Addon',
49 | 'limits' => [
50 | 'limit' => [
51 | 'name' => 'disk_space',
52 | 'value' => 1024 * 1024 * 1024, // 1 GB
53 | ],
54 | ],
55 | ];
56 |
57 | $servicePlanAddon = static::$client->servicePlanAddon()->create($properties);
58 | $this->assertGreaterThan(0, $servicePlanAddon->id);
59 |
60 | static::$client->servicePlanAddon()->delete('id', $servicePlanAddon->id);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tests/ServicePlanTest.php:
--------------------------------------------------------------------------------
1 | servicePlan()->get('id', $servicePlan->id);
12 | $this->assertNotEmpty($servicePlanInfo->name);
13 | $this->assertSame($servicePlan->id, $servicePlanInfo->id);
14 |
15 | static::$client->servicePlan()->delete('id', $servicePlan->id);
16 | }
17 |
18 | public function testGetAll()
19 | {
20 | static::createServicePlan();
21 | static::createServicePlan();
22 | static::createServicePlan();
23 |
24 | $servicePlans = static::$client->servicePlan()->getAll();
25 | $this->assertIsArray($servicePlans);
26 | $this->assertGreaterThan(2, count($servicePlans));
27 | $this->assertNotEmpty($servicePlans[0]->name);
28 | }
29 |
30 | public function testCreateServicePlan()
31 | {
32 | $servicePlan = static::createServicePlan();
33 | $this->assertGreaterThan(0, $servicePlan->id);
34 |
35 | static::$client->servicePlan()->delete('id', $servicePlan->id);
36 | }
37 |
38 | public function testDelete()
39 | {
40 | $servicePlan = static::createServicePlan();
41 | $result = static::$client->servicePlan()->delete('id', $servicePlan->id);
42 |
43 | $this->assertTrue($result);
44 | }
45 |
46 | public function testCreateComplexServicePlan()
47 | {
48 | $properties = [
49 | 'name' => 'Complex Service Plan',
50 | 'limits' => [
51 | 'overuse' => 'block',
52 | 'limit' => [
53 | 'name' => 'disk_space',
54 | 'value' => 1024 * 1024 * 1024, // 1 GB
55 | ],
56 | ],
57 | 'preferences' => [
58 | 'stat' => 6,
59 | 'maillists' => 'true',
60 | ],
61 | 'hosting' => [
62 | 'property' => [
63 | [
64 | 'name' => 'ftp_quota',
65 | 'value' => '-1',
66 | ],
67 | [
68 | 'name' => 'ssl',
69 | 'value' => 'true',
70 | ],
71 | ],
72 | ],
73 | ];
74 |
75 | $servicePlan = static::$client->servicePlan()->create($properties);
76 | $this->assertGreaterThan(0, $servicePlan->id);
77 |
78 | static::$client->servicePlan()->delete('id', $servicePlan->id);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/tests/SessionTest.php:
--------------------------------------------------------------------------------
1 | session()->create('admin', '127.0.0.1');
11 |
12 | $this->assertIsString($sessionToken);
13 | $this->assertGreaterThan(10, strlen($sessionToken));
14 | }
15 |
16 | public function testGet()
17 | {
18 | $sessionId = static::$client->server()->createSession('admin', '127.0.0.1');
19 | $sessions = static::$client->session()->get();
20 | $this->assertArrayHasKey($sessionId, $sessions);
21 |
22 | $sessionInfo = $sessions[$sessionId];
23 | $this->assertEquals('admin', $sessionInfo->login);
24 | $this->assertEquals('127.0.0.1', $sessionInfo->ipAddress);
25 | $this->assertEquals($sessionId, $sessionInfo->id);
26 | }
27 |
28 | public function testTerminate()
29 | {
30 | $sessionId = static::$client->server()->createSession('admin', '127.0.0.1');
31 | static::$client->session()->terminate($sessionId);
32 | $sessions = static::$client->session()->get();
33 | $this->assertArrayNotHasKey($sessionId, $sessions);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/SiteAliasTest.php:
--------------------------------------------------------------------------------
1 | $name,
20 | 'site-id' => static::$webspace->id,
21 | ], $properties);
22 |
23 | return static::$client->siteAlias()->create($properties);
24 | }
25 |
26 | public function testCreate()
27 | {
28 | $siteAlias = $this->createSiteAlias('alias.dom');
29 |
30 | $this->assertIsNumeric($siteAlias->id);
31 | $this->assertGreaterThan(0, $siteAlias->id);
32 |
33 | static::$client->siteAlias()->delete('id', $siteAlias->id);
34 | }
35 |
36 | public function testDelete()
37 | {
38 | $siteAlias = $this->createSiteAlias('alias.dom');
39 |
40 | $result = static::$client->siteAlias()->delete('id', $siteAlias->id);
41 | $this->assertTrue($result);
42 | }
43 |
44 | public function testGet()
45 | {
46 | $siteAlias = $this->createSiteAlias('alias.dom');
47 |
48 | $siteAliasInfo = static::$client->siteAlias()->get('id', $siteAlias->id);
49 | $this->assertEquals('alias.dom', $siteAliasInfo->name);
50 |
51 | static::$client->siteAlias()->delete('id', $siteAlias->id);
52 | }
53 |
54 | public function testGetAll()
55 | {
56 | $siteAlias = $this->createSiteAlias('alias.dom');
57 | $siteAlias2 = $this->createSiteAlias('alias2.dom');
58 |
59 | $siteAliasInfo = static::$client->siteAlias()->get('id', $siteAlias->id);
60 | $this->assertEquals('alias.dom', $siteAliasInfo->name);
61 |
62 | $siteAliasesInfo = static::$client->siteAlias()->getAll('site-id', self::$webspace->id);
63 | $this->assertCount(2, $siteAliasesInfo);
64 | $this->assertEquals('alias.dom', $siteAliasesInfo[0]->name);
65 | $this->assertEquals('alias.dom', $siteAliasesInfo[0]->asciiName);
66 |
67 | static::$client->siteAlias()->delete('id', $siteAlias->id);
68 | static::$client->siteAlias()->delete('id', $siteAlias2->id);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/tests/SiteTest.php:
--------------------------------------------------------------------------------
1 | server()->getKeyInfo();
23 |
24 | if (!KeyLimitChecker::checkByType($keyInfo, KeyLimitChecker::LIMIT_DOMAINS, 2)) {
25 | $this->markTestSkipped('License does not allow to create more than 1 domain.');
26 | }
27 | }
28 |
29 | private function createSite($name, array $properties = []): \PleskX\Api\Struct\Site\Info
30 | {
31 | $properties = array_merge([
32 | 'name' => $name,
33 | 'webspace-id' => static::$webspace->id,
34 | ], $properties);
35 |
36 | return static::$client->site()->create($properties);
37 | }
38 |
39 | public function testCreate()
40 | {
41 | $site = $this->createSite('addon.dom');
42 |
43 | $this->assertIsNumeric($site->id);
44 | $this->assertGreaterThan(0, $site->id);
45 |
46 | static::$client->site()->delete('id', $site->id);
47 | }
48 |
49 | public function testDelete()
50 | {
51 | $site = $this->createSite('addon.dom');
52 |
53 | $result = static::$client->site()->delete('id', $site->id);
54 | $this->assertTrue($result);
55 | }
56 |
57 | public function testGet()
58 | {
59 | $site = $this->createSite('addon.dom');
60 |
61 | $siteInfo = static::$client->site()->get('id', $site->id);
62 | $this->assertEquals('addon.dom', $siteInfo->name);
63 | $this->assertMatchesRegularExpression("/^\d{4}-\d{2}-\d{2}$/", $siteInfo->creationDate);
64 | $this->assertEquals(36, strlen($siteInfo->guid));
65 |
66 | $siteGuid = $siteInfo->guid;
67 | $siteInfo = static::$client->site()->get('guid', $siteGuid);
68 | $this->assertEquals($site->id, $siteInfo->id);
69 |
70 | static::$client->site()->delete('id', $site->id);
71 |
72 | $siteInfo = static::$client->site()->get('parent-id', static::$webspace->id);
73 | $this->assertNull($siteInfo);
74 | }
75 |
76 | public function testGetHostingWoHosting()
77 | {
78 | $site = $this->createSite('addon.dom');
79 |
80 | $siteHosting = static::$client->site()->getHosting('id', $site->id);
81 | $this->assertNull($siteHosting);
82 |
83 | static::$client->site()->delete('id', $site->id);
84 | }
85 |
86 | public function testGetHostingWithHosting()
87 | {
88 | $properties = [
89 | 'hosting' => [
90 | 'www_root' => 'addon.dom',
91 | ],
92 | ];
93 | $site = $this->createSite('addon.dom', $properties);
94 |
95 | $siteHosting = static::$client->site()->getHosting('id', $site->id);
96 | $this->assertArrayHasKey('www_root', $siteHosting->properties);
97 | $this->assertStringEndsWith('addon.dom', $siteHosting->properties['www_root']);
98 |
99 | static::$client->site()->delete('id', $site->id);
100 | }
101 |
102 | public function testGetAll()
103 | {
104 | $site = $this->createSite('addon.dom');
105 | $site2 = $this->createSite('addon2.dom');
106 |
107 | $sitesInfo = static::$client->site()->getAll();
108 | $this->assertCount(2, $sitesInfo);
109 | $this->assertEquals('addon.dom', $sitesInfo[0]->name);
110 | $this->assertEquals('addon.dom', $sitesInfo[0]->asciiName);
111 | $this->assertEquals($site->id, $sitesInfo[0]->id);
112 |
113 | static::$client->site()->delete('id', $site->id);
114 | static::$client->site()->delete('id', $site2->id);
115 | }
116 |
117 | public function testGetAllWithoutSites()
118 | {
119 | $sitesInfo = static::$client->site()->getAll();
120 | $this->assertEmpty($sitesInfo);
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/tests/SubdomainTest.php:
--------------------------------------------------------------------------------
1 | webspace()->get('id', static::$webspace->id);
16 | static::$webspaceName = $webspaceInfo->name;
17 | }
18 |
19 | private function createSubdomain(string $name): \PleskX\Api\Struct\Subdomain\Info
20 | {
21 | return static::$client->subdomain()->create([
22 | 'parent' => static::$webspaceName,
23 | 'name' => $name,
24 | 'property' => [
25 | 'www_root' => $name,
26 | ],
27 | ]);
28 | }
29 |
30 | public function testCreate()
31 | {
32 | $subdomain = $this->createSubdomain('sub');
33 |
34 | $this->assertIsInt($subdomain->id);
35 | $this->assertGreaterThan(0, $subdomain->id);
36 |
37 | static::$client->subdomain()->delete('id', $subdomain->id);
38 | }
39 |
40 | public function testDelete()
41 | {
42 | $subdomain = $this->createSubdomain('sub');
43 |
44 | $result = static::$client->subdomain()->delete('id', $subdomain->id);
45 | $this->assertTrue($result);
46 | }
47 |
48 | public function testGet()
49 | {
50 | $name = 'sub';
51 | $subdomain = $this->createSubdomain($name);
52 |
53 | $subdomainInfo = static::$client->subdomain()->get('id', $subdomain->id);
54 | $this->assertEquals($name . '.' . $subdomainInfo->parent, $subdomainInfo->name);
55 | $this->assertTrue(false !== strpos($subdomainInfo->properties['www_root'], $name));
56 | $this->assertEquals($subdomain->id, $subdomainInfo->id);
57 |
58 | static::$client->subdomain()->delete('id', $subdomain->id);
59 | }
60 |
61 | public function testGetAll()
62 | {
63 | $name = 'sub';
64 | $name2 = 'sub2';
65 | $subdomain = $this->createSubdomain($name);
66 | $subdomain2 = $this->createSubdomain($name2);
67 |
68 | $subdomainsInfo = static::$client->subdomain()->getAll();
69 | $this->assertCount(2, $subdomainsInfo);
70 | $this->assertEquals($name . '.' . $subdomainsInfo[0]->parent, $subdomainsInfo[0]->name);
71 | $this->assertTrue(false !== strpos($subdomainsInfo[0]->properties['www_root'], $name));
72 | $this->assertEquals($name2 . '.' . $subdomainsInfo[1]->parent, $subdomainsInfo[1]->name);
73 | $this->assertTrue(false !== strpos($subdomainsInfo[1]->properties['www_root'], $name2));
74 |
75 | static::$client->subdomain()->delete('id', $subdomain->id);
76 | static::$client->subdomain()->delete('id', $subdomain2->id);
77 |
78 | $subdomainsInfo = static::$client->subdomain()->getAll();
79 | $this->assertEmpty($subdomainsInfo);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/tests/UiTest.php:
--------------------------------------------------------------------------------
1 | 'admin',
10 | 'url' => 'http://example.com',
11 | 'text' => 'Example site',
12 | ];
13 |
14 | public function testGetNavigation()
15 | {
16 | $navigation = static::$client->ui()->getNavigation();
17 | $this->assertIsArray($navigation);
18 | $this->assertGreaterThan(0, count($navigation));
19 | $this->assertArrayHasKey('general', $navigation);
20 | $this->assertArrayHasKey('hosting', $navigation);
21 |
22 | $hostingSection = $navigation['hosting'];
23 | $this->assertArrayHasKey('name', $hostingSection);
24 | $this->assertArrayHasKey('nodes', $hostingSection);
25 | $this->assertGreaterThan(0, count($hostingSection['nodes']));
26 | }
27 |
28 | public function testCreateCustomButton()
29 | {
30 | $buttonId = static::$client->ui()->createCustomButton('admin', $this->customButtonProperties);
31 | $this->assertGreaterThan(0, $buttonId);
32 |
33 | static::$client->ui()->deleteCustomButton($buttonId);
34 | }
35 |
36 | public function testGetCustomButton()
37 | {
38 | $buttonId = static::$client->ui()->createCustomButton('admin', $this->customButtonProperties);
39 | $customButtonInfo = static::$client->ui()->getCustomButton($buttonId);
40 | $this->assertEquals('http://example.com', $customButtonInfo->url);
41 | $this->assertEquals('Example site', $customButtonInfo->text);
42 |
43 | static::$client->ui()->deleteCustomButton($buttonId);
44 | }
45 |
46 | public function testDeleteCustomButton()
47 | {
48 | $buttonId = static::$client->ui()->createCustomButton('admin', $this->customButtonProperties);
49 | $result = static::$client->ui()->deleteCustomButton($buttonId);
50 | $this->assertTrue($result);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/tests/Utility/KeyLimitChecker.php:
--------------------------------------------------------------------------------
1 | $minimalRequirement;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/tests/Utility/PasswordProvider.php:
--------------------------------------------------------------------------------
1 | webspace()->getPermissionDescriptor();
13 | $this->assertIsArray($descriptor->permissions);
14 | $this->assertNotEmpty($descriptor->permissions);
15 | }
16 |
17 | public function testGetLimitDescriptor()
18 | {
19 | $descriptor = static::$client->webspace()->getLimitDescriptor();
20 | $this->assertIsArray($descriptor->limits);
21 | $this->assertNotEmpty($descriptor->limits);
22 | }
23 |
24 | public function testGetDiskUsage()
25 | {
26 | $webspace = static::createWebspace();
27 | $diskusage = static::$client->webspace()->getDiskUsage('id', $webspace->id);
28 |
29 | $this->assertTrue(property_exists($diskusage, 'httpdocs'));
30 |
31 | static::$client->webspace()->delete('id', $webspace->id);
32 | }
33 |
34 | public function testGetPhysicalHostingDescriptor()
35 | {
36 | $descriptor = static::$client->webspace()->getPhysicalHostingDescriptor();
37 | $this->assertIsArray($descriptor->properties);
38 | $this->assertNotEmpty($descriptor->properties);
39 |
40 | $ftpLoginProperty = $descriptor->properties['ftp_login'];
41 | $this->assertEquals('ftp_login', $ftpLoginProperty->name);
42 | $this->assertEquals('string', $ftpLoginProperty->type);
43 | }
44 |
45 | public function testGetPhpSettings()
46 | {
47 | $webspace = static::createWebspace();
48 | $info = static::$client->webspace()->getPhpSettings('id', $webspace->id);
49 |
50 | $this->assertArrayHasKey('open_basedir', $info->properties);
51 |
52 | static::$client->webspace()->delete('id', $webspace->id);
53 | }
54 |
55 | public function testGetLimits()
56 | {
57 | $webspace = static::createWebspace();
58 | $limits = static::$client->webspace()->getLimits('id', $webspace->id);
59 |
60 | $this->assertIsArray($limits->limits);
61 | $this->assertNotEmpty($limits->limits);
62 |
63 | static::$client->webspace()->delete('id', $webspace->id);
64 | }
65 |
66 | public function testCreateWebspace()
67 | {
68 | $webspace = static::createWebspace();
69 |
70 | $this->assertGreaterThan(0, $webspace->id);
71 |
72 | static::$client->webspace()->delete('id', $webspace->id);
73 | }
74 |
75 | public function testDelete()
76 | {
77 | $webspace = static::createWebspace();
78 | $result = static::$client->webspace()->delete('id', $webspace->id);
79 |
80 | $this->assertTrue($result);
81 | }
82 |
83 | public function testDeleteByName()
84 | {
85 | $webspace = static::createWebspace();
86 | $result = static::$client->webspace()->delete('name', $webspace->name);
87 |
88 | $this->assertTrue($result);
89 | }
90 |
91 | public function testRequestCreateWebspace()
92 | {
93 | $handlers = static::$client->phpHandler()->getAll();
94 | $enabledHandlers = array_filter($handlers, function ($handler) {
95 | return $handler->handlerStatus !== 'disabled';
96 | });
97 | $this->assertGreaterThan(0, count($enabledHandlers));
98 | $handler = current($enabledHandlers);
99 |
100 | $request = [
101 | 'add' => [
102 | 'gen_setup' => [
103 | 'name' => 'webspace-test-full.test',
104 | 'htype' => 'vrt_hst',
105 | 'status' => '0',
106 | 'ip_address' => [static::getIpAddress()],
107 | ],
108 | 'hosting' => [
109 | 'vrt_hst' => [
110 | 'property' => [
111 | [
112 | 'name' => 'php_handler_id',
113 | 'value' => $handler->id,
114 | ],
115 | [
116 | 'name' => 'ftp_login',
117 | 'value' => 'testuser',
118 | ],
119 | [
120 | 'name' => 'ftp_password',
121 | 'value' => PasswordProvider::STRONG_PASSWORD,
122 | ],
123 | ],
124 | 'ip_address' => static::getIpAddress(),
125 | ],
126 | ],
127 | 'limits' => [
128 | 'overuse' => 'block',
129 | 'limit' => [
130 | [
131 | 'name' => 'mbox_quota',
132 | 'value' => 100,
133 | ],
134 | ],
135 | ],
136 | 'prefs' => [
137 | 'www' => 'false',
138 | 'stat_ttl' => 6,
139 | ],
140 | 'performance' => [
141 | 'bandwidth' => 120,
142 | 'max_connections' => 10000,
143 | ],
144 | 'permissions' => [
145 | 'permission' => [
146 | [
147 | 'name' => 'manage_sh_access',
148 | 'value' => 'true',
149 | ],
150 | ],
151 | ],
152 | 'php-settings' => [
153 | 'setting' => [
154 | [
155 | 'name' => 'memory_limit',
156 | 'value' => '128M',
157 | ],
158 | [
159 | 'name' => 'safe_mode',
160 | 'value' => 'false',
161 | ],
162 | ],
163 | ],
164 | 'plan-name' => 'Unlimited',
165 | ],
166 | ];
167 |
168 | $webspace = static::$client->webspace()->request($request);
169 |
170 | $this->assertGreaterThan(0, $webspace->id);
171 |
172 | static::$client->webspace()->delete('id', $webspace->id);
173 | }
174 |
175 | public function testGet()
176 | {
177 | $webspace = static::createWebspace();
178 | $webspaceInfo = static::$client->webspace()->get('id', $webspace->id);
179 |
180 | $this->assertNotEmpty($webspaceInfo->name);
181 | $this->assertEquals(0, $webspaceInfo->realSize);
182 | $this->assertEquals($webspaceInfo->name, $webspaceInfo->asciiName);
183 | $this->assertIsArray($webspaceInfo->ipAddresses);
184 | $this->assertEquals(36, strlen($webspaceInfo->guid));
185 | $this->assertMatchesRegularExpression("/^\d{4}-\d{2}-\d{2}$/", $webspaceInfo->creationDate);
186 | $this->assertEquals($webspace->id, $webspaceInfo->id);
187 |
188 | static::$client->webspace()->delete('id', $webspace->id);
189 | }
190 |
191 | public function testEnable()
192 | {
193 | $webspace = static::createWebspace();
194 |
195 | static::$client->webspace()->disable('id', $webspace->id);
196 | static::$client->webspace()->enable('id', $webspace->id);
197 | $webspaceInfo = static::$client->webspace()->get('id', $webspace->id);
198 | $this->assertTrue($webspaceInfo->enabled);
199 |
200 | static::$client->webspace()->delete('id', $webspace->id);
201 | }
202 |
203 | public function testDisable()
204 | {
205 | $webspace = static::createWebspace();
206 |
207 | static::$client->webspace()->disable('id', $webspace->id);
208 | $webspaceInfo = static::$client->webspace()->get('id', $webspace->id);
209 | $this->assertFalse($webspaceInfo->enabled);
210 |
211 | static::$client->webspace()->delete('id', $webspace->id);
212 | }
213 |
214 | public function testSetProperties()
215 | {
216 | $webspace = static::createWebspace();
217 | static::$client->webspace()->setProperties('id', $webspace->id, [
218 | 'description' => 'Test Description',
219 | ]);
220 | $webspaceInfo = static::$client->webspace()->get('id', $webspace->id);
221 | $this->assertEquals('Test Description', $webspaceInfo->description);
222 |
223 | static::$client->webspace()->delete('id', $webspace->id);
224 | }
225 |
226 | public function testIpsAsArray()
227 | {
228 | $webspace = static::$client->webspace()->create(
229 | [
230 | 'name' => "test-ips.test",
231 | 'ip_address' => [static::getIpAddress()],
232 | ],
233 | [
234 | 'ftp_login' => "u-ips",
235 | 'ftp_password' => PasswordProvider::STRONG_PASSWORD,
236 | ]
237 | );
238 |
239 | $this->assertGreaterThan(0, $webspace->id);
240 |
241 | static::$client->webspace()->delete('id', $webspace->id);
242 | }
243 | }
244 |
--------------------------------------------------------------------------------
/wait-for-plesk.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | ### Copyright 1999-2025. WebPros International GmbH.
3 |
4 | COUNTER=1
5 |
6 | while : ; do
7 | curl -ksL https://plesk:8443/ | grep "Plesk" > /dev/null
8 | [ $? -eq 0 ] && break
9 | echo "($COUNTER) Waiting for the Plesk initialization..."
10 | sleep 5
11 | COUNTER=$((COUNTER + 1))
12 | if [ $COUNTER -eq 60 ]; then
13 | echo "Too long, interrupting..."
14 | break
15 | fi
16 | done
17 |
--------------------------------------------------------------------------------