diff --git a/composer.json b/composer.json index e141239f..b4b82965 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "plesk/api-php-lib", + "name": "clonixdev/api-php-lib", "type": "library", "description": "PHP object-oriented library for Plesk XML-RPC API", "license": "Apache-2.0", @@ -54,5 +54,11 @@ "branch-alias": { "dev-master": "2.0.x-dev" } + }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/clonixdev/api-php-lib" } +] } diff --git a/src/Api/Client.php b/src/Api/Client.php index 7895ab0e..11a68d2a 100644 --- a/src/Api/Client.php +++ b/src/Api/Client.php @@ -460,6 +460,11 @@ public function subdomain(): Operator\Subdomain return $this->getOperator('Subdomain'); } + public function ftpUser(): Operator\FtpUser + { + return $this->getOperator('FtpUser'); + } + public function dns(): Operator\Dns { return $this->getOperator('Dns'); diff --git a/src/Api/Operator/FtpUser.php b/src/Api/Operator/FtpUser.php new file mode 100644 index 00000000..855564a4 --- /dev/null +++ b/src/Api/Operator/FtpUser.php @@ -0,0 +1,89 @@ +client->getPacket(); + $info = $packet->addChild($this->wrapperTag)->addChild('create'); + + $filter = $info->addChild('filter'); + $filter->addChild('site-id', (string) $siteId); + $mailname = $filter->addChild('mailname'); + $mailname->addChild('name', $name); + if ($mailbox) { + $mailname->addChild('mailbox')->addChild('enabled', 'true'); + } + if (!empty($password)) { + $mailname->addChild('password')->value = $password; + } + + $response = $this->client->request($packet); + + return new Struct\Info($response->mailname); + } + + /** + * @param string $field + * @param int|string $value + * @param int $siteId + * + * @return bool + */ + public function delete(string $field, $value, int $siteId): bool + { + $packet = $this->client->getPacket(); + $filter = $packet->addChild($this->wrapperTag)->addChild('remove')->addChild('filter'); + + $filter->addChild('site-id', (string) $siteId); + $filter->{$field} = (string) $value; + + $response = $this->client->request($packet); + + return 'ok' === (string) $response->status; + } + + public function get(string $name, int $siteId): Struct\GeneralInfo + { + $items = $this->getAll($siteId, $name); + + return reset($items); + } + + /** + * @param int $siteId + * @param string|null $name + * + * @return Struct\GeneralInfo[] + */ + public function getAll(int $siteId, $name = null): array + { + $packet = $this->client->getPacket(); + $getTag = $packet->addChild($this->wrapperTag)->addChild('get_info'); + + $filterTag = $getTag->addChild('filter'); + $filterTag->addChild('site-id', (string) $siteId); + if (!is_null($name)) { + $filterTag->addChild('name', $name); + } + + $response = $this->client->request($packet, Client::RESPONSE_FULL); + $items = []; + foreach ((array) $response->xpath('//result') as $xmlResult) { + if (!$xmlResult || !isset($xmlResult->mailname)) { + continue; + } + $item = new Struct\GeneralInfo($xmlResult->mailname); + $items[] = $item; + } + + return $items; + } +} diff --git a/src/Api/Struct/FtpUser/GeneralInfo.php b/src/Api/Struct/FtpUser/GeneralInfo.php new file mode 100644 index 00000000..e8b149b3 --- /dev/null +++ b/src/Api/Struct/FtpUser/GeneralInfo.php @@ -0,0 +1,22 @@ +initScalarProperties($apiResponse, [ + 'id', + 'name', + 'description', + ]); + } +} diff --git a/src/Api/Struct/FtpUser/Info.php b/src/Api/Struct/FtpUser/Info.php new file mode 100644 index 00000000..bf4cbc3a --- /dev/null +++ b/src/Api/Struct/FtpUser/Info.php @@ -0,0 +1,20 @@ +initScalarProperties($apiResponse, [ + 'id', + 'name', + ]); + } +}