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

pull/5/head
Qindel 2024-10-22 08:01:47 +00:00
parent 1e406be464
commit 943467a8ad
3 changed files with 51 additions and 45 deletions

View File

@ -4,7 +4,7 @@
# 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
parameters:
tftpboot_dir: '%kernel.project_dir%/tftpboot'
services:
# default configuration for services in *this* file
_defaults:

View File

@ -232,37 +232,37 @@ def og_boot_create_dirs():
exit(1)
def og_boot_symfony_install():
global INSTALL_OGBOOT_TARGET
logger.info("Creating Symfony application skeleton...")
global INSTALL_OGBOOT_TARGET
logger.info("Creating Symfony application skeleton...")
try:
try:
# Copiar los archivos .env y composer.json primero
env_src = os.path.join(f"{REPO_DIR}", ".env")
composer_src = os.path.join(f"{REPO_DIR}", "composer.json")
env_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", ".env")
composer_dest = os.path.join(f"{INSTALL_OGBOOT_TARGET}", "composer.json")
shutil.copy(env_src, env_dest)
shutil.copy(composer_src, composer_dest)
logger.info(f"Copied environment source {env_src} to {env_dest}")
logger.info(f"Copied composer source {composer_src} to {composer_dest}")
shutil.copy(env_src, env_dest)
shutil.copy(composer_src, composer_dest)
logger.info(f"Copied environment source {env_src} to {env_dest}")
logger.info(f"Copied composer source {composer_src} to {composer_dest}")
# Cambiar permisos y propietario de los archivos copiados
os.chmod(env_dest, 0o644)
os.chmod(composer_dest, 0o644)
shutil.chown(env_dest, user='ogboot', group='ogboot')
shutil.chown(composer_dest, user='ogboot', group='ogboot')
logger.info(f"Set permissions and owner for {env_dest} and {composer_dest}")
# Cambiar permisos y propietario de los archivos copiados
os.chmod(env_dest, 0o644)
os.chmod(composer_dest, 0o644)
shutil.chown(env_dest, user='ogboot', group='ogboot')
shutil.chown(composer_dest, user='ogboot', group='ogboot')
logger.info(f"Set permissions and owner for {env_dest} and {composer_dest}")
# Añadir la línea OGCORE_API_URL utilizando OGCORE_IP
ogcore_api_url = f'OGCORE_API_URL="https://{OGCORE_IP}"'
with open(env_dest, 'a') as env_file:
env_file.write(f"\n{ogcore_api_url}\n")
logger.info(f"Added OGCORE_API_URL to {env_dest} with IP: {OGCORE_IP}")
# Añadir la línea OGCORE_API_URL utilizando OGCORE_IP
ogcore_api_url = f'OGCORE_API_URL="https://{OGCORE_IP}"'
with open(env_dest, 'a') as env_file:
env_file.write(f"\n{ogcore_api_url}\n")
logger.info(f"Added OGCORE_API_URL to {env_dest} with IP: {OGCORE_IP}")
except Exception as e:
logger.error(f"An error occurred while copying files or modifying .env: {e}")
raise
except Exception as e:
logger.error(f"An error occurred while copying files or modifying .env: {e}")
raise
@ -904,12 +904,12 @@ except Exception as e:
logger.error(f"Error configuring php fpm: {e}")
exit(1)
try:
logger.info("Configuring ogCore")
tzConfigure()
except Exception as e:
logger.error(f"Error configuring ogCore: {e}")
exit(1)
#try:
# logger.info("Configuring ogCore")
# tzConfigure()
#except Exception as e:
# logger.error(f"Error configuring ogCore: {e}")
# exit(1)
try:
logger.info("Configuring Samba")
@ -922,3 +922,4 @@ logger.info(f"ogBoot installation finished.")
logging.shutdown()
console_handler.close()

View File

@ -27,12 +27,14 @@ class OgBootController
private $curlRequestService;
private $httpClient;
private $params;
private $tftpbootDir;
public function __construct(CurlRequestService $curlRequestService, LoggerInterface $logger, HttpClientInterface $httpClient, ParameterBagInterface $params)
{
$this->curlRequestService = $curlRequestService;
$this->logger = $logger;
$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
@ -770,8 +772,8 @@ public function uninstallOglive(string $checksum): Response
*/
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
if (!is_dir($directory)) {
return new JsonResponse(
@ -872,8 +874,8 @@ public function getBootFiles(): JsonResponse
public function getBootFile(string $mac): Response
{
// 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
$mac = $this->validateAndFormatMac($mac ?? null);
$fileName = "01-" . $mac;
@ -1079,7 +1081,8 @@ public function createBootFile(Request $request): JsonResponse
'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;
// Verificar si la plantilla existe
@ -1119,8 +1122,8 @@ public function createBootFile(Request $request): JsonResponse
$pxeFileName = '01-' . $mac;
// 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
if (file_put_contents($pxeFilePath, $pxeContent) === false) {
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
{
$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
#$directory = '/opt/ogboot/tftpboot/ipxe_scripts';
$directory = $this->tftpbootDir . '/ipxe_scripts';
// Validar y formatear la dirección MAC
$mac = $this->validateAndFormatMac($mac ?? null);
$fileName = "01-" . $mac;
@ -1258,8 +1261,8 @@ public function deleteBootFile(string $mac): Response
*/
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
if (!is_dir($templateDir)) {
return new JsonResponse(
@ -1326,7 +1329,8 @@ public function getAllTemplates(): JsonResponse
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";
// Comprobar si el archivo de plantilla existe
@ -1399,8 +1403,8 @@ public function createTemplate(Request $request)
$nameTemplate = $data['name_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
if (!preg_match('/^[a-zA-Z0-9._-]+$/', $nameTemplate)) {
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
{
$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
#$templateDir = '/opt/ogboot/tftpboot/ipxe_scripts/templates';
$templateDir = $this->tftpbootDir . '/ipxe_scripts/templates';
$filePath = $templateDir . '/' . $name;
// Comprobar si la plantilla existe