From cd5eaf94e30a3965068a904d0fa6cae1ab9c217c Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Wed, 25 Mar 2026 15:09:40 +0100 Subject: [PATCH 1/7] =?UTF-8?q?-=20Nuevo=20webhook=20`START=5FSCRIPT`=20en?= =?UTF-8?q?=20StatusController=20que=20permite=20crear=20autom=C3=A1ticame?= =?UTF-8?q?nte=20una=20entidad=20Trace=20y=20poner=20el=20equipo=20local?= =?UTF-8?q?=20en=20estado=20`BUSY`=20cuando=20un=20cliente=20inicia=20sus?= =?UTF-8?q?=20propios=20scripts=20de=20forma=20aut=C3=B3noma=20(ej:=20men?= =?UTF-8?q?=C3=BAs=20locales=20de=20ogLive).=20-=20Se=20ha=20corregido=20u?= =?UTF-8?q?n=20bug=20en=20RunScriptAction=20que=20provocaba=20que=20al=20e?= =?UTF-8?q?nviar=20la=20orden=20de=20ejecutar=20un=20script=20desde=20la?= =?UTF-8?q?=20web=20de=20administraci=C3=B3n,=20la=20interfaz=20no=20cambi?= =?UTF-8?q?ara=20visualmente=20el=20estado=20del=20cliente=20a=20ocupado?= =?UTF-8?q?=20(rojo),=20unificando=20as=C3=AD=20el=20comportamiento=20con?= =?UTF-8?q?=20el=20resto=20de=20comandos=20(como=20crear=20o=20restaurar?= =?UTF-8?q?=20imagen).=20-=20En=20StatusController=20ahora=20se=20restable?= =?UTF-8?q?ce=20autom=C3=A1ticamente=20el=20estado=20del=20cliente=20a=20`?= =?UTF-8?q?OG=5FLIVE`=20cuando=20se=20recibe=20el=20webhook=20de=20finaliz?= =?UTF-8?q?aci=C3=B3n=20`RESPUESTA=5FEjecutarScript`,=20reflejando=20visua?= =?UTF-8?q?lmente=20que=20el=20equipo=20ha=20terminado=20de=20trabajar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 12 ++++++++++ src/Controller/OgAgent/RunScriptAction.php | 4 ++++ .../OgAgent/Webhook/StatusController.php | 22 +++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b2da4f..e55a867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,16 @@ # Changelog +## [1.2.9] - 2026-03-25 +### Added +- Nuevo webhook `START_SCRIPT` en StatusController que permite crear automáticamente una entidad Trace y poner el equipo local en estado `BUSY` cuando un cliente inicia sus propios scripts de forma autónoma (ej: menús locales de ogLive). +### Fixed +- Se ha corregido un bug en RunScriptAction que provocaba que al enviar la orden de ejecutar un script desde la web de administración, la interfaz no cambiara visualmente el estado del cliente a ocupado (rojo), unificando así el comportamiento con el resto de comandos (como crear o restaurar imagen). +### Improved +- En StatusController ahora se restablece automáticamente el estado del cliente a `OG_LIVE` cuando se recibe el webhook de finalización `RESPUESTA_EjecutarScript`, reflejando visualmente que el equipo ha terminado de trabajar. + +## [1.2.8] - 2026-03-20 +### Added +- Modificado MenuBrowserController para permitir la edición de las plantillas de menú en "raw", permitiendo modificar el código twig en lugar del html ya compilado por twig, de esta forma podemos editar el fichero twig y aplicar cambios para ver el resultado antes de guardar la plantilla. + ## [1.2.7] - 2026-03-17 ### Fixed - Se ha corregido la lectura de la variable `OGCLIENT_API_KEY` desde `env.json` para inyectarla correctamente en la plantilla PXE generada por `ogBoot`. diff --git a/src/Controller/OgAgent/RunScriptAction.php b/src/Controller/OgAgent/RunScriptAction.php index 6d0ae99..c72352a 100644 --- a/src/Controller/OgAgent/RunScriptAction.php +++ b/src/Controller/OgAgent/RunScriptAction.php @@ -147,6 +147,10 @@ class RunScriptAction extends AbstractOgAgentController $jobId = $response['job_id']; $inputData = ['script' => $input->script]; + if (!$this->isLinuxOrWindows($client) && !$this->isLinuxOrWindowsSession($client)) { + $client->setStatus(ClientStatus::BUSY); + } + $this->entityManager->persist($client); $this->entityManager->flush(); diff --git a/src/Controller/OgAgent/Webhook/StatusController.php b/src/Controller/OgAgent/Webhook/StatusController.php index d3132f6..2647972 100644 --- a/src/Controller/OgAgent/Webhook/StatusController.php +++ b/src/Controller/OgAgent/Webhook/StatusController.php @@ -81,6 +81,21 @@ class StatusController extends AbstractController $this->entityManager->persist($client); $this->entityManager->flush(); } + + if (isset($data['nfn']) && $data['nfn'] === 'START_SCRIPT') { + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); + if (!$trace) { + $clientIp = $data['iph'] ?? $request->getClientIp(); + $client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]); + if ($client) { + $this->createService->__invoke($client, CommandTypes::RUN_SCRIPT, TraceStatus::IN_PROGRESS, $data['job_id'], ['script' => $data['command'] ?? 'Local script']); + $this->logger->info('Trace automatically created for local script', ['job_id' => $data['job_id']]); + $client->setStatus(ClientStatus::BUSY); + $this->entityManager->persist($client); + $this->entityManager->flush(); + } + } + } if (isset($data['progress'])){ $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); @@ -242,6 +257,13 @@ class StatusController extends AbstractController $trace->setStatus(TraceStatus::SUCCESS); $trace->setFinishedAt(new \DateTime()); $this->entityManager->persist($trace); + + $client = $trace->getClient(); + if ($client && $client->getStatus() === ClientStatus::BUSY) { + $client->setStatus(ClientStatus::OG_LIVE); + $this->entityManager->persist($client); + } + $this->entityManager->flush(); } } From 76f272267676e88bf1bdb80fc800517a54fe62bd Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 26 Mar 2026 13:11:05 +0100 Subject: [PATCH 2/7] modificacion en el StatusController para capturar el cambio de estado ante un reboot o poweroff del cliente --- .../OgAgent/Webhook/StatusController.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Controller/OgAgent/Webhook/StatusController.php b/src/Controller/OgAgent/Webhook/StatusController.php index 2647972..3abd737 100644 --- a/src/Controller/OgAgent/Webhook/StatusController.php +++ b/src/Controller/OgAgent/Webhook/StatusController.php @@ -96,6 +96,28 @@ class StatusController extends AbstractController } } } + + if (isset($data['nfn']) && in_array($data['nfn'], ['REBOOT', 'POWEROFF'], true)) { + $clientIp = $data['iph'] ?? $request->getClientIp(); + $client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]); + if ($client) { + $traces = $this->entityManager->getRepository(Trace::class)->findBy(['client' => $client, 'status' => TraceStatus::IN_PROGRESS]); + foreach ($traces as $trace) { + $trace->setStatus(TraceStatus::SUCCESS); + $trace->setFinishedAt(new \DateTime()); + $this->entityManager->persist($trace); + } + + if ($client->getStatus() === ClientStatus::BUSY) { + $newStatus = ($data['nfn'] === 'REBOOT') ? ClientStatus::INITIALIZING : ClientStatus::TURNING_OFF; + $client->setStatus($newStatus); + $this->entityManager->persist($client); + } + + $this->entityManager->flush(); + $this->logger->info('Reboot/Poweroff webhook received. Automatically resolved in-progress traces.', ['num_traces' => count($traces), 'nfn' => $data['nfn']]); + } + } if (isset($data['progress'])){ $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id']]); From 8209d2f302187ac6abc013d01ce08e427f844e9a Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 26 Mar 2026 14:14:04 +0100 Subject: [PATCH 3/7] Modificado StatusController para que al recibir un webhook de Poweroff o reboot actualice el estado de las trazas en progreso y las ponga como finalizadas. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bcd249..b86c59f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.2.10] - 2026-03-25 +### Added +Modificado StatusController para que al recibir un webhook de Poweroff o reboot actualice el estado de las trazas en progreso y las ponga como finalizadas. + ## [1.2.9] - 2026-03-25 ### Added - Nuevo webhook `START_SCRIPT` en StatusController que permite crear automáticamente una entidad Trace y poner el equipo local en estado `BUSY` cuando un cliente inicia sus propios scripts de forma autónoma (ej: menús locales de ogLive). From 1156b5b99e0e6eac8e722b53d7bba8390188ddbf Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 30 Mar 2026 12:06:07 +0200 Subject: [PATCH 4/7] =?UTF-8?q?Modificada=20columna=20cacheContent=20de=20?= =?UTF-8?q?una=20partici=C3=B3n=20para=20que=20sea=20de=20tipo=20TEXT=20y?= =?UTF-8?q?=20contener=20la=20lista=20de=20ficheros=20que=20tiene=20la=20c?= =?UTF-8?q?ache.=20Se=20env=C3=ADa=20desde=20el=20ogagent=20al=20obtener?= =?UTF-8?q?=20la=20configuraci=C3=B3n=20mediante=20el=20campo=20[cac]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 4 ++++ src/Entity/Partition.php | 3 ++- src/Service/CreatePartitionService.php | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b86c59f..ab94347 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.2.11] - 2026-03-25 +### Added +Modificada columna cacheContent de una partición para que sea de tipo TEXT y contener la lista de ficheros que tiene la cache. Se envía desde el ogagent al obtener la configuración mediante el campo [cac] + ## [1.2.10] - 2026-03-25 ### Added Modificado StatusController para que al recibir un webhook de Poweroff o reboot actualice el estado de las trazas en progreso y las ponga como finalizadas. diff --git a/src/Entity/Partition.php b/src/Entity/Partition.php index b0cc7ca..3308da9 100644 --- a/src/Entity/Partition.php +++ b/src/Entity/Partition.php @@ -3,6 +3,7 @@ namespace App\Entity; use App\Repository\PartitionRepository; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PartitionRepository::class)] @@ -21,7 +22,7 @@ class Partition extends AbstractEntity #[ORM\Column] private ?int $size = null; - #[ORM\Column(length: 255, nullable: true)] + #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $cacheContent = null; #[ORM\Column(length: 255, nullable: true)] diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php index f48acfd..b72fd91 100644 --- a/src/Service/CreatePartitionService.php +++ b/src/Service/CreatePartitionService.php @@ -86,6 +86,7 @@ class CreatePartitionService $partitionEntity->setFilesystem($cfg['fsi']); $partitionEntity->setMemoryUsage(((int) $cfg['uso']) * 100); + $partitionEntity->setCacheContent($cfg['cac'] ?? null); $this->entityManager->persist($partitionEntity); $receivedPartitions[] = ['disk' => $cfg['disk'], 'partition' => $cfg['par']]; From 0482a3e9e80335cea8919ee7d2e19d49fd638d13 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Tue, 31 Mar 2026 13:18:45 +0200 Subject: [PATCH 5/7] =?UTF-8?q?A=C3=B1adida=20accion=20Refresh=20para=20ac?= =?UTF-8?q?tualizar=20el=20estado=20de=20un=20cliente=20o=20clientes.=20Se?= =?UTF-8?q?=20actualiza=20su=20configuracion=20de=20discos=20y=20se=20reca?= =?UTF-8?q?rga=20el=20ogBrowser=20por=20si=20hubiese=20cambio=20del=20menu?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 + config/api_platform/Client.yaml | 7 ++ src/Controller/OgAgent/RefreshAction.php | 93 ++++++++++++++++++++++++ src/Model/CommandTypes.php | 2 + 4 files changed, 105 insertions(+) create mode 100644 src/Controller/OgAgent/RefreshAction.php diff --git a/CHANGELOG.md b/CHANGELOG.md index ab94347..78f39ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## [1.3.0] - 2026-03-31 +### Added +Añadida acción Refresh para actualizar el estado de un cliente o clientes. Se actualiza su configuración de discos y se recarga el ogBrowser por si hubiese cambio del menu. ## [1.2.11] - 2026-03-25 ### Added diff --git a/config/api_platform/Client.yaml b/config/api_platform/Client.yaml index 3b0e448..229aa8c 100644 --- a/config/api_platform/Client.yaml +++ b/config/api_platform/Client.yaml @@ -100,6 +100,13 @@ resources: uriTemplate: /clients/server/power-off controller: App\Controller\OgAgent\PowerOffAction + refresh_client: + class: ApiPlatform\Metadata\Post + method: POST + input: App\Dto\Input\MultipleClientsInput + uriTemplate: /clients/server/refresh + controller: App\Controller\OgAgent\RefreshAction + check_partition_sizes: class: ApiPlatform\Metadata\Post method: POST diff --git a/src/Controller/OgAgent/RefreshAction.php b/src/Controller/OgAgent/RefreshAction.php new file mode 100644 index 0000000..2107a2d --- /dev/null +++ b/src/Controller/OgAgent/RefreshAction.php @@ -0,0 +1,93 @@ +clients as $clientEntity) { + /** @var Client $client */ + $client = $clientEntity->getEntity(); + + if (!$client->getIp()) { + throw new BadRequestHttpException('IP is required'); + } + + // ONLY execute if the client is in OG_LIVE state + if ($client->getStatus() !== ClientStatus::OG_LIVE) { + $this->logger->info('Skipping refresh for client not in OG_LIVE state', ['client' => $client->getId(), 'status' => $client->getStatus()]); + continue; + } + + $data = [ + 'nfn' => 'Actualizar', + 'ids' => '0' + ]; + + $response = $this->createRequest( + method: 'POST', + url: 'https://'.$client->getIp().':8000/ogAdmClient/Actualizar', + params: [ + 'json' => $data, + ], + token: $client->getToken(), + ); + + if (isset($response['error']) && $response['code'] === Response::HTTP_INTERNAL_SERVER_ERROR) { + $this->logger->error('Error refreshing client', ['client' => $client->getId(), 'error' => $response['error']]); + + if ($input->queue) { + $this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::PENDING, null, []); + continue; + } + + continue; + } + + $this->logger->info('Refreshing client menu and disk configuration', ['client' => $client->getId()]); + + $jobId = $response['job_id'] ?? null; + + // We do not change the status here, it remains OG_LIVE + // $client->setStatus(ClientStatus::OG_LIVE); + + $this->createService->__invoke($client, CommandTypes::REFRESH, TraceStatus::SUCCESS, $jobId, []); + } + + return new JsonResponse(data: [], status: Response::HTTP_OK); + } +} diff --git a/src/Model/CommandTypes.php b/src/Model/CommandTypes.php index cff2407..a788231 100644 --- a/src/Model/CommandTypes.php +++ b/src/Model/CommandTypes.php @@ -29,6 +29,7 @@ final class CommandTypes public const string HARDWARE_INVENTORY = 'hardware-inventory'; public const string SOFTWARE_INVENTORY = 'software-inventory'; public const string KILL_JOB = 'kill-job'; + public const string REFRESH = 'refresh'; private const array COMMAND_TYPES = [ self::DEPLOY_IMAGE => 'Deploy Image', @@ -56,6 +57,7 @@ final class CommandTypes self::HARDWARE_INVENTORY => 'Hardware Inventory', self::SOFTWARE_INVENTORY => 'Software Inventory', self::KILL_JOB => 'Kill Job', + self::REFRESH => 'Refresh', ]; public static function getCommandTypes(): array From b990a3d8946c6843b416bca4ad43347504e09ff3 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Wed, 8 Apr 2026 11:07:05 +0200 Subject: [PATCH 6/7] =?UTF-8?q?Partition:=20a=C3=B1adido=20campo=20deployD?= =?UTF-8?q?ate=20a=20la=20BBDD=20extra=C3=ADdo=20autom=C3=A1ticamente=20y?= =?UTF-8?q?=20de=20forma=20idempotente=20de=20la=20variable=20img=3D=20del?= =?UTF-8?q?=20getConfiguration=20del=20cliente,=20y=20securizaci=C3=B3n=20?= =?UTF-8?q?de=20fallbacks=20a=20null=20por=20seguridad.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 +++++++++- src/Dto/Output/PartitionOutput.php | 8 ++++++++ src/Entity/Partition.php | 15 +++++++++++++++ src/Service/CreatePartitionService.php | 26 ++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78f39ea..39571c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,15 @@ # Changelog +## [1.4.0] - 2026-04-08 +### Added +- Entidad Partition: Añadido el campo deployDate expuesto mediante el DTO para registrar la fecha exacta de despliegue de imagen. +- CreatePartitionService: Inclusión de lógica idempotente que asocia la imagen y extrae su fecha real directamente del fichero /.ogimage enviado por el cliente en el parámetro img=. + +### Fixed +- Limpieza explícita del deployDate (null) en caso de que el inventario no informe de fecha o haya alteraciones en el payload para evitar desincronizaciones de trazas de la imagen subyacente. + ## [1.3.0] - 2026-03-31 ### Added -Añadida acción Refresh para actualizar el estado de un cliente o clientes. Se actualiza su configuración de discos y se recarga el ogBrowser por si hubiese cambio del menu. +- Añadida acción Refresh para actualizar el estado de un cliente o clientes. Se actualiza su configuración de discos y se recarga el ogBrowser por si hubiese cambio del menu. ## [1.2.11] - 2026-03-25 ### Added diff --git a/src/Dto/Output/PartitionOutput.php b/src/Dto/Output/PartitionOutput.php index 76e55e2..0063ba6 100644 --- a/src/Dto/Output/PartitionOutput.php +++ b/src/Dto/Output/PartitionOutput.php @@ -74,6 +74,13 @@ class PartitionOutput extends AbstractOutput )] public ?int $memoryUsage = null; + #[Groups(['partition:read', 'client:read'])] + #[ApiProperty( + description: 'Fecha de despliegue de la imagen', + example: '2025-01-01T00:00:00+00:00' + )] + public ?\DateTimeInterface $deployDate = null; + public function __construct(Partition $partition) { parent::__construct($partition); @@ -94,5 +101,6 @@ class PartitionOutput extends AbstractOutput } $this->memoryUsage = $partition->getMemoryUsage() / 100; + $this->deployDate = $partition->getDeployDate(); } } \ No newline at end of file diff --git a/src/Entity/Partition.php b/src/Entity/Partition.php index 3308da9..dde3700 100644 --- a/src/Entity/Partition.php +++ b/src/Entity/Partition.php @@ -43,6 +43,21 @@ class Partition extends AbstractEntity #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')] private ?ImageImageRepository $image = null; + #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] + private ?\DateTimeInterface $deployDate = null; + + public function getDeployDate(): ?\DateTimeInterface + { + return $this->deployDate; + } + + public function setDeployDate(?\DateTimeInterface $deployDate): static + { + $this->deployDate = $deployDate; + + return $this; + } + public function getDiskNumber(): ?int { return $this->diskNumber; diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php index b72fd91..5798fe8 100644 --- a/src/Service/CreatePartitionService.php +++ b/src/Service/CreatePartitionService.php @@ -63,6 +63,32 @@ class CreatePartitionService $partitionEntity->setOperativeSystem($operativeSystem); } } + + if (isset($cfg['img']) && $cfg['img'] !== '') { + $imgParts = explode(':', $cfg['img']); + $imgName = $imgParts[0]; + $imgDate = $imgParts[1] ?? null; + + $imageImageRepository = $this->entityManager->getRepository(\App\Entity\ImageImageRepository::class) + ->findOneBy(['name' => $imgName]); + + if ($imageImageRepository) { + $partitionEntity->setImage($imageImageRepository); + $partitionEntity->setDeployDate(null); + if ($imgDate) { + $dateObj = \DateTime::createFromFormat('YmdHi', $imgDate); + if ($dateObj) { + $partitionEntity->setDeployDate($dateObj); + } + } + } else { + $partitionEntity->setImage(null); + $partitionEntity->setDeployDate(null); + } + } elseif (isset($cfg['img']) && $cfg['img'] === '') { + $partitionEntity->setImage(null); + $partitionEntity->setDeployDate(null); + } $partitionEntity->setClient($clientEntity); $partitionEntity->setDiskNumber($cfg['disk']); From 2eff4066dad70f5f8d294efaacb08b306a001470 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 9 Apr 2026 08:51:27 +0200 Subject: [PATCH 7/7] =?UTF-8?q?A=C3=B1adido=20tratamiento=20a=20RESPUESTA?= =?UTF-8?q?=5FActualizar=20para=20tratar=20la=20informacion=20de=20configu?= =?UTF-8?q?racion=20que=20envia=20el=20agente,=20de=20esta=20forma=20actua?= =?UTF-8?q?liza=20la=20informacion=20de=20la=20particion=20con=20el=20nomb?= =?UTF-8?q?re=20y=20la=20fecha=20de=20despliegue=20de=20una=20imagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OgAgent/Webhook/StatusController.php | 25 +++++++++++++++++++ src/Service/CreatePartitionService.php | 4 +-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Controller/OgAgent/Webhook/StatusController.php b/src/Controller/OgAgent/Webhook/StatusController.php index 3abd737..bc989ae 100644 --- a/src/Controller/OgAgent/Webhook/StatusController.php +++ b/src/Controller/OgAgent/Webhook/StatusController.php @@ -44,6 +44,7 @@ class StatusController extends AbstractController const string RESTORE_IMAGE_GIT = 'RESPUESTA_RestaurarImagenGit'; const string CONFIGURE_IMAGE = 'RESPUESTA_Configurar'; const string HARDWARE_INVENTORY = 'RESPUESTA_InventarioHardware'; + const string REFRESH = 'RESPUESTA_Actualizar'; const string SOFTWARE_INVENTORY = 'RESPUESTA_InventarioSoftware'; const string RUN_SCRIPT = 'RESPUESTA_EjecutarScript'; @@ -324,6 +325,30 @@ class StatusController extends AbstractController } } + if (isset($data['nfn']) && $data['nfn'] === self::REFRESH) { + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy(['jobId' => $data['job_id'] ?? '']); + if ($trace) { + $client = $trace->getClient(); + $trace->setStatus(TraceStatus::SUCCESS); + $trace->setFinishedAt(new \DateTime()); + $this->entityManager->persist($trace); + } else { + $clientIp = $data['iph'] ?? $request->getClientIp(); + $client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]); + } + + if ($client) { + $client->setStatus(ClientStatus::OG_LIVE); + $this->entityManager->persist($client); + + if (isset($data['cfg'])) { + $this->createPartitionService->__invoke($data, $client); + $this->logger->info('Partition configuration updated via RESPUESTA_Actualizar', ['job_id' => $data['job_id'] ?? 'none']); + } + } + $this->entityManager->flush(); + } + return new JsonResponse(data: 'Webhook finished', status: Response::HTTP_OK); } diff --git a/src/Service/CreatePartitionService.php b/src/Service/CreatePartitionService.php index 5798fe8..9e16482 100644 --- a/src/Service/CreatePartitionService.php +++ b/src/Service/CreatePartitionService.php @@ -66,7 +66,7 @@ class CreatePartitionService if (isset($cfg['img']) && $cfg['img'] !== '') { $imgParts = explode(':', $cfg['img']); - $imgName = $imgParts[0]; + $imgName = trim($imgParts[0]); $imgDate = $imgParts[1] ?? null; $imageImageRepository = $this->entityManager->getRepository(\App\Entity\ImageImageRepository::class) @@ -76,7 +76,7 @@ class CreatePartitionService $partitionEntity->setImage($imageImageRepository); $partitionEntity->setDeployDate(null); if ($imgDate) { - $dateObj = \DateTime::createFromFormat('YmdHi', $imgDate); + $dateObj = \DateTime::createFromFormat('YmdHi', trim($imgDate)); if ($dateObj) { $partitionEntity->setDeployDate($dateObj); }