diff --git a/src/Controller/OgAgent/Webhook/StatusController.php b/src/Controller/OgAgent/Webhook/StatusController.php index f2cf5d1..c46a852 100644 --- a/src/Controller/OgAgent/Webhook/StatusController.php +++ b/src/Controller/OgAgent/Webhook/StatusController.php @@ -47,6 +47,7 @@ class StatusController extends AbstractController const string REFRESH = 'RESPUESTA_Actualizar'; const string SOFTWARE_INVENTORY = 'RESPUESTA_InventarioSoftware'; const string RUN_SCRIPT = 'RESPUESTA_EjecutarScript'; + const string INICIAR_SESION = 'RESPUESTA_IniciarSesion'; public function __construct( protected readonly EntityManagerInterface $entityManager, @@ -355,6 +356,32 @@ class StatusController extends AbstractController $this->entityManager->flush(); } + if (isset($data['nfn']) && $data['nfn'] === self::INICIAR_SESION) { + $clientIp = $data['iph'] ?? $request->getClientIp(); + $client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $clientIp]); + if ($client && isset($data['res']) && (int) $data['res'] !== 1) { + // IniciarSesion failed on the agent side; re-queue the login trace + $trace = $this->entityManager->getRepository(Trace::class)->findOneBy([ + 'client' => $client, + 'command' => CommandTypes::LOGIN, + 'status' => TraceStatus::PENDING, + ]); + if (!$trace) { + $this->logger->warning('RESPUESTA_IniciarSesion: failure, no pending trace to retry', [ + 'ip' => $clientIp, + 'job_id' => $data['job_id'] ?? null, + 'res' => $data['res'] ?? null, + ]); + } else { + $this->logger->warning('RESPUESTA_IniciarSesion: failure, trace kept pending for retry', [ + 'ip' => $clientIp, + 'trace_id' => $trace->getId(), + 'res' => $data['res'] ?? null, + ]); + } + } + } + return new JsonResponse(data: 'Webhook finished', status: Response::HTTP_OK); } diff --git a/src/EventListener/UdsSyncOnClientStatusListener.php b/src/EventListener/UdsSyncOnClientStatusListener.php index 268e160..1f3682b 100644 --- a/src/EventListener/UdsSyncOnClientStatusListener.php +++ b/src/EventListener/UdsSyncOnClientStatusListener.php @@ -3,6 +3,7 @@ namespace App\EventListener; use App\Entity\Client; +use App\Model\ClientStatus; use App\Service\UDS\UDSClient; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; use Doctrine\ORM\Event\PostFlushEventArgs; @@ -37,6 +38,14 @@ class UdsSyncOnClientStatusListener return; } + // INITIALIZING is a transient state set during the RemotePC reserve flow. + // Syncing with UDS at this point sends max_srvs=0/visible=false, which causes + // UDS to cancel the active reservation with an unreserve call after ~20 seconds. + [, $newStatus] = $changeSet['status']; + if ($newStatus === ClientStatus::INITIALIZING) { + return; + } + $ou = $entity->getOrganizationalUnit(); if (!$ou || !$ou->getRemoteCalendar()) { return; diff --git a/src/Service/UDS/UDSClient.php b/src/Service/UDS/UDSClient.php index 4680ce7..bf3438c 100644 --- a/src/Service/UDS/UDSClient.php +++ b/src/Service/UDS/UDSClient.php @@ -231,6 +231,11 @@ class UDSClient continue; } + $remotePC = $client->getRemotePC(); + if ($remotePC && $remotePC->isReservedActive()) { + continue; + } + if ($imageId !== null && !$this->clientHasImage($client, $imageId)) { continue; }