79 lines
3.3 KiB
PHP
79 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Service\OgBoot\PxeBootFile;
|
|
|
|
use App\Entity\PxeBootFile;
|
|
use Symfony\Component\HttpClient\HttpClient;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
readonly class PostService
|
|
{
|
|
public function __construct(
|
|
private string $ogBootApiUrl
|
|
)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @throws TransportExceptionInterface
|
|
* @throws ServerExceptionInterface
|
|
* @throws RedirectionExceptionInterface
|
|
* @throws ClientExceptionInterface
|
|
*/
|
|
public function __invoke(PxeBootFile $bootFile)
|
|
{
|
|
$httpClient = HttpClient::create([
|
|
'verify_peer' => false, // Ignorar la verificación del certificado SSL
|
|
'verify_host' => false, // Ignorar la verificación del nombre del host
|
|
]);
|
|
|
|
foreach ($bootFile->getClients() as $client) {
|
|
$data = [
|
|
'template_name' => 'pxe_default',
|
|
'mac' => $client->getMac(),
|
|
'lang' => 'es_ES.UTF_8',
|
|
'ip' => $client->getIp(),
|
|
'server_ip' => '92.168.2.1',
|
|
'router' => $client->getOrganizationalUnit()->getNetworkSettings()->getRouter(),
|
|
'netmask' => $client->getOrganizationalUnit()->getNetworkSettings() ? $client->getOrganizationalUnit()->getNetworkSettings()->getNetmask() : '255.255.255.0',
|
|
'computer_name' => $client->getName(),
|
|
'netiface' => $client->getNetiface(),
|
|
'group' => $client->getOrganizationalUnit()->getName(),
|
|
'ogrepo' => $client->getRepository() ? $client->getRepository()->getIpAddress() : '192.168.2.1',
|
|
'oglive' => '127.0.0.1',
|
|
'oglog' => '192.168.2.1',
|
|
'ogshare' => '192.168.2.1',
|
|
'oglivedir' => 'ogLive',
|
|
'ogprof' => 'false',
|
|
'hardprofile' => $client->getHardwareProfile() ? $client->getHardwareProfile()->getDescription() : 'default',
|
|
'ogntp' => $client->getOrganizationalUnit()->getNetworkSettings()?->getNtp(),
|
|
'ogdns' => $client->getOrganizationalUnit()->getNetworkSettings()?->getDns(),
|
|
'ogProxy' => $client->getOrganizationalUnit()->getNetworkSettings()?->getProxy(),
|
|
'ogunit' => '',
|
|
'resolution' => '788'
|
|
];
|
|
|
|
try {
|
|
$response = $httpClient->request('POST', $this->ogBootApiUrl.'/ogboot/v1/pxes', [
|
|
'headers' => [
|
|
'accept' => 'application/json',
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
'json' => $data
|
|
]);
|
|
} catch (TransportExceptionInterface $e) {
|
|
return new JsonResponse( data: $e->getMessage(), status: Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
}
|
|
|
|
return json_decode($response->getContent(), true);
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
} |