diff --git a/src/Controller/OgAgent/OgAdmClientController.php b/src/Controller/OgAgent/OgAdmClientController.php new file mode 100644 index 0000000..8012b71 --- /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]; + } +} 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]; - } }