refs #1001 removes all hardcoded routes in the controller and dynamically manage tftpboot directory for all endpoints. Fix some index problems in installer and comments tzConfigure function that is failingright now
parent
1e406be464
commit
943467a8ad
|
@ -4,7 +4,7 @@
|
||||||
# Put parameters here that don't need to change on each machine where the app is deployed
|
# Put parameters here that don't need to change on each machine where the app is deployed
|
||||||
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
|
||||||
parameters:
|
parameters:
|
||||||
|
tftpboot_dir: '%kernel.project_dir%/tftpboot'
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
_defaults:
|
_defaults:
|
||||||
|
|
|
@ -904,12 +904,12 @@ except Exception as e:
|
||||||
logger.error(f"Error configuring php fpm: {e}")
|
logger.error(f"Error configuring php fpm: {e}")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
try:
|
#try:
|
||||||
logger.info("Configuring ogCore")
|
# logger.info("Configuring ogCore")
|
||||||
tzConfigure()
|
# tzConfigure()
|
||||||
except Exception as e:
|
#except Exception as e:
|
||||||
logger.error(f"Error configuring ogCore: {e}")
|
# logger.error(f"Error configuring ogCore: {e}")
|
||||||
exit(1)
|
# exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info("Configuring Samba")
|
logger.info("Configuring Samba")
|
||||||
|
@ -922,3 +922,4 @@ logger.info(f"ogBoot installation finished.")
|
||||||
|
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
console_handler.close()
|
console_handler.close()
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,14 @@ class OgBootController
|
||||||
private $curlRequestService;
|
private $curlRequestService;
|
||||||
private $httpClient;
|
private $httpClient;
|
||||||
private $params;
|
private $params;
|
||||||
|
private $tftpbootDir;
|
||||||
public function __construct(CurlRequestService $curlRequestService, LoggerInterface $logger, HttpClientInterface $httpClient, ParameterBagInterface $params)
|
public function __construct(CurlRequestService $curlRequestService, LoggerInterface $logger, HttpClientInterface $httpClient, ParameterBagInterface $params)
|
||||||
{
|
{
|
||||||
$this->curlRequestService = $curlRequestService;
|
$this->curlRequestService = $curlRequestService;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->httpClient = $httpClient;
|
$this->httpClient = $httpClient;
|
||||||
$this->params = $params; // Accedemos a las variables de entorno a través de ParameterBagInterface
|
$this->params = $params; // Accedemos a las variables de entorno a través de ParameterBagInterface
|
||||||
|
$this->tftpbootDir = $params->get('tftpboot_dir');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Tabla de Contenido
|
/*Tabla de Contenido
|
||||||
|
@ -770,8 +772,8 @@ public function uninstallOglive(string $checksum): Response
|
||||||
*/
|
*/
|
||||||
public function getBootFiles(): JsonResponse
|
public function getBootFiles(): JsonResponse
|
||||||
{
|
{
|
||||||
$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
#$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
||||||
|
$directory = $this->tftpbootDir . '/ipxe_scripts';
|
||||||
// Verificar si el directorio existe
|
// Verificar si el directorio existe
|
||||||
if (!is_dir($directory)) {
|
if (!is_dir($directory)) {
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
|
@ -872,8 +874,8 @@ public function getBootFiles(): JsonResponse
|
||||||
public function getBootFile(string $mac): Response
|
public function getBootFile(string $mac): Response
|
||||||
{
|
{
|
||||||
// Ruta donde están alojados los archivos de arranque
|
// Ruta donde están alojados los archivos de arranque
|
||||||
$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
#$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
||||||
|
$directory = $this->tftpbootDir . '/ipxe_scripts';
|
||||||
// Generar el nombre del archivo basado en la dirección MAC
|
// Generar el nombre del archivo basado en la dirección MAC
|
||||||
$mac = $this->validateAndFormatMac($mac ?? null);
|
$mac = $this->validateAndFormatMac($mac ?? null);
|
||||||
$fileName = "01-" . $mac;
|
$fileName = "01-" . $mac;
|
||||||
|
@ -1079,7 +1081,8 @@ public function createBootFile(Request $request): JsonResponse
|
||||||
'resolution' => $data['resolution'] ?? '788'
|
'resolution' => $data['resolution'] ?? '788'
|
||||||
];
|
];
|
||||||
|
|
||||||
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
||||||
|
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
|
||||||
$templatePath = $templateDir . '/' . $templateName;
|
$templatePath = $templateDir . '/' . $templateName;
|
||||||
|
|
||||||
// Verificar si la plantilla existe
|
// Verificar si la plantilla existe
|
||||||
|
@ -1119,8 +1122,8 @@ public function createBootFile(Request $request): JsonResponse
|
||||||
$pxeFileName = '01-' . $mac;
|
$pxeFileName = '01-' . $mac;
|
||||||
|
|
||||||
// Ruta para guardar el archivo PXE
|
// Ruta para guardar el archivo PXE
|
||||||
$pxeFilePath = '/opt/ogboot/tftpboot/ipxe_scripts/' . $pxeFileName;
|
#$pxeFilePath = '/opt/ogboot/tftpboot/ipxe_scripts/' . $pxeFileName;
|
||||||
|
$pxeFilePath = $this->tftpbootDir . '/ipxe_scripts' . $pxeFileName;
|
||||||
// Crear el archivo PXE
|
// Crear el archivo PXE
|
||||||
if (file_put_contents($pxeFilePath, $pxeContent) === false) {
|
if (file_put_contents($pxeFilePath, $pxeContent) === false) {
|
||||||
return new JsonResponse(['error' => 'Failed to create PXE boot file'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
return new JsonResponse(['error' => 'Failed to create PXE boot file'], Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
@ -1196,8 +1199,8 @@ function validateAndFormatMac($mac)
|
||||||
*/
|
*/
|
||||||
public function deleteBootFile(string $mac): Response
|
public function deleteBootFile(string $mac): Response
|
||||||
{
|
{
|
||||||
$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
#$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
|
||||||
|
$directory = $this->tftpbootDir . '/ipxe_scripts';
|
||||||
// Validar y formatear la dirección MAC
|
// Validar y formatear la dirección MAC
|
||||||
$mac = $this->validateAndFormatMac($mac ?? null);
|
$mac = $this->validateAndFormatMac($mac ?? null);
|
||||||
$fileName = "01-" . $mac;
|
$fileName = "01-" . $mac;
|
||||||
|
@ -1258,8 +1261,8 @@ public function deleteBootFile(string $mac): Response
|
||||||
*/
|
*/
|
||||||
public function getAllTemplates(): JsonResponse
|
public function getAllTemplates(): JsonResponse
|
||||||
{
|
{
|
||||||
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
||||||
|
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
|
||||||
// Verificar si el directorio existe
|
// Verificar si el directorio existe
|
||||||
if (!is_dir($templateDir)) {
|
if (!is_dir($templateDir)) {
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
|
@ -1326,7 +1329,8 @@ public function getAllTemplates(): JsonResponse
|
||||||
|
|
||||||
public function getTemplate(string $templateName): Response
|
public function getTemplate(string $templateName): Response
|
||||||
{
|
{
|
||||||
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
||||||
|
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
|
||||||
$filePath = "$templateDir/$templateName";
|
$filePath = "$templateDir/$templateName";
|
||||||
|
|
||||||
// Comprobar si el archivo de plantilla existe
|
// Comprobar si el archivo de plantilla existe
|
||||||
|
@ -1399,8 +1403,8 @@ public function createTemplate(Request $request)
|
||||||
|
|
||||||
$nameTemplate = $data['name_template'];
|
$nameTemplate = $data['name_template'];
|
||||||
$contentTemplate = $data['content_template'];
|
$contentTemplate = $data['content_template'];
|
||||||
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
||||||
|
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
|
||||||
// Validar el nombre de la plantilla
|
// Validar el nombre de la plantilla
|
||||||
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $nameTemplate)) {
|
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $nameTemplate)) {
|
||||||
return new Response('Nombre de la plantilla no válido.', 400);
|
return new Response('Nombre de la plantilla no válido.', 400);
|
||||||
|
@ -1481,7 +1485,8 @@ public function createTemplate(Request $request)
|
||||||
*/
|
*/
|
||||||
public function deleteTemplate($name): Response
|
public function deleteTemplate($name): Response
|
||||||
{
|
{
|
||||||
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
|
||||||
|
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
|
||||||
$filePath = $templateDir . '/' . $name;
|
$filePath = $templateDir . '/' . $name;
|
||||||
|
|
||||||
// Comprobar si la plantilla existe
|
// Comprobar si la plantilla existe
|
||||||
|
|
Loading…
Reference in New Issue