This commit is contained in:
cutemeli
2025-12-22 10:35:30 +00:00
parent 0bfc6c8425
commit 5ce7ca2c5d
38927 changed files with 0 additions and 4594700 deletions

View File

@@ -1,34 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Entity\ErrorResponse;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Entity\SecretKeyRequest;
use PleskExt\RestApi\v2\Entity\SecretKeyResponse;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class AuthKeys extends InvokableHandler
{
/**
* @Consumer(type=SecretKeyRequest::class)
*/
protected function post(Request $request, Response $response)
{
$secretKeyRequest = $this->consume();
$secretKey = new SecretKeyResponse();
$secretKey->key = SDK\pm_Auth::createSecretKey(\array_merge((array) $secretKeyRequest->ip, (array) $secretKeyRequest->ips) ?: null, $secretKeyRequest->description, $secretKeyRequest->login);
$response->getBody()->write($this->produce($secretKey));
return $response->withStatus(201);
}
protected function delete(Request $request, Response $response)
{
SDK\pm_Auth::deleteSecretKey($request->getAttribute('key'));
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,31 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\CliCallRequest;
use PleskExt\RestApi\v2\Entity\CliCallResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class CliCall extends InvokableHandler
{
/**
* @Consumer(type=CliCallRequest::class)
*/
protected function post(Request $request, Response $response)
{
$cmd = $request->getAttribute('id');
/** @var CliCallRequest $cliCall */
$cliCall = $this->consume();
$result = SDK\pm_ApiCli::call($cmd, $cliCall->params, \pm_ApiCli::RESULT_FULL, $cliCall->env);
$data = new CliCallResponse();
$data->code = (int) $result['code'];
$data->stdout = \trim((string) $result['stdout']);
$data->stderr = \trim((string) $result['stderr']);
$response->getBody()->write($this->serialize($data));
return $response;
}
}

View File

@@ -1,18 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class CliCommands extends InvokableHandler
{
protected function get(Request $request, Response $response)
{
$commands = SDK\pm_ApiCli::getCommands();
$response->getBody()->write($this->serialize($commands));
return $response;
}
}

View File

@@ -1,20 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class CliReference extends InvokableHandler
{
protected function get(Request $request, Response $response)
{
$result = SDK\pm_ApiCli::getReference($request->getAttribute('id'));
$result['allowed_commands'] = (object) $result['allowed_commands'];
$result['allowed_options'] = (object) $result['allowed_options'];
$response->getBody()->write($this->serialize($result));
return $response;
}
}

View File

@@ -1,36 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Clients as ClientsMapper;
use PleskExt\RestApi\v2\Mapper\Response as ResponseMapper;
use PleskExt\RestApi\v2\Entity\Client as ClientEntity;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Clients extends InvokableHandler
{
/**
* @Producer(mapper=ClientsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$clients = \pm_Client::getAll();
$response->getBody()->write($this->produce($clients));
return $response;
}
/**
* @Consumer(type=ClientEntity::class)
* @Producer(mapper=ResponseMapper::class)
*/
protected function post(Request $request, Response $response)
{
$client = SDK\pm_Client::create($this->consume());
$response->getBody()->write($this->produce($client));
return $response->withStatus(201);
}
}

View File

@@ -1,47 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Response as ResponseMapper;
use PleskExt\RestApi\v2\Mapper\Client as ClientMapper;
use PleskExt\RestApi\v2\Entity\Client as ClientEntity;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ClientsId extends InvokableHandler
{
/**
* @Producer(mapper=ClientMapper::class)
*/
protected function get(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$response->getBody()->write($this->produce($client));
return $response;
}
/**
* @Consumer(type=ClientEntity::class)
* @Producer(mapper=ResponseMapper::class)
*/
protected function put(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$client->update($this->consume());
$response->getBody()->write($this->produce($client));
return $response;
}
/**
* @Producer(mapper=ResponseMapper::class)
*/
protected function delete(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$client->delete();
$response->getBody()->write($this->produce($client));
return $response;
}
}

View File

@@ -1,20 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ClientsIdActivate extends InvokableHandler
{
protected function put(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$client->activate();
$response->getBody()->write($this->serialize(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,24 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Domains as DomainsMapper;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ClientsIdDomains extends InvokableHandler
{
/**
* @Producer(mapper=DomainsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$domains = \pm_Domain::getDomainsByClient($client);
$response->getBody()->write($this->produce($domains));
return $response;
}
}

View File

@@ -1,24 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\ClientStatistics as ClientStatisticsMapper;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ClientsIdStatistics extends InvokableHandler
{
/**
* @Producer(mapper=ClientStatisticsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$statistics = $client->getStatistics();
$response->getBody()->write($this->produce($statistics));
return $response;
}
}

View File

@@ -1,20 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ClientsIdSuspend extends InvokableHandler
{
protected function put(Request $request, Response $response)
{
$client = SDK\pm_Client::getByClientId($request->getAttribute('id'));
$client->suspend();
$response->getBody()->write($this->serialize(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,26 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\DatabaseServers as DatabaseServersMapper;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DatabaseServers extends InvokableHandler
{
/**
* @Producer(mapper=DatabaseServersMapper::class)
*/
protected function get(Request $request, Response $response)
{
if (null !== ($id = $this->getQueryParam('id'))) {
$response->getBody()->write($this->produce([SDK\pm_DatabaseServer::getById($id)]));
} else {
$response->getBody()->write($this->produce(SDK\pm_DatabaseServer::getAll()));
}
return $response;
}
}

View File

@@ -1,59 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Entity\DatabaseUser;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\DatabaseUser as DatabaseUserMapper;
use PleskExt\RestApi\v2\Mapper\DatabaseUsers as DatabaseUsersMapper;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DatabaseUsers extends InvokableHandler
{
/**
* @Producer(mapper=DatabaseUsersMapper::class)
*/
protected function get(Request $request, Response $response)
{
if (null !== ($databaseId = $this->getQueryParam('dbId'))) {
$database = SDK\pm_Database::getById($databaseId);
$users = SDK\pm_DatabaseUser::getForDatabase($database);
} else {
$users = SDK\pm_DatabaseUser::getAll();
}
$response->getBody()->write($this->produce($users));
return $response;
}
/**
* @Consumer(type=DatabaseUser::class)
*/
protected function put(Request $request, Response $response)
{
$user = SDK\pm_DatabaseUser::getById($request->getAttribute('id'));
$user->update($this->consume());
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
/**
* @Consumer(type=DatabaseUser::class)
* @Producer(mapper=DatabaseUserMapper::class)
*/
protected function post(Request $request, Response $response)
{
$user = SDK\pm_DatabaseUser::create($this->consume());
$response->getBody()->write($this->produce($user));
return $response;
}
protected function delete(Request $request, Response $response)
{
$user = SDK\pm_DatabaseUser::getById($request->getAttribute('id'));
$user->delete();
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,49 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Entity\DatabaseRequest;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Database as DatabaseMapper;
use PleskExt\RestApi\v2\Mapper\Databases as DatabasesMapper;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Databases extends InvokableHandler
{
/**
* @Producer(mapper=DatabasesMapper::class)
*/
protected function get(Request $request, Response $response)
{
if (null !== ($domainName = $this->getQueryParam('domain'))) {
$domain = SDK\pm_Domain::getByName($domainName);
$databases = SDK\pm_Database::getForDomain($domain);
} else {
$databases = SDK\pm_Database::getAll();
}
$response->getBody()->write($this->produce($databases));
return $response;
}
/**
* @Consumer(type=DatabaseRequest::class)
* @Producer(mapper=DatabaseMapper::class)
*/
protected function post(Request $request, Response $response)
{
$database = SDK\pm_Database::create($this->consume());
$response->getBody()->write($this->produce($database));
return $response;
}
protected function delete(Request $request, Response $response)
{
$database = SDK\pm_Database::getById($request->getAttribute('id'));
$database->delete();
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,120 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Entity;
use PleskExt\RestApi\v2\Mapper;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK\Exception\InvalidDataException;
use PleskExt\RestApi\v2\SDK\Exception\NotFoundException;
use PleskExt\RestApi\v2\SDK\Helper\VersionTrait;
use PleskExt\RestApi\v2\SDK\pm_DnsRecord;
use PleskExt\RestApi\v2\SDK\pm_Domain;
use PleskExt\RestApi\v2\SDK\pm_DomainAlias;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DnsRecords extends InvokableHandler
{
use VersionTrait;
public function __call($name, $args)
{
self::requiredVersion('18.0.33');
if (\method_exists($this, $name)) {
return \call_user_func_array(array($this, $name), $args);
} else {
return parent::__call($name, $args);
}
}
/**
* @Producer(mapper=Mapper\DnsRecords::class)
*/
private function get(Request $request, Response $response)
{
$id = $request->getAttribute('id');
if ($id !== null) {
if (!\ctype_digit($id)) {
throw new InvalidDataException("Invalid DNS record id '{$id}'");
}
$dnsrec = pm_DnsRecord::getById($id);
$response->getBody()->write($this->produce($dnsrec));
} elseif ($domain = $this->getQueryParam('domain')) {
$dnsZone = $this->getDomainOrAliasDnsZoneByName($domain);
$dnsrecs = $dnsZone->getRecords();
$response->getBody()->write($this->produce($dnsrecs));
} else {
throw new InvalidDataException();
}
}
/**
* @Consumer(type=Entity\DnsRecordRequest::class)
* @Producer(mapper=Mapper\DnsRecords::class)
*/
private function post(Request $request, Response $response)
{
if (null === ($domainName = $this->getQueryParam('domain'))) {
throw new InvalidDataException();
}
$zone = $this->getDomainOrAliasDnsZoneByName($domainName);
/** @var Entity\DnsRecordRequest $entity */
$entity = $this->consume();
$dnsrec = new \pm_Dns_Record();
try {
$dnsrec->setType($entity->type)->setHost($entity->host)->setValue($entity->value)->setOption($entity->opt)->setTtl($entity->ttl)->setZone($zone);
} catch (\TypeError $e) {
throw new InvalidDataException();
}
pm_DnsRecord::save($dnsrec);
$response->getBody()->write($this->produce($dnsrec));
return $response;
}
/**
* @Consumer(type=Entity\DnsRecord::class)
*/
private function put(Request $request, Response $response)
{
$id = $request->getAttribute('id');
if (!\ctype_digit($id)) {
throw new InvalidDataException("Invalid DNS record id '{$id}'");
}
$dnsrec = pm_DnsRecord::getById($id);
$entity = $this->consume();
try {
$dnsrec->setId($id)->setType($entity->type)->setHost($entity->host)->setValue($entity->value)->setOption($entity->opt)->setTtl($entity->ttl);
} catch (\TypeError $e) {
throw new InvalidDataException();
}
pm_DnsRecord::save($dnsrec);
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
private function delete(Request $request, Response $response)
{
$id = $request->getAttribute('id');
if (!\ctype_digit($id)) {
throw new InvalidDataException("Invalid DNS record id '{$id}'");
}
pm_DnsRecord::getById($id)->remove();
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
/**
* @throws NotFoundException
* @throws \pm_Exception
*/
private function getDomainOrAliasDnsZoneByName(string $name) : \pm_Dns_Zone
{
try {
return pm_Domain::getByName($name)->getDnsZone();
} catch (NotFoundException $e) {
try {
return pm_DomainAlias::getByName($name)->getDnsZone();
} catch (NotFoundException $e) {
throw new NotFoundException("Domain or Domain Alias not found by name '{$name}'", $e->getCode(), $e);
}
}
}
}

View File

@@ -1,16 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\ApiReference;
use PleskExt\RestApi\v2\Helper\Application;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Documentation
{
public function __invoke(Request $request, Response $response)
{
return Application::get()->getContainer()->get('renderer')->render($response, 'v2/ui.phtml', ['schemas' => \json_encode(ApiReference::getSchemas())]);
}
}

View File

@@ -1,45 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Domains as DomainsMapper;
use PleskExt\RestApi\v2\Mapper\Response as ResponseMapper;
use PleskExt\RestApi\v2\Entity\DomainRequest as DomainRequestEntity;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Domains extends InvokableHandler
{
/**
* @Producer(mapper=DomainsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$domains = [];
$name = $this->getQueryParam('name');
if ($name) {
try {
$domains = [SDK\pm_Domain::getByName($name)];
} catch (SDK\Exception\NotFoundException $e) {
}
} else {
$domains = SDK\pm_Domain::getAllDomains();
}
$response->getBody()->write($this->produce($domains));
return $response;
}
/**
* @Consumer(type=DomainRequestEntity::class)
* @Producer(mapper=ResponseMapper::class)
*/
protected function post(Request $request, Response $response)
{
$domain = SDK\pm_Domain::create($this->consume());
$response->getBody()->write($this->produce($domain));
return $response->withStatus(201);
}
}

View File

@@ -1,47 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Domain as DomainMapper;
use PleskExt\RestApi\v2\Mapper\Response as ResponseMapper;
use PleskExt\RestApi\v2\Entity\DomainRequest as DomainRequestEntity;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DomainsId extends InvokableHandler
{
/**
* @Producer(mapper=DomainMapper::class)
*/
protected function get(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$response->getBody()->write($this->produce($domain));
return $response;
}
/**
* @Consumer(type=DomainRequestEntity::class)
* @Producer(mapper=ResponseMapper::class)
*/
protected function put(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$domain->update($this->consume());
$response->getBody()->write($this->produce($domain));
return $response;
}
/**
* @Producer(mapper=ResponseMapper::class)
*/
protected function delete(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$domain->delete();
$response->getBody()->write($this->produce($domain));
return $response;
}
}

View File

@@ -1,23 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\Client as ClientMapper;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DomainsIdClient extends InvokableHandler
{
/**
* @Producer(mapper=ClientMapper::class)
*/
protected function get(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$response->getBody()->write($this->produce($domain->getClient()));
return $response;
}
}

View File

@@ -1,36 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Mapper\DomainStatus as DomainStatusMapper;
use PleskExt\RestApi\v2\Entity\DomainStatus as DomainStatusEntity;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class DomainsIdStatus extends InvokableHandler
{
/**
* @Producer(mapper=DomainStatusMapper::class)
*/
protected function get(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$response->getBody()->write($this->produce($domain));
return $response;
}
/**
* @Consumer(type=DomainStatusEntity::class)
* @Producer(mapper=DomainStatusMapper::class)
*/
protected function put(Request $request, Response $response)
{
$domain = SDK\pm_Domain::getByDomainId($request->getAttribute('id'));
$domain->setStatus($this->consume());
$response->getBody()->write($this->produce(SDK\pm_Domain::getByDomainId($request->getAttribute('id'))));
return $response;
}
}

View File

@@ -1,48 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Mapper\Extensions as ExtensionsMapper;
use PleskExt\RestApi\v2\Mapper\Extension as ExtensionMapper;
use PleskExt\RestApi\v2\Entity\ExtensionInstallRequest;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\Exception\InvalidDataException;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Extensions extends InvokableHandler
{
/**
* @Producer(mapper=ExtensionsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$extensions = SDK\pm_Extension::getExtensions();
$response->getBody()->write($this->produce($extensions));
return $response;
}
/**
* @Consumer(type=ExtensionInstallRequest::class)
* @Producer(mapper=ExtensionMapper::class)
*/
protected function post(Request $request, Response $response)
{
/** @var ExtensionInstallRequest $requestData */
$requestData = $this->consume();
if ($requestData->id) {
SDK\pm_Extension::installById($requestData->id);
} elseif ($requestData->url) {
SDK\pm_Extension::installByUrl($requestData->url);
} elseif ($requestData->file) {
SDK\pm_Extension::installByFile($requestData->file);
} else {
throw new InvalidDataException("Unsupported installation type");
}
$response->getBody()->write($this->serialize(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,32 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Mapper\Extension as ExtensionMapper;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ExtensionsId extends InvokableHandler
{
/**
* @Producer(mapper=ExtensionMapper::class)
*/
protected function get(Request $request, Response $response)
{
$extension = SDK\pm_Extension::getById($request->getAttribute('id'));
$response->getBody()->write($this->produce($extension));
return $response;
}
protected function delete(Request $request, Response $response)
{
$successResponseData = $this->serialize(new SuccessResponse());
$extension = SDK\pm_Extension::getById($request->getAttribute('id'));
$extension->uninstall();
$response->getBody()->write($successResponseData);
return $response;
}
}

View File

@@ -1,20 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ExtensionsIdDisable extends InvokableHandler
{
protected function put(Request $request, Response $response)
{
$extension = SDK\pm_Extension::getById($request->getAttribute('id'));
$extension->disable();
$response->getBody()->write($this->serialize(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,20 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ExtensionsIdEnable extends InvokableHandler
{
protected function put(Request $request, Response $response)
{
$extension = SDK\pm_Extension::getById($request->getAttribute('id'));
$extension->enable();
$response->getBody()->write($this->serialize(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,62 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Entity\FtpUserRequest;
use PleskExt\RestApi\v2\Entity\FtpUserUpdateRequest;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\FtpUser as FtpUserMapper;
use PleskExt\RestApi\v2\Mapper\FtpUsers as FtpUsersMapper;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class FtpUsers extends InvokableHandler
{
/**
* @Producer(mapper=FtpUsersMapper::class)
*/
protected function get(Request $request, Response $response)
{
if (null !== ($name = $this->getQueryParam('name'))) {
$users = [SDK\pm_FtpUser::getByName($name)];
} elseif (null !== ($domainName = $this->getQueryParam('domain'))) {
$domain = SDK\pm_Domain::getByName($domainName);
$users = SDK\pm_FtpUser::getForDomain($domain);
} else {
$users = SDK\pm_FtpUser::getAll();
}
$response->getBody()->write($this->produce($users));
return $response;
}
/**
* @Consumer(type=FtpUserUpdateRequest::class)
*/
protected function put(Request $request, Response $response)
{
$user = SDK\pm_FtpUser::getByName($request->getAttribute('name'));
$user->update($this->consume());
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
/**
* @Consumer(type=FtpUserRequest::class)
* @Producer(mapper=FtpUserMapper::class)
*/
protected function post(Request $request, Response $response)
{
$user = SDK\pm_FtpUser::create($this->consume());
$response->getBody()->write($this->produce($user));
return $response;
}
protected function delete(Request $request, Response $response)
{
$user = SDK\pm_FtpUser::getByName($request->getAttribute('name'));
$user->delete();
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,30 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\SDK;
use PleskExt\RestApi\v2\Entity\ServerMeta;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class Server extends InvokableHandler
{
protected function get(Request $request, Response $response)
{
$entity = new ServerMeta();
$entity->platform = SDK\pm_ProductInfo::getPlatform();
$entity->hostname = SDK\pm_Server::getHostname();
$entity->guid = SDK\pm_Server::getGuid();
$entity->panel_version = SDK\pm_ProductInfo::getVersion();
$entity->panel_revision = SDK\pm_ProductInfo::getRevision();
$entity->panel_build_date = \date('Y-m-d', SDK\pm_ProductInfo::getBuildDate());
$entity->panel_update_version = SDK\pm_ProductInfo::getLastInstalledUpdate();
$extension = \pm_Extension::getById('rest-api');
$entity->extension_version = $extension->getVersion();
$entity->extension_release = $extension->getRelease();
$response->getBody()->write($this->serialize($entity));
return $response;
}
}

View File

@@ -1,26 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Entity\ServerInit as ServerInitEntity;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ServerInit extends InvokableHandler
{
/**
* @Consumer(type=ServerInitEntity::class)
*/
protected function post(Request $request, Response $response)
{
/** @var ServerInitEntity $serverInit */
$serverInit = $this->consume();
SDK\pm_Server::initSetup($serverInit->admin, $serverInit->password, $serverInit->server_name);
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}

View File

@@ -1,23 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Producer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Mapper\ServerIps as ServerIpsMapper;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ServerIps extends InvokableHandler
{
/**
* @Producer(mapper=ServerIpsMapper::class)
*/
protected function get(Request $request, Response $response)
{
$ipAddresses = SDK\pm_Server::getIpAddresses();
$response->getBody()->write($this->produce($ipAddresses));
return $response;
}
}

View File

@@ -1,26 +0,0 @@
<?php
// Copyright 1999-2024. WebPros International GmbH. All rights reserved.
namespace PleskExt\RestApi\v2\Handler;
use PleskExt\RestApi\v2\Annotation\Consumer;
use PleskExt\RestApi\v2\Helper\InvokableHandler;
use PleskExt\RestApi\v2\Entity\ServerLicense as ServerLicenseEntity;
use PleskExt\RestApi\v2\Entity\SuccessResponse;
use PleskExt\RestApi\v2\SDK;
use PleskRestApi\Slim\Psr7\Request;
use PleskRestApi\Slim\Psr7\Response;
class ServerLicense extends InvokableHandler
{
/**
* @Consumer(type=ServerLicenseEntity::class)
*/
protected function post(Request $request, Response $response)
{
/** @var ServerLicenseEntity $serverLicense */
$serverLicense = $this->consume();
SDK\pm_License::install($serverLicense);
$response->getBody()->write($this->produce(new SuccessResponse()));
return $response;
}
}