2022-01-26 19:36:56 +01:00
|
|
|
<?php declare(strict_types=1);
|
2022-01-31 20:49:44 +01:00
|
|
|
|
2022-01-18 19:14:24 +01:00
|
|
|
namespace App\Controller;
|
|
|
|
|
2022-01-26 19:36:56 +01:00
|
|
|
error_reporting(error_level: E_ALL);
|
|
|
|
|
2022-02-06 17:58:52 +01:00
|
|
|
use App\Entity\Domain;
|
2022-01-31 20:49:44 +01:00
|
|
|
use App\Repository\ApikeyRepository;
|
|
|
|
use App\Repository\DomainRepository;
|
|
|
|
use DI\Container;
|
|
|
|
use DI\ContainerBuilder;
|
2022-02-12 19:27:38 +01:00
|
|
|
use Monolog\Formatter\LineFormatter;
|
|
|
|
use Monolog\Handler\StreamHandler;
|
|
|
|
use Monolog\Logger;
|
2022-02-01 20:39:46 +01:00
|
|
|
use OpenApi\Generator;
|
2022-01-20 11:06:58 +01:00
|
|
|
use UnhandledMatchError;
|
2022-01-31 20:49:44 +01:00
|
|
|
use function DI\autowire;
|
2022-02-01 20:39:46 +01:00
|
|
|
use OpenApi\Attributes as OAT;
|
2022-01-18 19:14:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2022-02-06 17:58:52 +01:00
|
|
|
#[OAT\Info(version: '0.0.1', title: 'bindAPI')]
|
|
|
|
#[OAT\Server(
|
|
|
|
url: "{schema}://{hostname}/api",
|
|
|
|
description: "The bindAPI URL.",
|
|
|
|
variables: [
|
|
|
|
new OAT\ServerVariable(
|
|
|
|
serverVariable: "schema",
|
|
|
|
default: "https",
|
|
|
|
enum: ["https", "http"]
|
|
|
|
),
|
|
|
|
new OAT\ServerVariable(
|
|
|
|
serverVariable: "hostname",
|
|
|
|
default: "ns2.24unix.net",
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)]
|
|
|
|
#[OAT\Tag(
|
|
|
|
name: "Server"
|
|
|
|
)]
|
|
|
|
#[OAT\SecurityScheme(
|
|
|
|
securityScheme: "Authorization",
|
|
|
|
type: "apiKey",
|
|
|
|
description: "description",
|
|
|
|
name: "X-API-Key",
|
|
|
|
in: "header"
|
|
|
|
)]
|
2022-01-18 19:14:24 +01:00
|
|
|
class RequestController
|
|
|
|
{
|
2022-02-12 19:27:38 +01:00
|
|
|
private Logger $log;
|
|
|
|
|
2022-01-31 20:49:44 +01:00
|
|
|
//private DatabaseConnection $databaseConnection;
|
|
|
|
private DomainRepository $domainRepository;
|
|
|
|
private ApikeyRepository $apikeyRepository;
|
|
|
|
private Container $container;
|
|
|
|
private string $header;
|
2022-01-20 11:06:58 +01:00
|
|
|
private array $result;
|
2022-01-31 20:49:44 +01:00
|
|
|
private string $status;
|
|
|
|
private string $message;
|
2022-01-18 19:14:24 +01:00
|
|
|
|
2022-01-20 11:06:58 +01:00
|
|
|
/**
|
2022-01-25 20:50:26 +01:00
|
|
|
* @param array $config
|
|
|
|
* @param String $requestMethod
|
|
|
|
* @param array $uri
|
2022-01-31 20:49:44 +01:00
|
|
|
*
|
|
|
|
* @throws \Exception
|
2022-01-20 11:06:58 +01:00
|
|
|
*/
|
2022-01-31 20:49:44 +01:00
|
|
|
public function __construct(private array $config, private string $requestMethod, private array $uri)
|
2022-01-18 19:14:24 +01:00
|
|
|
{
|
2022-01-26 19:36:56 +01:00
|
|
|
$this->requestMethod = strtoupper(string: $requestMethod);
|
2022-01-31 20:49:44 +01:00
|
|
|
|
2022-02-12 19:27:38 +01:00
|
|
|
|
|
|
|
$dateFormat = "Y:m:d H:i:s";
|
|
|
|
$output = "%datetime% %channel%.%level_name% %message%\n"; // %context% %extra%
|
|
|
|
$formatter = new LineFormatter(format: $output, dateFormat: $dateFormat);
|
|
|
|
|
|
|
|
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 2) . '/bindAPI.log');
|
|
|
|
$stream->setFormatter(formatter: $formatter);
|
|
|
|
|
|
|
|
$this->log = new Logger(name: 'bindAPI');
|
|
|
|
$this->log->pushHandler(handler: $stream);
|
|
|
|
|
|
|
|
|
2022-01-31 20:49:44 +01:00
|
|
|
$containerBuilder = new ContainerBuilder();
|
|
|
|
$containerBuilder->addDefinitions([
|
|
|
|
DatabaseConnection::class => autowire()->constructorParameter(parameter: 'config', value: $this->config),
|
2022-02-12 19:27:38 +01:00
|
|
|
DomainRepository::class => autowire()
|
|
|
|
->constructorParameter(parameter: 'config', value: $this->config)
|
|
|
|
->constructorParameter(parameter: 'log', value: $this->log),
|
|
|
|
|
2022-01-31 20:49:44 +01:00
|
|
|
]);
|
|
|
|
$this->container = $containerBuilder->build();
|
|
|
|
|
|
|
|
$this->domainRepository = $this->container->get(name: DomainRepository::class);
|
|
|
|
$this->apikeyRepository = $this->container->get(name: ApikeyRepository::class);
|
|
|
|
|
2022-01-18 19:14:24 +01:00
|
|
|
}
|
2022-01-20 11:06:58 +01:00
|
|
|
|
|
|
|
/**
|
2022-02-06 17:58:52 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
#[OAT\Get(
|
|
|
|
path: '/domains',
|
|
|
|
operationId: 'getAllDomains',
|
|
|
|
description: 'Returns a list of all domains on this server.',
|
|
|
|
summary: 'Listing all domains.',
|
|
|
|
// security: [
|
|
|
|
// 'Authorization' => [
|
|
|
|
//
|
|
|
|
// "read:api"
|
|
|
|
// ]
|
|
|
|
// ],
|
|
|
|
servers: [],
|
|
|
|
tags: ['Domains'],
|
|
|
|
responses: [
|
|
|
|
new OAT\Response(
|
|
|
|
response: 200,
|
|
|
|
description: 'OK'
|
|
|
|
),
|
|
|
|
new OAT\Response(
|
|
|
|
response: 401,
|
|
|
|
description: 'API key is missing or invalid.'
|
|
|
|
),
|
|
|
|
new OAT\Response(
|
|
|
|
response: 404,
|
|
|
|
description: 'Domain not found.'
|
|
|
|
)]
|
|
|
|
)]
|
|
|
|
public function handleAllDomainsGetRequest(): void
|
|
|
|
{
|
|
|
|
$domains = $this->domainRepository->findAll();
|
|
|
|
$resultDomain = [];
|
|
|
|
foreach ($domains as $singleDomain) {
|
|
|
|
$domain = [
|
2022-02-12 19:27:38 +01:00
|
|
|
'id' => $singleDomain->getId(),
|
|
|
|
'name' => $singleDomain->getName(),
|
|
|
|
'content' => json_decode(json: $singleDomain->getContent())
|
2022-02-06 17:58:52 +01:00
|
|
|
];
|
|
|
|
$resultDomain[] = $domain;
|
|
|
|
}
|
|
|
|
$this->result = $resultDomain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-02-01 20:39:46 +01:00
|
|
|
* @OA\Tag(name = "Server")
|
|
|
|
* @OA\Get(
|
|
|
|
* path = "/ping",
|
|
|
|
* summary = "Returning pong.",
|
|
|
|
* description = "Can be used to check API or server availability.",
|
|
|
|
* tags={"Server"},
|
|
|
|
* @OA\Response(response = "200", description = "OK"),
|
|
|
|
* @OA\Response(response = "401", description = "API key is missing or invalid."),
|
|
|
|
* security={
|
|
|
|
* {"Authorization":{"read"}}
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
*
|
|
|
|
* @OA\Tag(name = "Domains")
|
|
|
|
* @OA\Put(
|
|
|
|
* path="/domains/{name}",
|
|
|
|
* summary="Updates a domain.",
|
|
|
|
* description="Updates a domain. Only supplied fields will be updated, existing won't be affected.",
|
|
|
|
* tags={"Domains"},
|
|
|
|
* @OA\Response(response="200", description="OK"),
|
|
|
|
* @OA\Response(response = "401", description = "API key is missing or invalid."),
|
|
|
|
* @OA\Response(response="404", description="Domain not found."),
|
|
|
|
* security={
|
|
|
|
* {"Authorization":{"read":"write"}}
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
* @OA\Delete (
|
|
|
|
* path="/domains/{name}",
|
|
|
|
* summary="Deletes a domain.",
|
|
|
|
* description="Deletes a domain.",
|
|
|
|
* tags={"Domains"},
|
|
|
|
* @OA\Response(response="200", description="OK"),
|
|
|
|
* @OA\Response(response = "401", description = "API key is missing or invalid."),
|
|
|
|
* @OA\Response(response="404", description="Domain not found."),
|
|
|
|
* security={
|
|
|
|
* {"Authorization":{"read":"write"}}
|
|
|
|
* }
|
|
|
|
* )
|
2022-01-20 11:06:58 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-02-06 17:58:52 +01:00
|
|
|
|
|
|
|
#[OAT\Get(
|
|
|
|
path: '/domains/{name}',
|
|
|
|
operationId: 'getSingleDomain',
|
|
|
|
description: 'Returns information of a single domain specified by its domain name.',
|
|
|
|
summary: 'Returns a single domain.',
|
|
|
|
security: [
|
|
|
|
],
|
|
|
|
tags: ['Domains'],
|
|
|
|
parameters: [
|
|
|
|
new OAT\Parameter(name: 'name', in: 'path', required: true, schema: new OAT\Schema(type: 'string')),
|
|
|
|
],
|
|
|
|
responses: [
|
|
|
|
new OAT\Response(
|
|
|
|
response: 200,
|
|
|
|
description: 'OK'
|
|
|
|
),
|
|
|
|
new OAT\Response(
|
|
|
|
response: 401,
|
|
|
|
description: 'API key is missing or invalid.'
|
|
|
|
),
|
|
|
|
new OAT\Response(
|
|
|
|
response: 404,
|
|
|
|
description: 'Domain not found.'
|
|
|
|
)]
|
|
|
|
|
|
|
|
)]
|
2022-01-18 19:14:24 +01:00
|
|
|
public function processRequest()
|
|
|
|
{
|
2022-02-01 20:39:46 +01:00
|
|
|
$command = $this->uri[2];
|
|
|
|
|
|
|
|
if (empty($command) || !(($command == 'domains') || ($command == 'ping') || ($command == 'apidoc'))) {
|
2022-01-25 20:50:26 +01:00
|
|
|
$this->header = '404 Not Found';
|
2022-01-18 19:14:24 +01:00
|
|
|
$this->status = "404 Not Found";
|
|
|
|
$this->message = "Endpoint not found.";
|
|
|
|
} else {
|
2022-02-01 20:39:46 +01:00
|
|
|
if ($command == 'apidoc') {
|
|
|
|
$openapi = Generator::scan(sources: [__DIR__ . 'RequestController.php']);
|
|
|
|
$this->status = 'openapi';
|
|
|
|
$this->result[] = $openapi->toJson();
|
|
|
|
} else {
|
|
|
|
if ($this->checkPassword()) {
|
|
|
|
|
|
|
|
if ($this->uri[2] == "ping") {
|
|
|
|
$this->header = '200 OK';
|
|
|
|
$this->status = 'pong';
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
match ($this->requestMethod) {
|
|
|
|
'GET' => $this->handleDomainGetRequest(),
|
|
|
|
'POST' => $this->handleDomainPostRequest(),
|
|
|
|
'PUT' => $this->handleDomainPutRequest(),
|
|
|
|
'DELETE' => $this->handleDomainDeleteRequest()
|
|
|
|
};
|
|
|
|
} catch (UnhandledMatchError) {
|
|
|
|
$this->header = '400 Bad Request';
|
|
|
|
$this->status = '400 Bad Request';
|
|
|
|
$this->message = "unknown request method: $this->requestMethod";
|
|
|
|
}
|
2022-01-24 18:57:47 +01:00
|
|
|
}
|
2022-01-18 19:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-01 20:39:46 +01:00
|
|
|
|
|
|
|
if (!empty($this->header)) {
|
|
|
|
header(header: $_SERVER['SERVER_PROTOCOL'] . ' ' . $this->header);
|
|
|
|
}
|
|
|
|
if (!empty($this->result)) {
|
|
|
|
if (!empty($this->status) && $this->status == 'openapi') {
|
|
|
|
header(header: 'Content-Type: application/json');
|
|
|
|
echo $this->result[0];
|
|
|
|
} else {
|
|
|
|
echo json_encode(value: $this->result);
|
|
|
|
}
|
2022-01-24 18:57:47 +01:00
|
|
|
} else {
|
2022-02-01 20:39:46 +01:00
|
|
|
if (!empty($this->status) && $this->status == 'pong') {
|
|
|
|
echo json_encode(value: [
|
|
|
|
'response' => $this->status
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
echo json_encode(value: [
|
|
|
|
'status' => $this->status ?? "Error: No status",
|
|
|
|
'message' => $this->message ?? "Error: No message."
|
|
|
|
]);
|
|
|
|
}
|
2022-01-24 18:57:47 +01:00
|
|
|
}
|
2022-01-18 19:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function checkPassword(): bool
|
|
|
|
{
|
2022-01-26 19:36:56 +01:00
|
|
|
$headers = array_change_key_case(array: getallheaders(), case: CASE_UPPER);
|
|
|
|
$apiKey = $headers['X-API-KEY'] ?? '';
|
2022-01-18 19:14:24 +01:00
|
|
|
|
|
|
|
if (empty($apiKey)) {
|
2022-01-25 20:50:26 +01:00
|
|
|
$this->header = "401 Unauthorized";
|
2022-01-18 19:14:24 +01:00
|
|
|
$this->status = "401 Unauthorized";
|
|
|
|
$this->message = "API key is missing.";
|
|
|
|
return false;
|
|
|
|
} else {
|
2022-01-26 19:36:56 +01:00
|
|
|
[$prefix,] = explode(separator: '.', string: $apiKey);
|
2022-01-31 20:49:44 +01:00
|
|
|
if ($apiResult = $this->apikeyRepository->findByPrefix(prefix: $prefix)) {
|
|
|
|
$storedHash = $apiResult->getApiToken();
|
2022-01-27 15:16:20 +01:00
|
|
|
if (!password_verify(password: $apiKey, hash: $storedHash)) {
|
|
|
|
$this->header = "401 Unauthorized";
|
|
|
|
$this->status = "401 Unauthorized";
|
|
|
|
$this->message = "API key mismatch.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-25 20:50:26 +01:00
|
|
|
$this->header = "401 Unauthorized";
|
2022-01-18 19:14:24 +01:00
|
|
|
$this->status = "401 Unauthorized";
|
2022-01-31 20:49:44 +01:00
|
|
|
$this->message = "Invalid API key.";
|
2022-01-18 19:14:24 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-01-20 11:06:58 +01:00
|
|
|
/**
|
2022-01-22 17:36:15 +01:00
|
|
|
* @return void
|
2022-01-20 11:06:58 +01:00
|
|
|
*/
|
2022-01-22 17:32:36 +01:00
|
|
|
public function handleDomainGetRequest(): void
|
2022-01-20 11:06:58 +01:00
|
|
|
{
|
2022-02-12 19:27:38 +01:00
|
|
|
if ($this->uri[3] == 'name') {
|
|
|
|
if ($result = $this->domainRepository->findByName(name: $this->uri[4])) {
|
2022-01-31 20:49:44 +01:00
|
|
|
$domain = [
|
2022-02-12 19:27:38 +01:00
|
|
|
'id' => $result->getId(),
|
|
|
|
'name' => $result->getName(),
|
|
|
|
'content' => json_decode(json: $result->getContent())
|
2022-01-31 20:49:44 +01:00
|
|
|
];
|
|
|
|
$this->result = $domain;
|
2022-01-22 17:32:36 +01:00
|
|
|
} else {
|
2022-01-25 20:50:26 +01:00
|
|
|
$this->header = "404 Not Found ";
|
2022-01-20 11:06:58 +01:00
|
|
|
$this->status = "404 Not Found ";
|
|
|
|
$this->message = "The specified domain was not found.";
|
|
|
|
}
|
|
|
|
} else {
|
2022-02-12 19:27:38 +01:00
|
|
|
if (empty($this->uri[3])) {
|
|
|
|
$this->handleAllDomainsGetRequest();
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-13 15:47:23 +01:00
|
|
|
$id = intval(value: $this->uri['3']);
|
|
|
|
if ($id > 0) {
|
|
|
|
if ($result = $this->domainRepository->findById(id: $id)) {
|
|
|
|
$domain = [
|
|
|
|
'id' => $result->getId(),
|
|
|
|
'name' => $result->getName(),
|
|
|
|
'content' => json_decode(json: $result->getContent())
|
|
|
|
];
|
|
|
|
$this->result = $domain;
|
|
|
|
} else {
|
|
|
|
$this->header = "404 Not Found ";
|
|
|
|
$this->status = "404 Not Found ";
|
|
|
|
$this->message = "The specified domain was not found.";
|
|
|
|
}
|
|
|
|
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-13 15:47:23 +01:00
|
|
|
$this->header = "400 Bad request";
|
|
|
|
$this->status = "400 Not Found";
|
|
|
|
$this->message = "You need to supply an ID or user the /domain/name/<name> path.";
|
|
|
|
|
2022-01-20 11:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-12 19:27:38 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public
|
|
|
|
function handleDomainPostRequest(): void
|
|
|
|
{
|
|
|
|
$name = $_POST['name'] ?? '';
|
2022-02-13 16:35:38 +01:00
|
|
|
$panel = $_POST['panel'] ?? '';
|
2022-02-12 19:27:38 +01:00
|
|
|
$content = $_POST['content'] ?? '';
|
|
|
|
if (empty($name)) {
|
|
|
|
$this->header = "400 Bad Request";
|
|
|
|
$this->status = "400 Bad Request";
|
|
|
|
$this->message = "A name is required";
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-13 16:35:38 +01:00
|
|
|
if (empty($a) && empty($aaaa) && empty($panel)) {
|
2022-02-12 19:27:38 +01:00
|
|
|
$this->header = "400 Bad Request";
|
2022-01-20 11:06:58 +01:00
|
|
|
$this->status = "400 Bad Request";
|
2022-02-12 19:27:38 +01:00
|
|
|
$this->message = "At least one IP address or panel ID is required.";
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-12 19:27:38 +01:00
|
|
|
if ($this->domainRepository->findByName(name: $name)) {
|
|
|
|
$this->header = "400 Bad request";
|
|
|
|
$this->status = "400 Bad request";
|
|
|
|
$this->message = "Domain: $name already exists.";
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-12 19:27:38 +01:00
|
|
|
$domain = new Domain(name: $name, content: $content);
|
2022-02-13 16:35:38 +01:00
|
|
|
if ($result = $this->domainRepository->insert(domain: $domain)) {
|
2022-02-22 14:06:35 +01:00
|
|
|
$this->header = "201 Created";
|
2022-02-13 16:35:38 +01:00
|
|
|
$this->status = "201 Created";
|
|
|
|
} else {
|
|
|
|
$this->header = "500 Server error";
|
|
|
|
$this->status = "500 Server error";
|
|
|
|
}
|
2022-02-22 14:06:35 +01:00
|
|
|
$this->message = $result;
|
2022-01-20 11:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:27:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public
|
|
|
|
function handleDomainPutRequest(): void
|
|
|
|
{
|
|
|
|
$putData = fopen(filename: 'php://input', mode: 'r');
|
|
|
|
$data = fread(stream: $putData, length: 512);
|
|
|
|
$params = explode(separator: '&', string: $data);
|
|
|
|
|
|
|
|
foreach ($params as $param) {
|
|
|
|
[$key, $value] = explode(separator: '=', string: $param);
|
|
|
|
$put[$key] = $value;
|
|
|
|
}
|
|
|
|
$id = $put['id'] ?? 0;
|
|
|
|
$name = $put['name'] ?? '';
|
|
|
|
$content = $put['content'] ?? "";
|
|
|
|
|
|
|
|
if ($id == 0) {
|
|
|
|
$this->status = "400 Bad Request";
|
|
|
|
$this->message = "An ID is required";
|
|
|
|
} else {
|
|
|
|
if (!$this->domainRepository->findByID(id: $id)) {
|
|
|
|
$this->status = "404 Not Found";
|
|
|
|
$this->message = "Domain with ID : $id doesn't exist.";
|
|
|
|
} else {
|
|
|
|
// TODO not required, as we rely on the ID
|
|
|
|
if (empty($name)) {
|
|
|
|
$this->status = "400 Bad Request";
|
|
|
|
$this->message = "A name is required";
|
|
|
|
} else {
|
|
|
|
if (empty($a) && empty($aaaa)) {
|
|
|
|
$this->status = "400 Bad Request";
|
|
|
|
$this->message = "At least one IP address is required.";
|
|
|
|
} else {
|
|
|
|
$domain = new Domain(name: $name, id: $id, content: $content);
|
|
|
|
$this->domainRepository->update(domain: $domain);
|
|
|
|
$this->header = "201 Updated";
|
|
|
|
$this->status = "201 Updated";
|
|
|
|
$this->message = "201 Updated";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-20 11:06:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-12 19:27:38 +01:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public
|
|
|
|
function handleDomainDeleteRequest(): void
|
|
|
|
{
|
|
|
|
$deleteData = fopen(filename: 'php://input', mode: 'r');
|
|
|
|
$data = fread(stream: $deleteData, length: 512);
|
|
|
|
$params = explode(separator: '&', string: $data);
|
|
|
|
|
|
|
|
foreach ($params as $param) {
|
|
|
|
[$key, $value] = explode(separator: '=', string: $param);
|
|
|
|
$delete[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$id = $delete['id'] ?? 0;
|
2022-02-06 17:58:52 +01:00
|
|
|
|
2022-02-12 19:27:38 +01:00
|
|
|
if ($id == 0) {
|
2022-01-26 19:36:56 +01:00
|
|
|
$this->header = "400 Bad Request";
|
2022-01-20 11:06:58 +01:00
|
|
|
$this->status = "400 Bad Request";
|
2022-02-12 19:27:38 +01:00
|
|
|
$this->message = "You need to supply an ID.";
|
2022-01-20 11:06:58 +01:00
|
|
|
} else {
|
2022-02-12 19:27:38 +01:00
|
|
|
|
|
|
|
if (!$domain = $this->domainRepository->findByID(id: $id)) {
|
|
|
|
$this->header = "400 Bad Request";
|
|
|
|
$this->status = "400 Bad Request";
|
|
|
|
$this->message = "There is no domain with ID $id.";
|
|
|
|
} else {
|
|
|
|
$this->domainRepository->delete(domain: $domain);
|
|
|
|
$this->header = "204 No content.";
|
|
|
|
$this->status = "204 No content.";
|
|
|
|
$this->message = "The domain $id has been deleted.";
|
|
|
|
}
|
2022-01-20 11:06:58 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-12 19:27:38 +01:00
|
|
|
|
2022-01-20 11:06:58 +01:00
|
|
|
}
|