changed from content to panel
Signed-off-by: tracer <tracer@24unix.net>
This commit is contained in:
parent
1ad945fbf2
commit
8c7755e096
|
@ -22,17 +22,17 @@ use OpenApi\Attributes as OAT;
|
|||
*/
|
||||
#[OAT\Info(version: '0.0.1', title: 'bindAPI')]
|
||||
#[OAT\Server(
|
||||
url: "{schema}://{hostname}/api",
|
||||
url : "{schema}://{hostname}/api",
|
||||
description: "The bindAPI URL.",
|
||||
variables: [
|
||||
variables : [
|
||||
new OAT\ServerVariable(
|
||||
serverVariable: "schema",
|
||||
default: "https",
|
||||
enum: ["https", "http"]
|
||||
default : "https",
|
||||
enum : ["https", "http"]
|
||||
),
|
||||
new OAT\ServerVariable(
|
||||
serverVariable: "hostname",
|
||||
default: "ns2.24unix.net",
|
||||
default : "ns2.24unix.net",
|
||||
)
|
||||
]
|
||||
)]
|
||||
|
@ -41,10 +41,10 @@ use OpenApi\Attributes as OAT;
|
|||
)]
|
||||
#[OAT\SecurityScheme(
|
||||
securityScheme: "Authorization",
|
||||
type: "apiKey",
|
||||
description: "description",
|
||||
name: "X-API-Key",
|
||||
in: "header"
|
||||
type : "apiKey",
|
||||
description : "description",
|
||||
name : "X-API-Key",
|
||||
in : "header"
|
||||
)]
|
||||
class RequestController
|
||||
{
|
||||
|
@ -101,29 +101,29 @@ class RequestController
|
|||
* @return void
|
||||
*/
|
||||
#[OAT\Get(
|
||||
path: '/domains',
|
||||
path : '/domains',
|
||||
operationId: 'getAllDomains',
|
||||
description: 'Returns a list of all domains on this server.',
|
||||
summary: 'Listing all domains.',
|
||||
summary : 'Listing all domains.',
|
||||
// security: [
|
||||
// 'Authorization' => [
|
||||
//
|
||||
// "read:api"
|
||||
// ]
|
||||
// ],
|
||||
servers: [],
|
||||
tags: ['Domains'],
|
||||
responses: [
|
||||
servers : [],
|
||||
tags : ['Domains'],
|
||||
responses : [
|
||||
new OAT\Response(
|
||||
response: 200,
|
||||
response : 200,
|
||||
description: 'OK'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 401,
|
||||
response : 401,
|
||||
description: 'API key is missing or invalid.'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 404,
|
||||
response : 404,
|
||||
description: 'Domain not found.'
|
||||
)]
|
||||
)]
|
||||
|
@ -186,27 +186,27 @@ class RequestController
|
|||
*/
|
||||
|
||||
#[OAT\Get(
|
||||
path: '/domains/{name}',
|
||||
path : '/domains/{name}',
|
||||
operationId: 'getSingleDomain',
|
||||
description: 'Returns information of a single domain specified by its domain name.',
|
||||
summary: 'Returns a single domain.',
|
||||
security: [
|
||||
summary : 'Returns a single domain.',
|
||||
security : [
|
||||
],
|
||||
tags: ['Domains'],
|
||||
parameters: [
|
||||
tags : ['Domains'],
|
||||
parameters : [
|
||||
new OAT\Parameter(name: 'name', in: 'path', required: true, schema: new OAT\Schema(type: 'string')),
|
||||
],
|
||||
responses: [
|
||||
responses : [
|
||||
new OAT\Response(
|
||||
response: 200,
|
||||
response : 200,
|
||||
description: 'OK'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 401,
|
||||
response : 401,
|
||||
description: 'API key is missing or invalid.'
|
||||
),
|
||||
new OAT\Response(
|
||||
response: 404,
|
||||
response : 404,
|
||||
description: 'Domain not found.'
|
||||
)]
|
||||
|
||||
|
@ -316,7 +316,7 @@ class RequestController
|
|||
$domain = [
|
||||
'id' => $result->getId(),
|
||||
'name' => $result->getName(),
|
||||
'content' => json_decode(json: $result->getContent())
|
||||
'panel' => $result->getPanel()
|
||||
];
|
||||
$this->result = $domain;
|
||||
} else {
|
||||
|
@ -334,7 +334,7 @@ class RequestController
|
|||
$domain = [
|
||||
'id' => $result->getId(),
|
||||
'name' => $result->getName(),
|
||||
'content' => json_decode(json: $result->getContent())
|
||||
'panel' => $result->getPanel()
|
||||
];
|
||||
$this->result = $domain;
|
||||
} else {
|
||||
|
@ -342,7 +342,6 @@ class RequestController
|
|||
$this->status = "404 Not Found ";
|
||||
$this->message = "The specified domain was not found.";
|
||||
}
|
||||
|
||||
} else {
|
||||
$this->header = "400 Bad request";
|
||||
$this->status = "400 Not Found";
|
||||
|
@ -362,23 +361,22 @@ class RequestController
|
|||
{
|
||||
$name = $_POST['name'] ?? '';
|
||||
$panel = $_POST['panel'] ?? '';
|
||||
$content = $_POST['content'] ?? '';
|
||||
if (empty($name)) {
|
||||
$this->header = "400 Bad Request";
|
||||
$this->status = "400 Bad Request";
|
||||
$this->message = "A name is required";
|
||||
} else {
|
||||
if (empty($a) && empty($aaaa) && empty($panel)) {
|
||||
if (empty($panel)) {
|
||||
$this->header = "400 Bad Request";
|
||||
$this->status = "400 Bad Request";
|
||||
$this->message = "At least one IP address or panel ID is required.";
|
||||
$this->message = "A panel ID is required.";
|
||||
} else {
|
||||
if ($this->domainRepository->findByName(name: $name)) {
|
||||
$this->header = "400 Bad request";
|
||||
$this->status = "400 Bad request";
|
||||
$this->message = "Domain: $name already exists.";
|
||||
} else {
|
||||
$domain = new Domain(name: $name, content: $content);
|
||||
$domain = new Domain(name: $name, panel: $panel);
|
||||
if ($result = $this->domainRepository->insert(domain: $domain)) {
|
||||
$this->header = "201 Created";
|
||||
$this->status = "201 Created";
|
||||
|
@ -396,8 +394,7 @@ class RequestController
|
|||
/**
|
||||
* @return void
|
||||
*/
|
||||
public
|
||||
function handleDomainPutRequest(): void
|
||||
public function handleDomainPutRequest(): void
|
||||
{
|
||||
$putData = fopen(filename: 'php://input', mode: 'r');
|
||||
$data = fread(stream: $putData, length: 512);
|
||||
|
@ -409,9 +406,10 @@ class RequestController
|
|||
}
|
||||
$id = $put['id'] ?? 0;
|
||||
$name = $put['name'] ?? '';
|
||||
$content = $put['content'] ?? "";
|
||||
$panel = $put['panel'] ?? "";
|
||||
|
||||
if ($id == 0) {
|
||||
$this->header = "400 Bad Request";
|
||||
$this->status = "400 Bad Request";
|
||||
$this->message = "An ID is required";
|
||||
} else {
|
||||
|
@ -420,15 +418,7 @@ class RequestController
|
|||
$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);
|
||||
$domain = new Domain(name: $name, panel: $panel, id: $id);
|
||||
$this->domainRepository->update(domain: $domain);
|
||||
$this->header = "201 Updated";
|
||||
$this->status = "201 Updated";
|
||||
|
@ -436,8 +426,6 @@ class RequestController
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -476,4 +464,4 @@ class RequestController
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue