From 280e5e5a972ae02d35d6490bc127035009ee8eff Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 31 Jan 2024 11:56:11 +0100 Subject: [PATCH] new api 2.0 --- .../godmode/agentes/agent_manager.php | 16 +++++++++------- .../Groups/Controllers/CreateGroupController.php | 4 ++++ .../Groups/Controllers/DeleteGroupController.php | 6 +++++- .../Groups/Controllers/UpdateGroupController.php | 6 +++++- .../lib/Modules/Groups/Entities/GroupFilter.php | 4 ++-- .../Groups/Repositories/GroupRepositoryMySQL.php | 2 ++ .../Controllers/CreateProfileController.php | 6 ++++++ .../Controllers/DeleteProfileController.php | 8 +++++++- .../Controllers/UpdateProfileController.php | 8 +++++++- .../Tags/Controllers/CreateTagController.php | 4 ++++ .../Tags/Controllers/DeleteTagController.php | 10 +++++++--- .../Tags/Controllers/UpdateTagController.php | 10 +++++++--- .../Users/Controllers/CreateUserController.php | 4 +++- .../Users/Controllers/DeleteUserController.php | 4 +++- .../Users/Controllers/GetUserController.php | 4 ++++ .../Users/Controllers/UpdateUserController.php | 4 +++- .../Controllers/CreateUserProfileController.php | 8 +++++++- .../Controllers/DeleteUserProfileController.php | 8 +++++++- 18 files changed, 92 insertions(+), 24 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 80a480dd12..283610e06a 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -507,14 +507,16 @@ if (enterprise_installed()) { // Read configuration file. $files = config_agents_get_agent_config_filenames($id_agente); $file_name = $files['conf']; - $agent_config = file_get_contents($file_name); - $encoding = 'UTF-8'; - $agent_config_utf8 = mb_convert_encoding($agent_config, 'UTF-8', $encoding); - if ($agent_config_utf8 !== false) { - $agent_config = $agent_config_utf8; - } + if (empty($file_name) === false) { + $agent_config = file_get_contents($file_name); + $encoding = 'UTF-8'; + $agent_config_utf8 = mb_convert_encoding($agent_config, 'UTF-8', $encoding); + if ($agent_config_utf8 !== false) { + $agent_config = $agent_config_utf8; + } - $broker = str_contains($agent_config, '#broker active'); + $broker = str_contains($agent_config, '#broker active'); + } } if ($broker === false) { diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php index 3f4f5a2477..bfefba32f7 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/CreateGroupController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Groups\Controllers; use PandoraFMS\Modules\Groups\Actions\CreateGroupAction; use PandoraFMS\Modules\Groups\Entities\Group; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -15,6 +16,7 @@ final class CreateGroupController extends Controller public function __construct( private CreateGroupAction $createGroupAction, private ValidateAclSystem $acl, + private Management $management ) { } @@ -40,6 +42,8 @@ final class CreateGroupController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user for groups'); + $this->management->isManagementAllowed('Group', true); + $result = $this->createGroupAction->__invoke($group); return $this->getResponse($response, $result); diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php index 84c880db58..91b29597c4 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/DeleteGroupController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Groups\Controllers; use PandoraFMS\Modules\Groups\Actions\DeleteGroupAction; use PandoraFMS\Modules\Groups\Actions\GetGroupAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -15,7 +16,8 @@ final class DeleteGroupController extends Controller public function __construct( private DeleteGroupAction $deleteGroupAction, private ValidateAclSystem $acl, - private GetGroupAction $getGroupAction + private GetGroupAction $getGroupAction, + private Management $management ) { } @@ -41,6 +43,8 @@ final class DeleteGroupController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user for groups'); + $this->management->isManagementAllowed('Group', true); + $result = $this->deleteGroupAction->__invoke($group); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php b/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php index 14be288e86..3256407f7f 100644 --- a/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php +++ b/pandora_console/include/lib/Modules/Groups/Controllers/UpdateGroupController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Groups\Controllers; use PandoraFMS\Modules\Groups\Actions\GetGroupAction; use PandoraFMS\Modules\Groups\Actions\UpdateGroupAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -31,7 +32,8 @@ final class UpdateGroupController extends Controller public function __construct( private UpdateGroupAction $updateGroupAction, private ValidateAclSystem $acl, - private GetGroupAction $getGroupAction + private GetGroupAction $getGroupAction, + private Management $management ) { } @@ -46,6 +48,8 @@ final class UpdateGroupController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user for groups'); + $this->management->isManagementAllowed('Group', true); + $result = $this->updateGroupAction->__invoke($group, $oldGroup); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php b/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php index 2a3a6942b0..7f9af6084f 100644 --- a/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php +++ b/pandora_console/include/lib/Modules/Groups/Entities/GroupFilter.php @@ -124,8 +124,8 @@ final class GroupFilter extends FilterAbstract public function getFieldsFreeSearch(): ?array { return [ - GroupDataMapper::NAME, - GroupDataMapper::DESCRIPTION, + GroupDataMapper::TABLE_NAME.'.'.GroupDataMapper::NAME, + GroupDataMapper::TABLE_NAME.'.'.GroupDataMapper::DESCRIPTION, ]; } } diff --git a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php index 6915ac6de6..a678cacf26 100644 --- a/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php +++ b/pandora_console/include/lib/Modules/Groups/Repositories/GroupRepositoryMySQL.php @@ -159,6 +159,8 @@ class GroupRepositoryMySQL extends RepositoryMySQL implements GroupRepository $pagination ); + hd($sql, true); + return $sql; } } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php index 967a3b29ee..65298dc26f 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/CreateProfileController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Profiles\Controllers; use PandoraFMS\Modules\Profiles\Actions\CreateProfileAction; use PandoraFMS\Modules\Profiles\Entities\Profile; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -15,6 +16,7 @@ final class CreateProfileController extends Controller public function __construct( private CreateProfileAction $createProfileAction, private ValidateAclSystem $acl, + private Management $management ) { } @@ -41,6 +43,10 @@ final class CreateProfileController extends Controller $this->acl->validateUserAdmin(); $this->acl->validate(0, 'UM', ' tried to manage profile'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('Profile', true); + } + $result = $this->createProfileAction->__invoke($profile); return $this->getResponse($response, $result); diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php index 7efe367cbf..536b025989 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/DeleteProfileController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Profiles\Controllers; use PandoraFMS\Modules\Profiles\Actions\DeleteProfileAction; use PandoraFMS\Modules\Profiles\Actions\GetProfileAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -15,7 +16,8 @@ final class DeleteProfileController extends Controller public function __construct( private DeleteProfileAction $deleteProfileAction, private ValidateAclSystem $acl, - private GetProfileAction $getProfileAction + private GetProfileAction $getProfileAction, + private Management $management ) { } @@ -42,6 +44,10 @@ final class DeleteProfileController extends Controller $this->acl->validateUserAdmin(); $this->acl->validate(0, 'UM', ' tried to manage profile'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('Profile', true); + } + $result = $this->deleteProfileAction->__invoke($profile); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php index 441e39b622..6d064cec4a 100644 --- a/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php +++ b/pandora_console/include/lib/Modules/Profiles/Controllers/UpdateProfileController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Profiles\Controllers; use PandoraFMS\Modules\Profiles\Actions\GetProfileAction; use PandoraFMS\Modules\Profiles\Actions\UpdateProfileAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -31,7 +32,8 @@ final class UpdateProfileController extends Controller public function __construct( private UpdateProfileAction $updateProfileAction, private ValidateAclSystem $acl, - private GetProfileAction $getProfileAction + private GetProfileAction $getProfileAction, + private Management $management ) { } @@ -47,6 +49,10 @@ final class UpdateProfileController extends Controller $this->acl->validateUserAdmin(); $this->acl->validate(0, 'UM', ' tried to manage profile'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('Profile', true); + } + $result = $this->updateProfileAction->__invoke($profile, $oldProfile); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php index 1bf6461c54..dda6499fe6 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/CreateTagController.php @@ -5,6 +5,7 @@ namespace PandoraFMS\Modules\Tags\Controllers; use PandoraFMS\Modules\Tags\Actions\CreateTagAction; use PandoraFMS\Modules\Tags\Entities\Tag; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; @@ -15,6 +16,7 @@ final class CreateTagController extends Controller public function __construct( private CreateTagAction $createTagAction, private ValidateAclSystem $acl, + private Management $management ) { } @@ -40,6 +42,8 @@ final class CreateTagController extends Controller $this->acl->validate(0, 'PM', ' tried to manage tag'); + $this->management->isManagementAllowed('Tag', true); + $result = $this->createTagAction->__invoke($tag); return $this->getResponse($response, $result); diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php index 715e34bbff..e77b229e6e 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/DeleteTagController.php @@ -2,10 +2,11 @@ namespace PandoraFMS\Modules\Tags\Controllers; +use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; +use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Tags\Actions\DeleteTagAction; use PandoraFMS\Modules\Tags\Actions\GetTagAction; -use PandoraFMS\Modules\Shared\Controllers\Controller; -use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; @@ -15,7 +16,8 @@ final class DeleteTagController extends Controller public function __construct( private DeleteTagAction $deleteTagAction, private ValidateAclSystem $acl, - private GetTagAction $getTagAction + private GetTagAction $getTagAction, + private Management $management ) { } @@ -41,6 +43,8 @@ final class DeleteTagController extends Controller $this->acl->validate(0, 'PM', ' tried to manage tag'); + $this->management->isManagementAllowed('Tag', true); + $result = $this->deleteTagAction->__invoke($tag); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php b/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php index dc80e22f0c..1ae5768848 100644 --- a/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php +++ b/pandora_console/include/lib/Modules/Tags/Controllers/UpdateTagController.php @@ -2,10 +2,11 @@ namespace PandoraFMS\Modules\Tags\Controllers; +use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; +use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Tags\Actions\GetTagAction; use PandoraFMS\Modules\Tags\Actions\UpdateTagAction; -use PandoraFMS\Modules\Shared\Controllers\Controller; -use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; @@ -31,7 +32,8 @@ final class UpdateTagController extends Controller public function __construct( private UpdateTagAction $updateTagAction, private ValidateAclSystem $acl, - private GetTagAction $getTagAction + private GetTagAction $getTagAction, + private Management $management ) { } @@ -46,6 +48,8 @@ final class UpdateTagController extends Controller $this->acl->validate(0, 'PM', ' tried to manage tag'); + $this->management->isManagementAllowed('Tag', true); + $result = $this->updateTagAction->__invoke($tag, $oldTag); return $this->getResponse($response, $result); } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php index 45c73dad3d..f639b4d455 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/CreateUserController.php @@ -42,7 +42,9 @@ final class CreateUserController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user'); - $this->management->isManagementAllowed('User'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('User', true); + } $result = $this->createUserAction->__invoke($user); diff --git a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php index ffa3af6553..cccf79e070 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/DeleteUserController.php @@ -43,7 +43,9 @@ final class DeleteUserController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user'); - $this->management->isManagementAllowed('User'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('User'); + } $result = $this->deleteUserAction->__invoke($user); return $this->getResponse($response, $result); diff --git a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php index a4d255f167..04b830803c 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/GetUserController.php @@ -35,7 +35,11 @@ final class GetUserController extends Controller public function __invoke(Request $request, Response $response): Response { $idUser = $this->getParam($request, 'idUser'); + + $this->acl->validate(0, 'UM', ' tried to manage user'); + $result = $this->getUserAction->__invoke($idUser); + return $this->getResponse($response, $result); } } diff --git a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php index 6730074cb5..d365e882b3 100644 --- a/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php +++ b/pandora_console/include/lib/Modules/Users/Controllers/UpdateUserController.php @@ -48,7 +48,9 @@ final class UpdateUserController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user'); - $this->management->isManagementAllowed('User'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('User'); + } $result = $this->updateUserAction->__invoke($user, $oldUser); return $this->getResponse($response, $result); diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php index ff9afdc4d5..17dcd6b886 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/CreateUserProfileController.php @@ -4,6 +4,7 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Controllers; use PandoraFMS\Modules\Profiles\Actions\GetProfileAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Users\UserProfiles\Actions\CreateUserProfileAction; @@ -18,7 +19,8 @@ final class CreateUserProfileController extends Controller private CreateUserProfileAction $createUserProfileAction, private ValidateAclSystem $acl, private GetUserAction $getUserAction, - private GetProfileAction $getProfileAction + private GetProfileAction $getProfileAction, + private Management $management ) { } @@ -46,6 +48,10 @@ final class CreateUserProfileController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user profile'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('User profile', true); + } + $idProfile = $this->getParam($request, 'idProfile'); $this->getProfileAction->__invoke($idProfile); diff --git a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php index 56b623acdb..3637a72ced 100644 --- a/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php +++ b/pandora_console/include/lib/Modules/Users/UserProfiles/Controllers/DeleteUserProfileController.php @@ -4,6 +4,7 @@ namespace PandoraFMS\Modules\Users\UserProfiles\Controllers; use PandoraFMS\Modules\Profiles\Actions\GetProfileAction; use PandoraFMS\Modules\Shared\Controllers\Controller; +use PandoraFMS\Modules\Shared\Services\Management; use PandoraFMS\Modules\Shared\Services\ValidateAclSystem; use PandoraFMS\Modules\Users\Actions\GetUserAction; use PandoraFMS\Modules\Users\UserProfiles\Actions\DeleteUserProfileAction; @@ -19,7 +20,8 @@ final class DeleteUserProfileController extends Controller private ValidateAclSystem $acl, private GetUserAction $getUserAction, private GetProfileAction $getProfileAction, - private GetUserProfileAction $getUserProfileAction + private GetUserProfileAction $getUserProfileAction, + private Management $management ) { } @@ -46,6 +48,10 @@ final class DeleteUserProfileController extends Controller $this->acl->validate(0, 'UM', ' tried to manage user profile'); + if (\is_metaconsole() === false) { + $this->management->isManagementAllowed('User profile', true); + } + $idProfile = $this->getParam($request, 'idProfile'); $profile = $this->getProfileAction->__invoke($idProfile);