Added ogAgent webhook logic in started, stoped, loggin and logout
testing/ogcore-api/pipeline/head This commit looks good Details
testing/ogcore-api/pipeline/tag This commit looks good Details

composer-install opengnsys_devel-0.0.17
Manuel Aranda Rosales 2024-11-27 16:48:21 +01:00
parent e3b5bc202c
commit dd9cd5e2cf
4 changed files with 60 additions and 11 deletions

View File

@ -61,7 +61,7 @@ services:
api_platform.filter.image.search:
parent: 'api_platform.doctrine.orm.search_filter'
arguments: [ { 'id': 'exact', 'name': 'partial', 'repository.id': 'exact'} ]
arguments: [ { 'id': 'exact', 'name': 'partial', 'repository.id': 'exact', status: 'exact'} ]
tags: [ 'api_platform.filter' ]
api_platform.filter.image.boolean:

View File

@ -44,6 +44,12 @@ class OgAgentController extends AbstractController
case 'Linux':
$client->setStatus(ClientStatus::LINUX);
break;
case 'Windows':
$client->setStatus(ClientStatus::WINDOWS);
break;
case 'MacOS':
$client->setStatus(ClientStatus::MACOS);
break;
default:
return new JsonResponse(['message' => 'Invalid status'], Response::HTTP_BAD_REQUEST);
@ -67,7 +73,14 @@ class OgAgentController extends AbstractController
}
}
// Procesar los datos recibidos si es necesario
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['mac' => $data['mac']]);
if (!$client) {
return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND);
}
$client->setStatus(ClientStatus::OFF);
$this->entityManager->persist($client);
$this->entityManager->flush();
return new JsonResponse([], Response::HTTP_OK);
}
@ -84,7 +97,25 @@ class OgAgentController extends AbstractController
}
}
// Procesar los datos recibidos si es necesario
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $data['ip']]);
if (!$client) {
return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND);
}
switch ($data['ostype']) {
case 'Linux':
$client->setStatus(ClientStatus::LINUX_SESSION);
break;
case 'Windows':
$client->setStatus(ClientStatus::WINDOWS_SESSION);
break;
case 'MacOS':
$client->setStatus(ClientStatus::MACOS_SESSION);
break;
default:
return new JsonResponse(['message' => 'Invalid status'], Response::HTTP_BAD_REQUEST);
}
return new JsonResponse([], Response::HTTP_OK);
}
@ -101,7 +132,25 @@ class OgAgentController extends AbstractController
}
}
// Procesar los datos recibidos si es necesario
$client = $this->entityManager->getRepository(Client::class)->findOneBy(['ip' => $data['ip']]);
if (!$client) {
return new JsonResponse(['message' => 'Client not found'], Response::HTTP_NOT_FOUND);
}
switch ($data['ostype']) {
case 'Linux':
$client->setStatus(ClientStatus::LINUX);
break;
case 'Windows':
$client->setStatus(ClientStatus::WINDOWS);
break;
case 'MacOS':
$client->setStatus(ClientStatus::MACOS);
break;
default:
return new JsonResponse(['message' => 'Invalid status'], Response::HTTP_BAD_REQUEST);
}
return new JsonResponse([], Response::HTTP_OK);
}

View File

@ -32,13 +32,10 @@ class SyncAction extends AbstractOgBootController
foreach ($content['message']['installed_ogLives'] as $ogLive) {
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);
if ($ogLiveEntity) {
$this->extracted($ogLiveEntity, $ogLive);
$this->entityManager->persist($ogLiveEntity);
} else {
if (!$ogLiveEntity) {
$ogLiveEntity = new OgLive();
$this->extracted($ogLiveEntity, $ogLive);
}
$this->extracted($ogLiveEntity, $ogLive);
$this->entityManager->persist($ogLiveEntity);
}
$this->entityManager->flush();
@ -52,9 +49,9 @@ class SyncAction extends AbstractOgBootController
* @param mixed $ogLive
* @return void
*/
private function extracted(OgLive|null $ogLiveEntity, mixed $ogLive): void
private function extracted(OgLive $ogLiveEntity, mixed $ogLive): void
{
if (!$ogLiveEntity){
if (!$ogLiveEntity->getId()){
$ogLiveEntity->setName(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory']));
}
$ogLiveEntity->setInstalled(true);

View File

@ -18,6 +18,8 @@ final class ClientStatus
public const string MACOS = 'macos';
public const string MACOS_SESSION = 'macos-session';
public const string WINDOWS = 'windows';
public const string WINDOWS_SESSION = 'windows-session';
@ -30,6 +32,7 @@ final class ClientStatus
self::LINUX => 'Linux',
self::LINUX_SESSION => 'Sesión Linux',
self::MACOS => 'MacOS',
self::MACOS_SESSION => 'Session en MacOS',
self::WINDOWS => 'Windows',
self::WINDOWS_SESSION => 'Sesión Windows',
];