705 lines
34 KiB
PHP
705 lines
34 KiB
PHP
<?php
|
|
|
|
namespace App\OpenApi;
|
|
|
|
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
|
|
use ApiPlatform\OpenApi\OpenApi;
|
|
use ApiPlatform\OpenApi\Model;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
final readonly class OpenApiFactory implements OpenApiFactoryInterface
|
|
{
|
|
|
|
public function __construct(private OpenApiFactoryInterface $decorated)
|
|
{
|
|
}
|
|
|
|
public function __invoke(array $context = []): OpenApi
|
|
{
|
|
$openApi = $this->decorated->__invoke($context);
|
|
|
|
$this->addRefreshToken($openApi);
|
|
$this->addSearchEndpoint($openApi);
|
|
$this->addOgAgentEndpoints($openApi);
|
|
|
|
return $openApi;
|
|
}
|
|
|
|
private function addRefreshToken(OpenApi $openApi): void
|
|
{
|
|
$openApi
|
|
->getPaths()
|
|
->addPath( '/auth/refresh', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postRefreshToken'))
|
|
->withTags(['Login check'])
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Refresh token',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'token' => [
|
|
'type' => 'string',
|
|
'readOnly' => true,
|
|
'nullable' => false,
|
|
],
|
|
'refreshToken' => [
|
|
'type' => 'string',
|
|
'readOnly' => true,
|
|
'nullable' => false,
|
|
]
|
|
],
|
|
'required' => ['token', 'refreshToken'],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
->withSummary('Create refresh token')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('The refresh token data')
|
|
->withContent( new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'refreshToken' => [
|
|
'type' => 'string',
|
|
'nullable' => false,
|
|
],
|
|
],
|
|
'required' => ['refreshToken'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
));
|
|
}
|
|
private function addSearchEndpoint(OpenApi $openApi): void
|
|
{
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/search', (new Model\PathItem())->withGet(
|
|
(new Model\Operation('getSearch'))
|
|
->withTags(['Search'])
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Search results',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'results' => [
|
|
'type' => 'array',
|
|
'items' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'id' => [
|
|
'type' => 'integer',
|
|
'example' => 1,
|
|
],
|
|
'name' => [
|
|
'type' => 'string',
|
|
'example' => 'Item name',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
->withSummary('Search for items')
|
|
->withParameters([
|
|
new Model\Parameter(
|
|
'query',
|
|
'query',
|
|
'Search query parameter',
|
|
true,
|
|
false,
|
|
),
|
|
])
|
|
));
|
|
}
|
|
|
|
private function addOgAgentEndpoints(OpenApi $openApi): void
|
|
{
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/ogagent/started', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postAgentStarted'))
|
|
->withTags(['OS agent'])
|
|
->withSummary('Receive notification that an agent has started')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('Notification of agent start')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'mac' => [
|
|
'type' => 'string',
|
|
'example' => '00:01:02:03:04:05',
|
|
],
|
|
'ip' => [
|
|
'type' => 'string',
|
|
'example' => '192.168.2.11',
|
|
],
|
|
'secret' => [
|
|
'type' => 'string',
|
|
'example' => 'nug05l0ipc0lzl578uu5ohm1a074v4t2',
|
|
],
|
|
'ostype' => [
|
|
'type' => 'string',
|
|
'enum' => ['Linux', 'MacOS', 'Windows'],
|
|
],
|
|
'osversion' => [
|
|
'type' => 'string',
|
|
'example' => 'Debian GNU/Linux 12 (bookworm)',
|
|
],
|
|
'agent_version' => [
|
|
'type' => 'string',
|
|
'example' => '1.3.0',
|
|
],
|
|
],
|
|
'required' => ['mac', 'ip', 'secret', 'ostype', 'osversion', 'agent_version'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/EmptyObj'],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/ogagent/stopped', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postAgentStopped'))
|
|
->withTags(['OS agent'])
|
|
->withSummary('Receive notification that an agent has stopped')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('Notification of agent stop')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'mac' => [
|
|
'type' => 'string',
|
|
'example' => '00:01:02:03:04:05',
|
|
],
|
|
'ip' => [
|
|
'type' => 'string',
|
|
'example' => '192.168.2.11',
|
|
],
|
|
'ostype' => [
|
|
'type' => 'string',
|
|
'enum' => ['Linux', 'MacOS', 'Windows'],
|
|
],
|
|
'osversion' => [
|
|
'type' => 'string',
|
|
'example' => 'Debian GNU/Linux 12 (bookworm)',
|
|
],
|
|
],
|
|
'required' => ['mac', 'ip', 'ostype', 'osversion'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/EmptyObj'],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/ogagent/loggedin', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postAgentLoggedIn'))
|
|
->withTags(['OS agent'])
|
|
->withSummary('Receive notification that a user has logged in')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('Notification of user login')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'ip' => [
|
|
'type' => 'string',
|
|
'example' => '192.168.2.11',
|
|
],
|
|
'user' => [
|
|
'type' => 'string',
|
|
'example' => 'student',
|
|
],
|
|
'language' => [
|
|
'type' => 'string',
|
|
'example' => 'en_GB',
|
|
],
|
|
'session' => [
|
|
'type' => 'string',
|
|
'example' => 'x11',
|
|
],
|
|
'ostype' => [
|
|
'type' => 'string',
|
|
'enum' => ['Linux', 'MacOS', 'Windows'],
|
|
],
|
|
'osversion' => [
|
|
'type' => 'string',
|
|
'example' => 'Debian GNU/Linux 12 (bookworm)',
|
|
],
|
|
],
|
|
'required' => ['ip', 'user', 'language', 'session', 'ostype', 'osversion'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/EmptyObj'],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/ogagent/loggedout', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postAgentLoggedOut'))
|
|
->withTags(['OS agent'])
|
|
->withSummary('Receive notification that a user has logged out')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('Notification of user logout')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'ip' => [
|
|
'type' => 'string',
|
|
'example' => '192.168.2.11',
|
|
],
|
|
'user' => [
|
|
'type' => 'string',
|
|
'example' => 'student',
|
|
],
|
|
],
|
|
'required' => ['ip', 'user'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/EmptyObj'],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/__ogAdmClient/InclusionCliente', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postInclusionCliente'))
|
|
->withTags(['OgLive agent'])
|
|
->withSummary('Add client to the list of known ones')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('Inclusion cliente request')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'iph' => [
|
|
'type' => 'string',
|
|
],
|
|
'ido' => [
|
|
'type' => 'integer',
|
|
],
|
|
'npc' => [
|
|
'type' => 'string',
|
|
],
|
|
'idc' => [
|
|
'type' => 'integer',
|
|
],
|
|
'ida' => [
|
|
'type' => 'integer',
|
|
],
|
|
'cfg' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
'required' => ['iph', 'cfg'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/InclusionClienteRes'],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/__ogAdmClient/AutoexecCliente', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postAutoexecCliente'))
|
|
->withTags(['OgLive agent'])
|
|
->withSummary('Create and return autoexec file for client')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('AutoexecCliente request')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'iph' => [
|
|
'type' => 'string',
|
|
],
|
|
'ido' => [
|
|
'type' => 'integer',
|
|
],
|
|
'npc' => [
|
|
'type' => 'string',
|
|
],
|
|
'idc' => [
|
|
'type' => 'integer',
|
|
],
|
|
'ida' => [
|
|
'type' => 'integer',
|
|
],
|
|
'exe' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
'required' => ['iph', 'exe'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success, autoexec file created',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'res' => [
|
|
'type' => 'integer',
|
|
'example' => 1,
|
|
],
|
|
'nfl' => [
|
|
'type' => 'string',
|
|
'example' => '/tmp/Sautoexec-00:01:02:03:04:05',
|
|
],
|
|
],
|
|
'required' => ['res', 'nfl'],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_BAD_REQUEST => [
|
|
'description' => 'Missing parameter',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_INTERNAL_SERVER_ERROR => [
|
|
'description' => 'Error creating file',
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/__ogAdmClient/enviaArchivo', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postEnviaArchivo'))
|
|
->withTags(['OgLive agent'])
|
|
->withSummary('Send the contents of a file')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('EnviaArchivo request')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'iph' => [
|
|
'type' => 'string',
|
|
],
|
|
'ido' => [
|
|
'type' => 'integer',
|
|
],
|
|
'npc' => [
|
|
'type' => 'string',
|
|
],
|
|
'idc' => [
|
|
'type' => 'integer',
|
|
],
|
|
'ida' => [
|
|
'type' => 'integer',
|
|
],
|
|
'nfl' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
'required' => ['nfl'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success, file content returned',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'contents' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
'required' => ['contents'],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_BAD_REQUEST => [
|
|
'description' => 'Missing parameter',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_NOT_FOUND => [
|
|
'description' => 'File not found',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/__ogAdmClient/ComandosPendientes', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postComandosPendientes'))
|
|
->withTags(['OgLive agent'])
|
|
->withSummary('Retrieve pending commands for a client')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('ComandosPendientes request')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'iph' => [
|
|
'type' => 'string',
|
|
],
|
|
'ido' => [
|
|
'type' => 'integer',
|
|
],
|
|
'npc' => [
|
|
'type' => 'string',
|
|
],
|
|
'idc' => [
|
|
'type' => 'integer',
|
|
],
|
|
'ida' => [
|
|
'type' => 'integer',
|
|
],
|
|
],
|
|
'required' => ['iph', 'ido'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success, pending commands returned',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'nfn' => [
|
|
'type' => 'string',
|
|
'example' => 'NoComandosPtes',
|
|
],
|
|
'comandos' => [
|
|
'type' => 'array',
|
|
'items' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_BAD_REQUEST => [
|
|
'description' => 'Missing parameter',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_NOT_FOUND => [
|
|
'description' => 'Client not found',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
$openApi
|
|
->getPaths()
|
|
->addPath('/opengnsys/rest/__ogAdmClient/DisponibilidadComandos', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postDisponibilidadComandos'))
|
|
->withTags(['OgLive agent'])
|
|
->withSummary('Check command availability for a client')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('DisponibilidadComandos request')
|
|
->withContent(new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'iph' => [
|
|
'type' => 'string',
|
|
],
|
|
'ido' => [
|
|
'type' => 'integer',
|
|
],
|
|
'npc' => [
|
|
'type' => 'string',
|
|
],
|
|
'idc' => [
|
|
'type' => 'integer',
|
|
],
|
|
'ida' => [
|
|
'type' => 'integer',
|
|
],
|
|
'tpc' => [
|
|
'type' => 'integer',
|
|
],
|
|
],
|
|
'required' => ['iph', 'tpc'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Success, command availability checked',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => ['$ref' => '#/components/schemas/EmptyObj'],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_BAD_REQUEST => [
|
|
'description' => 'Missing parameter',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
Response::HTTP_NOT_FOUND => [
|
|
'description' => 'Client not found',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'message' => [
|
|
'type' => 'string',
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
));
|
|
}
|
|
} |