toArray(); $requiredFields = ['iph', 'cfg']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); } } $responseData = [ 'res' => 1, 'ido' => $data['ido'] ?? 42, 'npc' => $data['npc'] ?? 42, 'che' => 42, 'exe' => 42, 'ida' => $data['ida'] ?? 42, 'idc' => $data['idc'] ?? 42, ]; 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', 'exe']; $responseData = ['res' => 0]; foreach ($requiredFields as $field) { if (!isset($data[$field])) { return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); } } $fileAutoExec = '/tmp/Sautoexec-' . $data['iph']; try { $fileExe = fopen($fileAutoExec, 'w'); fwrite($fileExe, "nfn=popup\x0dtitle=my title\x0dmessage=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 = ['nfl']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); } } $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); } $contents = file_get_contents($nfl); return new JsonResponse(['contents' => base64_encode($contents)], Response::HTTP_OK); } #[Route('/opengnsys/rest/__ogAdmClient/ComandosPendientes', methods: ['POST'])] public function comandosPendientes(Request $request): JsonResponse { $data = $request->toArray(); $requiredFields = ['iph', 'ido']; 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', 'tpc']; foreach ($requiredFields as $field) { if (!isset($data[$field])) { return new JsonResponse(['message' => "Missing parameter: $field"], Response::HTTP_BAD_REQUEST); } } 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) { return true; } private function buscaComandos($ido) { return ['nfn' => 'popup', 'title' => 'my title', 'message' => 'my message', 'ids' => 42]; } }