Added ogAgent webhook logic in started, stoped, loggin and logout
parent
e3b5bc202c
commit
dd9cd5e2cf
|
@ -61,7 +61,7 @@ services:
|
||||||
|
|
||||||
api_platform.filter.image.search:
|
api_platform.filter.image.search:
|
||||||
parent: 'api_platform.doctrine.orm.search_filter'
|
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' ]
|
tags: [ 'api_platform.filter' ]
|
||||||
|
|
||||||
api_platform.filter.image.boolean:
|
api_platform.filter.image.boolean:
|
||||||
|
|
|
@ -44,6 +44,12 @@ class OgAgentController extends AbstractController
|
||||||
case 'Linux':
|
case 'Linux':
|
||||||
$client->setStatus(ClientStatus::LINUX);
|
$client->setStatus(ClientStatus::LINUX);
|
||||||
break;
|
break;
|
||||||
|
case 'Windows':
|
||||||
|
$client->setStatus(ClientStatus::WINDOWS);
|
||||||
|
break;
|
||||||
|
case 'MacOS':
|
||||||
|
$client->setStatus(ClientStatus::MACOS);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new JsonResponse(['message' => 'Invalid status'], Response::HTTP_BAD_REQUEST);
|
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);
|
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);
|
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);
|
return new JsonResponse([], Response::HTTP_OK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,10 @@ class SyncAction extends AbstractOgBootController
|
||||||
|
|
||||||
foreach ($content['message']['installed_ogLives'] as $ogLive) {
|
foreach ($content['message']['installed_ogLives'] as $ogLive) {
|
||||||
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);
|
$ogLiveEntity = $this->entityManager->getRepository(OgLive::class)->findOneBy(['checksum' => $ogLive['id']]);
|
||||||
if ($ogLiveEntity) {
|
if (!$ogLiveEntity) {
|
||||||
$this->extracted($ogLiveEntity, $ogLive);
|
|
||||||
$this->entityManager->persist($ogLiveEntity);
|
|
||||||
} else {
|
|
||||||
$ogLiveEntity = new OgLive();
|
$ogLiveEntity = new OgLive();
|
||||||
$this->extracted($ogLiveEntity, $ogLive);
|
|
||||||
}
|
}
|
||||||
|
$this->extracted($ogLiveEntity, $ogLive);
|
||||||
$this->entityManager->persist($ogLiveEntity);
|
$this->entityManager->persist($ogLiveEntity);
|
||||||
}
|
}
|
||||||
$this->entityManager->flush();
|
$this->entityManager->flush();
|
||||||
|
@ -52,9 +49,9 @@ class SyncAction extends AbstractOgBootController
|
||||||
* @param mixed $ogLive
|
* @param mixed $ogLive
|
||||||
* @return void
|
* @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->setName(str_replace(self::OG_BOOT_DIRECTORY, '', $ogLive['directory']));
|
||||||
}
|
}
|
||||||
$ogLiveEntity->setInstalled(true);
|
$ogLiveEntity->setInstalled(true);
|
||||||
|
|
|
@ -18,6 +18,8 @@ final class ClientStatus
|
||||||
|
|
||||||
public const string MACOS = 'macos';
|
public const string MACOS = 'macos';
|
||||||
|
|
||||||
|
public const string MACOS_SESSION = 'macos-session';
|
||||||
|
|
||||||
public const string WINDOWS = 'windows';
|
public const string WINDOWS = 'windows';
|
||||||
|
|
||||||
public const string WINDOWS_SESSION = 'windows-session';
|
public const string WINDOWS_SESSION = 'windows-session';
|
||||||
|
@ -30,6 +32,7 @@ final class ClientStatus
|
||||||
self::LINUX => 'Linux',
|
self::LINUX => 'Linux',
|
||||||
self::LINUX_SESSION => 'Sesión Linux',
|
self::LINUX_SESSION => 'Sesión Linux',
|
||||||
self::MACOS => 'MacOS',
|
self::MACOS => 'MacOS',
|
||||||
|
self::MACOS_SESSION => 'Session en MacOS',
|
||||||
self::WINDOWS => 'Windows',
|
self::WINDOWS => 'Windows',
|
||||||
self::WINDOWS_SESSION => 'Sesión Windows',
|
self::WINDOWS_SESSION => 'Sesión Windows',
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue