new api 2.0

This commit is contained in:
daniel 2024-01-24 09:23:01 +01:00
parent 2a46720b80
commit b35af80afb
4 changed files with 47 additions and 21 deletions

View File

@ -2,9 +2,3 @@
require_once __DIR__.'/../../../vendor/autoload.php'; require_once __DIR__.'/../../../vendor/autoload.php';
require_once __DIR__.'/../../../include/config.php'; require_once __DIR__.'/../../../include/config.php';
global $config;
if (file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php') === true) {
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php';
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/include/functions_login.php';
}

View File

@ -0,0 +1,15 @@
<?php
global $config;
ob_start();
if (file_exists($config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php') === true) {
$config['return_api_mode'] = true;
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/load_enterprise.php';
include_once $config['homedir'].'/'.ENTERPRISE_DIR.'/include/functions_login.php';
}
$error = ob_get_clean();
if (empty($error) === false) {
throw new Exception($error);
}

View File

@ -1,5 +1,6 @@
<?php <?php
use PandoraFMS\Modules\Shared\Enums\HttpCodesEnum;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler; use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
@ -55,7 +56,20 @@ return function (App $app, ContainerInterface $container) {
json_encode(['error' => 'You need to be authenticated to perform this action']) json_encode(['error' => 'You need to be authenticated to perform this action'])
); );
$errorCode = 401; $errorCode = HttpCodesEnum::UNAUTHORIZED;
$newResponse = $response->withStatus($errorCode);
return $newResponse;
}
try {
include_once __DIR__.'/includeEnterpriseDependencies.php';
} catch (\Throwable $th) {
$response = $app->getResponseFactory()->createResponse();
$response->getBody()->write(
json_encode(['error' => 'Invalid License'])
);
$errorCode = HttpCodesEnum::UNAUTHORIZED;
$newResponse = $response->withStatus($errorCode); $newResponse = $response->withStatus($errorCode);
return $newResponse; return $newResponse;
} }

View File

@ -51,19 +51,19 @@ final class GroupFilter extends FilterAbstract
public function fieldsTranslate(): array public function fieldsTranslate(): array
{ {
return [ return [
'idGroup' => GroupDataMapper::ID_GROUP, 'idGroup' => GroupDataMapper::ID_GROUP,
'name' => GroupDataMapper::NAME, 'name' => GroupDataMapper::NAME,
'icon' => GroupDataMapper::ICON, 'icon' => GroupDataMapper::ICON,
'parent' => GroupDataMapper::PARENT, 'parent' => GroupDataMapper::PARENT,
'isPropagate' => GroupDataMapper::IS_PROPAGATE, 'isPropagate' => GroupDataMapper::IS_PROPAGATE,
'isAlertEnabled' => GroupDataMapper::IS_DISABLED, 'isAlertEnabled' => GroupDataMapper::IS_DISABLED,
'customId' => GroupDataMapper::CUSTOM_ID, 'customId' => GroupDataMapper::CUSTOM_ID,
'idSkin' => GroupDataMapper::ID_SKIN, 'idSkin' => GroupDataMapper::ID_SKIN,
'description' => GroupDataMapper::DESCRIPTION, 'description' => GroupDataMapper::DESCRIPTION,
'contact' => GroupDataMapper::CONTACT, 'contact' => GroupDataMapper::CONTACT,
'other' => GroupDataMapper::OTHER, 'other' => GroupDataMapper::OTHER,
'password' => GroupDataMapper::PASSWORD, 'password' => GroupDataMapper::PASSWORD,
'maxAgents' => GroupDataMapper::MAX_AGENTS, 'maxAgents' => GroupDataMapper::MAX_AGENTS,
]; ];
} }
@ -123,6 +123,9 @@ final class GroupFilter extends FilterAbstract
*/ */
public function getFieldsFreeSearch(): ?array public function getFieldsFreeSearch(): ?array
{ {
return [GroupDataMapper::NAME, GroupDataMapper::DESCRIPTION]; return [
GroupDataMapper::NAME,
GroupDataMapper::DESCRIPTION,
];
} }
} }