refs #624. Added ogAdmClientController API
parent
782c345f43
commit
bae07e46a1
|
@ -0,0 +1,155 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\OgAgent;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Attribute\AsController;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
#[AsController]
|
||||||
|
class OgAdmClientController extends AbstractController
|
||||||
|
{
|
||||||
|
#[\Symfony\Component\Routing\Annotation\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];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue