From 782c345f4394e29c37db2ad5d8aaa02f11977195 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 21 Aug 2024 09:37:17 +0200 Subject: [PATCH 01/19] refs #624. Added ogAgent controller API --- config/packages/security.yaml | 1 + src/Controller/OgAgent/OgAgentController.php | 224 +++++++ src/OpenApi/OpenApiFactory.php | 578 ++++++++++++++++++- 3 files changed, 802 insertions(+), 1 deletion(-) create mode 100644 src/Controller/OgAgent/OgAgentController.php diff --git a/config/packages/security.yaml b/config/packages/security.yaml index 5e2315b..e0670c8 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -29,6 +29,7 @@ security: - { path: ^/$, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI - { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs - { path: ^/auth/login, roles: PUBLIC_ACCESS } + - { path: ^/opengnsys/rest/, roles: PUBLIC_ACCESS } - { path: ^/auth/refresh, roles: PUBLIC_ACCESS } - { path: ^/, roles: IS_AUTHENTICATED_FULLY } diff --git a/src/Controller/OgAgent/OgAgentController.php b/src/Controller/OgAgent/OgAgentController.php new file mode 100644 index 0000000..b402993 --- /dev/null +++ b/src/Controller/OgAgent/OgAgentController.php @@ -0,0 +1,224 @@ +toArray(); + $requiredFields = ['mac', 'ip', 'secret', 'ostype', 'osversion', 'agent_version']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Procesar los datos recibidos si es necesario + + return new JsonResponse([], Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/ogagent/stopped', methods: ['POST'])] + public function agentStopped(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['mac', 'ip', 'ostype', 'osversion']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Procesar los datos recibidos si es necesario + + return new JsonResponse([], Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/ogagent/loggedin', methods: ['POST'])] + public function agentLoggedIn(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['ip', 'user', 'language', 'session', 'ostype', 'osversion']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Procesar los datos recibidos si es necesario + + return new JsonResponse([], Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/ogagent/loggedout', methods: ['POST'])] + public function agentLoggedOut(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['ip', 'user']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Procesar los datos recibidos si es necesario + + return new JsonResponse([], Response::HTTP_OK); + } + + + #[Route('/opengnsys/rest/__ogAdmClient/InclusionCliente', methods: ['POST'])] + public function inclusionCliente(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'cfg']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Suponemos que el proceso para incluir al cliente es exitoso + + $responseData = [ + 'res' => 1, + 'ido' => $data['ido'], + 'npc' => $data['npc'], + 'che' => 42, + 'exe' => 42, + 'ida' => $data['ida'], + 'idc' => $data['idc'] + ]; + + return new JsonResponse($responseData, Response::HTTP_OK); + } + + + #[Route('/opengnsys/rest/__ogAdmClient/AutoexecCliente', methods: ['POST'])] + public function autoexecCliente(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'exe']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Crear archivo autoexec + $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; + try { + $fileExe = fopen($fileAutoExec, 'w'); + fwrite($fileExe, json_encode(['param' => '@'.join(["nfn=popup\rtitle=my title\rmessage=my message"])])); + fclose($fileExe); + } catch (\Exception $e) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $responseData = [ + 'res' => 1, + 'nfl' => $fileAutoExec + ]; + + return new JsonResponse($responseData, Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/enviaArchivo', methods: ['POST'])] + public function enviaArchivo(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'nfl']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + $nfl = $data['nfl']; + if (!file_exists($nfl)) { + return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); + } + + $contents = file_get_contents($nfl); + + return new JsonResponse(['contents' => $contents], Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] + public function comandosPendientes(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Simula que el cliente existe + if (!$this->clienteExistente($data['iph'])) { + return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); + } + + // Simula obtener comandos pendientes + $param = $this->buscaComandos($data['ido']); + + if (is_null($param)) { + return new JsonResponse(['nfn' => 'NoComandosPtes'], Response::HTTP_OK); + } + + return new JsonResponse($param, Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/DisponibilidadComandos', methods: ['POST'])] + public function disponibilidadComandos(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'tpc']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Simula que el cliente existe + if (!$this->clienteExistente($data['iph'])) { + return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); + } + + return new JsonResponse([], Response::HTTP_OK); + } + + private function clienteExistente($iph) + { + // Simula que el cliente existe + return true; + } + + private function buscaComandos($ido) + { + // Simula obtener comandos pendientes + return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; + } +} diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index 9e0ae6f..535a1c9 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -20,7 +20,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface $this->addRefreshToken($openApi); $this->addSearchEndpoint($openApi); - + $this->addOgAgentEndpoints($openApi); return $openApi; } @@ -126,4 +126,580 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface ]) )); } + + 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', 'ido', 'npc', 'idc', 'ida', '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', 'ido', 'npc', 'idc', 'ida', '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' => ['iph', 'ido', 'npc', 'idc', 'ida', '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', 'npc', 'idc', 'ida'], + ]))) + ])) + ->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', 'ido', 'npc', 'idc', 'ida', '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', + ], + ], + ], + ], + ], + ], + ]) + )); + } } \ No newline at end of file -- 2.40.1 From bae07e46a17af780512544a908ea490895e5afdd Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Wed, 21 Aug 2024 09:39:49 +0200 Subject: [PATCH 02/19] refs #624. Added ogAdmClientController API --- .../OgAgent/OgAdmClientController.php | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/Controller/OgAgent/OgAdmClientController.php diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php new file mode 100644 index 0000000..613b076 --- /dev/null +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -0,0 +1,155 @@ +toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'cfg']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Suponemos que el proceso para incluir al cliente es exitoso + + $responseData = [ + 'res' => 1, + 'ido' => $data['ido'], + 'npc' => $data['npc'], + 'che' => 42, + 'exe' => 42, + 'ida' => $data['ida'], + 'idc' => $data['idc'] + ]; + + return new JsonResponse($responseData, Response::HTTP_OK); + } + + + #[Route('/opengnsys/rest/__ogAdmClient/AutoexecCliente', methods: ['POST'])] + public function autoexecCliente(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'exe']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Crear archivo autoexec + $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; + try { + $fileExe = fopen($fileAutoExec, 'w'); + fwrite($fileExe, json_encode(['param' => '@'.join(["nfn=popup\rtitle=my title\rmessage=my message"])])); + fclose($fileExe); + } catch (\Exception $e) { + return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + $responseData = [ + 'res' => 1, + 'nfl' => $fileAutoExec + ]; + + return new JsonResponse($responseData, Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/enviaArchivo', methods: ['POST'])] + public function enviaArchivo(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'nfl']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + $nfl = $data['nfl']; + if (!file_exists($nfl)) { + return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); + } + + $contents = file_get_contents($nfl); + + return new JsonResponse(['contents' => $contents], Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] + public function comandosPendientes(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Simula que el cliente existe + if (!$this->clienteExistente($data['iph'])) { + return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); + } + + // Simula obtener comandos pendientes + $param = $this->buscaComandos($data['ido']); + + if (is_null($param)) { + return new JsonResponse(['nfn' => 'NoComandosPtes'], Response::HTTP_OK); + } + + return new JsonResponse($param, Response::HTTP_OK); + } + + #[Route('/opengnsys/rest/__ogAdmClient/DisponibilidadComandos', methods: ['POST'])] + public function disponibilidadComandos(Request $request): JsonResponse + { + $data = $request->toArray(); + $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'tpc']; + + foreach ($requiredFields as $field) { + if (!isset($data[$field])) { + return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); + } + } + + // Simula que el cliente existe + if (!$this->clienteExistente($data['iph'])) { + return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); + } + + return new JsonResponse([], Response::HTTP_OK); + } + + private function clienteExistente($iph) + { + // Simula que el cliente existe + return true; + } + + private function buscaComandos($ido) + { + // Simula obtener comandos pendientes + return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; + } +} \ No newline at end of file -- 2.40.1 From c8a348449ca968534c9dfa99e3a64568bc2cff6b Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Thu, 22 Aug 2024 09:19:19 +0200 Subject: [PATCH 03/19] refs #624. Updated OgAgentController --- .../OgAgent/OgAdmClientController.php | 2 +- src/Controller/OgAgent/OgAgentController.php | 140 ------------------ 2 files changed, 1 insertion(+), 141 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 613b076..ee1d445 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -14,7 +14,7 @@ use Symfony\Component\Routing\Attribute\Route; #[AsController] class OgAdmClientController extends AbstractController { - #[\Symfony\Component\Routing\Annotation\Route('/opengnsys/rest/__ogAdmClient/InclusionCliente', methods: ['POST'])] + #[Route('/opengnsys/rest/__ogAdmClient/InclusionCliente', methods: ['POST'])] public function inclusionCliente(Request $request): JsonResponse { $data = $request->toArray(); diff --git a/src/Controller/OgAgent/OgAgentController.php b/src/Controller/OgAgent/OgAgentController.php index b402993..9fc6edd 100644 --- a/src/Controller/OgAgent/OgAgentController.php +++ b/src/Controller/OgAgent/OgAgentController.php @@ -81,144 +81,4 @@ class OgAgentController extends AbstractController return new JsonResponse([], Response::HTTP_OK); } - - - #[Route('/opengnsys/rest/__ogAdmClient/InclusionCliente', methods: ['POST'])] - public function inclusionCliente(Request $request): JsonResponse - { - $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'cfg']; - - foreach ($requiredFields as $field) { - if (!isset($data[$field])) { - return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); - } - } - - // Suponemos que el proceso para incluir al cliente es exitoso - - $responseData = [ - 'res' => 1, - 'ido' => $data['ido'], - 'npc' => $data['npc'], - 'che' => 42, - 'exe' => 42, - 'ida' => $data['ida'], - 'idc' => $data['idc'] - ]; - - return new JsonResponse($responseData, Response::HTTP_OK); - } - - - #[Route('/opengnsys/rest/__ogAdmClient/AutoexecCliente', methods: ['POST'])] - public function autoexecCliente(Request $request): JsonResponse - { - $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'exe']; - - foreach ($requiredFields as $field) { - if (!isset($data[$field])) { - return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); - } - } - - // Crear archivo autoexec - $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; - try { - $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode(['param' => '@'.join(["nfn=popup\rtitle=my title\rmessage=my message"])])); - fclose($fileExe); - } catch (\Exception $e) { - return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); - } - - $responseData = [ - 'res' => 1, - 'nfl' => $fileAutoExec - ]; - - return new JsonResponse($responseData, Response::HTTP_OK); - } - - #[Route('/opengnsys/rest/__ogAdmClient/enviaArchivo', methods: ['POST'])] - public function enviaArchivo(Request $request): JsonResponse - { - $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'nfl']; - - foreach ($requiredFields as $field) { - if (!isset($data[$field])) { - return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); - } - } - - $nfl = $data['nfl']; - if (!file_exists($nfl)) { - return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); - } - - $contents = file_get_contents($nfl); - - return new JsonResponse(['contents' => $contents], Response::HTTP_OK); - } - - #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] - public function comandosPendientes(Request $request): JsonResponse - { - $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida']; - - foreach ($requiredFields as $field) { - if (!isset($data[$field])) { - return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); - } - } - - // Simula que el cliente existe - if (!$this->clienteExistente($data['iph'])) { - return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); - } - - // Simula obtener comandos pendientes - $param = $this->buscaComandos($data['ido']); - - if (is_null($param)) { - return new JsonResponse(['nfn' => 'NoComandosPtes'], Response::HTTP_OK); - } - - return new JsonResponse($param, Response::HTTP_OK); - } - - #[Route('/opengnsys/rest/__ogAdmClient/DisponibilidadComandos', methods: ['POST'])] - public function disponibilidadComandos(Request $request): JsonResponse - { - $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'tpc']; - - foreach ($requiredFields as $field) { - if (!isset($data[$field])) { - return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); - } - } - - // Simula que el cliente existe - if (!$this->clienteExistente($data['iph'])) { - return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); - } - - return new JsonResponse([], Response::HTTP_OK); - } - - private function clienteExistente($iph) - { - // Simula que el cliente existe - return true; - } - - private function buscaComandos($ido) - { - // Simula obtener comandos pendientes - return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; - } } -- 2.40.1 From 16e3168c3c0210b712e6c729ea7d109fc466a76a Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 11:46:57 +0200 Subject: [PATCH 04/19] refs #624. Added ogAgent controller API --- src/Controller/OgAgent/OgAdmClientController.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index ee1d445..55b4370 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -18,7 +18,7 @@ class OgAdmClientController extends AbstractController public function inclusionCliente(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'cfg']; + $requiredFields = ['iph', 'cfg']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { @@ -26,8 +26,6 @@ class OgAdmClientController extends AbstractController } } - // Suponemos que el proceso para incluir al cliente es exitoso - $responseData = [ 'res' => 1, 'ido' => $data['ido'], @@ -46,7 +44,7 @@ class OgAdmClientController extends AbstractController public function autoexecCliente(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'exe']; + $requiredFields = ['iph', 'exe']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { @@ -54,7 +52,6 @@ class OgAdmClientController extends AbstractController } } - // Crear archivo autoexec $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); @@ -76,7 +73,7 @@ class OgAdmClientController extends AbstractController public function enviaArchivo(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'nfl']; + $requiredFields = ['nfl']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { @@ -98,7 +95,7 @@ class OgAdmClientController extends AbstractController public function comandosPendientes(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida']; + $requiredFields = ['iph', 'ido']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { @@ -125,7 +122,7 @@ class OgAdmClientController extends AbstractController public function disponibilidadComandos(Request $request): JsonResponse { $data = $request->toArray(); - $requiredFields = ['iph', 'ido', 'npc', 'idc', 'ida', 'tpc']; + $requiredFields = ['iph', 'tpc']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { -- 2.40.1 From 7e84855117341bb4c331e93f44dc9beba3031a96 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 12:20:32 +0200 Subject: [PATCH 05/19] refs #624. Added ogAgent controller API --- src/Controller/OgAgent/OgAdmClientController.php | 11 ++++------- src/OpenApi/OpenApiFactory.php | 10 +++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 55b4370..6432080 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -28,12 +28,12 @@ class OgAdmClientController extends AbstractController $responseData = [ 'res' => 1, - 'ido' => $data['ido'], - 'npc' => $data['npc'], + 'ido' => $data['ido'] ?? null, + 'npc' => $data['npc'] ?? null, 'che' => 42, 'exe' => 42, - 'ida' => $data['ida'], - 'idc' => $data['idc'] + 'ida' => $data['ida'] ?? null, + 'idc' => $data['idc'] ?? null, ]; return new JsonResponse($responseData, Response::HTTP_OK); @@ -130,7 +130,6 @@ class OgAdmClientController extends AbstractController } } - // Simula que el cliente existe if (!$this->clienteExistente($data['iph'])) { return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); } @@ -140,13 +139,11 @@ class OgAdmClientController extends AbstractController private function clienteExistente($iph) { - // Simula que el cliente existe return true; } private function buscaComandos($ido) { - // Simula obtener comandos pendientes return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; } } \ No newline at end of file diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index 535a1c9..675a6d6 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -353,7 +353,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface 'type' => 'string', ], ], - 'required' => ['iph', 'ido', 'npc', 'idc', 'ida', 'cfg'], + 'required' => ['iph', 'cfg'], ]))) ])) ->withRequired(true) @@ -401,7 +401,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface 'type' => 'string', ], ], - 'required' => ['iph', 'ido', 'npc', 'idc', 'ida', 'exe'], + 'required' => ['iph', 'exe'], ]))) ])) ->withRequired(true) @@ -480,7 +480,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface 'type' => 'string', ], ], - 'required' => ['iph', 'ido', 'npc', 'idc', 'ida', 'nfl'], + 'required' => ['nfl'], ]))) ])) ->withRequired(true) @@ -563,7 +563,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface 'type' => 'integer', ], ], - 'required' => ['iph', 'ido', 'npc', 'idc', 'ida'], + 'required' => ['iph', 'ido'], ]))) ])) ->withRequired(true) @@ -655,7 +655,7 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface 'type' => 'integer', ], ], - 'required' => ['iph', 'ido', 'npc', 'idc', 'ida', 'tpc'], + 'required' => ['iph', 'tpc'], ]))) ])) ->withRequired(true) -- 2.40.1 From ee779798bf39333afef1d6d8acb6177a3ec67d26 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:01:21 +0200 Subject: [PATCH 06/19] refs #624. Added ogAgent controller API --- src/Controller/OgAgent/OgAdmClientController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 6432080..3c16ace 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -28,12 +28,12 @@ class OgAdmClientController extends AbstractController $responseData = [ 'res' => 1, - 'ido' => $data['ido'] ?? null, - 'npc' => $data['npc'] ?? null, + 'ido' => $data['ido'] ?? 42, + 'npc' => $data['npc'] ?? 42, 'che' => 42, 'exe' => 42, - 'ida' => $data['ida'] ?? null, - 'idc' => $data['idc'] ?? null, + 'ida' => $data['ida'] ?? 42, + 'idc' => $data['idc'] ?? 42, ]; return new JsonResponse($responseData, Response::HTTP_OK); -- 2.40.1 From 59ce22e6f1f5ccc44cc01bc3f94ac18b8adb5861 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:14:55 +0200 Subject: [PATCH 07/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 3c16ace..34af054 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -55,7 +55,7 @@ class OgAdmClientController extends AbstractController $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode(['param' => '@'.join(["nfn=popup\rtitle=my title\rmessage=my message"])])); + fwrite($fileExe, json_encode(['param' => ["nfn=popup\rtitle=my title\rmessage=my message"]])); fclose($fileExe); } catch (\Exception $e) { return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -- 2.40.1 From 4b197933716e88fb06d5b9210851794bc5d41be1 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:23:51 +0200 Subject: [PATCH 08/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 34af054..0d2649e 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -46,6 +46,8 @@ class OgAdmClientController extends AbstractController $data = $request->toArray(); $requiredFields = ['iph', 'exe']; + $responseData = ['res' => 0]; + foreach ($requiredFields as $field) { if (!isset($data[$field])) { return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); @@ -55,7 +57,7 @@ class OgAdmClientController extends AbstractController $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode(['param' => ["nfn=popup\rtitle=my title\rmessage=my message"]])); + fwrite($fileExe, json_encode(['contents' => "nfn=popup\rtitle=my title\rmessage=my message"])); fclose($fileExe); } catch (\Exception $e) { return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -- 2.40.1 From cb72571e39a7b66484ea99b01cb5263b3c82a337 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:49:13 +0200 Subject: [PATCH 09/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 0d2649e..f6a2cf4 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -88,9 +88,9 @@ class OgAdmClientController extends AbstractController return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); } - $contents = file_get_contents($nfl); + //$contents = file_get_contents($nfl); - return new JsonResponse(['contents' => $contents], Response::HTTP_OK); + return new JsonResponse(['contents' => base64_decode($nfl)], Response::HTTP_OK); } #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] -- 2.40.1 From e42f9613b28dd8d873d850653c2d8c30442298e2 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:54:03 +0200 Subject: [PATCH 10/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index f6a2cf4..7999247 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -88,9 +88,9 @@ class OgAdmClientController extends AbstractController return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); } - //$contents = file_get_contents($nfl); + $contents = file_get_contents($nfl); - return new JsonResponse(['contents' => base64_decode($nfl)], Response::HTTP_OK); + return new JsonResponse(['contents' => base64_encode($contents)], Response::HTTP_OK); } #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] -- 2.40.1 From 5859b47619f140fd1c1fba4741ed0c3d0c64c7cc Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Mon, 26 Aug 2024 14:55:07 +0200 Subject: [PATCH 11/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 7999247..fd972ff 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -90,7 +90,7 @@ class OgAdmClientController extends AbstractController $contents = file_get_contents($nfl); - return new JsonResponse(['contents' => base64_encode($contents)], Response::HTTP_OK); + return new JsonResponse(base64_encode($contents), Response::HTTP_OK); } #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] -- 2.40.1 From c6923d49fae95dd0dbe0109e985c6a9a5aeda3cb Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 09:51:30 +0200 Subject: [PATCH 12/19] refs #624. Changed endpoint AutoExec --- src/Controller/OgAgent/OgAdmClientController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index fd972ff..3a61d60 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -84,6 +84,8 @@ class OgAdmClientController extends AbstractController } $nfl = $data['nfl']; + //$nfl = $this->getParameter('kernel.project_dir') . '/file.txt'; + if (!file_exists($nfl)) { return new JsonResponse(['message' => 'File not found'], Response::HTTP_NOT_FOUND); } -- 2.40.1 From a54e9b113e5d2001932a53534917eae428299bff Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 10:59:39 +0200 Subject: [PATCH 13/19] refs #624. Changed endpoint enviaArchivo --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 3a61d60..d57868b 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -92,7 +92,7 @@ class OgAdmClientController extends AbstractController $contents = file_get_contents($nfl); - return new JsonResponse(base64_encode($contents), Response::HTTP_OK); + return new JsonResponse(['contents' => base64_encode($contents)], Response::HTTP_OK); } #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] -- 2.40.1 From 9574420180c7fd8bcd895c23fc820a6c2b640fb2 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:03:50 +0200 Subject: [PATCH 14/19] refs #624. Changed endpoint enviaArchivo --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index d57868b..bb72d15 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -57,7 +57,7 @@ class OgAdmClientController extends AbstractController $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode(['contents' => "nfn=popup\rtitle=my title\rmessage=my message"])); + fwrite($fileExe, json_encode("nfn=popup\rtitle=my title\rmessage=my message")); fclose($fileExe); } catch (\Exception $e) { return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -- 2.40.1 From a604e6dfc46fdadd078e8e2b8d407bf072dbae77 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:10:53 +0200 Subject: [PATCH 15/19] refs #624. Changed endpoint enviaArchivo --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index bb72d15..17edb18 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -57,7 +57,7 @@ class OgAdmClientController extends AbstractController $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode("nfn=popup\rtitle=my title\rmessage=my message")); + fwrite($fileExe, json_encode("nfn=popup\x0dtitle=my title\x0dmessage=my message")); fclose($fileExe); } catch (\Exception $e) { return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -- 2.40.1 From f848c2691e1c6b5f4a85f191e92522232a533c13 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:13:37 +0200 Subject: [PATCH 16/19] refs #624. Changed endpoint enviaArchivo --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 17edb18..ffecc2e 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -57,7 +57,7 @@ class OgAdmClientController extends AbstractController $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); - fwrite($fileExe, json_encode("nfn=popup\x0dtitle=my title\x0dmessage=my message")); + fwrite($fileExe, "nfn=popup\x0dtitle=my title\x0dmessage=my message"); fclose($fileExe); } catch (\Exception $e) { return new JsonResponse([], Response::HTTP_INTERNAL_SERVER_ERROR); -- 2.40.1 From 6094431a3892cf3961f865763a0bd929bf1a82ba Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:19:48 +0200 Subject: [PATCH 17/19] refs #624. Changed endpoint comandosPendientes --- src/Controller/OgAgent/OgAdmClientController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index ffecc2e..8fff66d 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -115,7 +115,7 @@ class OgAdmClientController extends AbstractController // Simula obtener comandos pendientes $param = $this->buscaComandos($data['ido']); - if (is_null($param)) { + if (!$param) { return new JsonResponse(['nfn' => 'NoComandosPtes'], Response::HTTP_OK); } @@ -146,8 +146,8 @@ class OgAdmClientController extends AbstractController return true; } - private function buscaComandos($ido) + private function buscaComandos($ido): null { - return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; + return null; } } \ No newline at end of file -- 2.40.1 From 16ece4c2b6d36cb40d73d89bc1ef3601edfa9533 Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:24:50 +0200 Subject: [PATCH 18/19] refs #624. Changed endpoint disponibilidadCOmandos --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index 8fff66d..c96a53f 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -138,7 +138,7 @@ class OgAdmClientController extends AbstractController return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); } - return new JsonResponse([], Response::HTTP_OK); + return new JsonResponse(json_encode ((object) null), Response::HTTP_OK); } private function clienteExistente($iph) -- 2.40.1 From 45dd18f55c22d474f116a9408f56ecf1e86d637b Mon Sep 17 00:00:00 2001 From: Manuel Aranda Date: Tue, 27 Aug 2024 11:28:41 +0200 Subject: [PATCH 19/19] refs #624. Changed endpoint disponibilidadCOmandos --- src/Controller/OgAgent/OgAdmClientController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php index c96a53f..0b50352 100644 --- a/src/Controller/OgAgent/OgAdmClientController.php +++ b/src/Controller/OgAgent/OgAdmClientController.php @@ -138,7 +138,7 @@ class OgAdmClientController extends AbstractController return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND); } - return new JsonResponse(json_encode ((object) null), Response::HTTP_OK); + return new JsonResponse(((object) null), Response::HTTP_OK); } private function clienteExistente($iph) -- 2.40.1