From 3fe53d35fd0a82a443723e2860aa44ea340a53ea Mon Sep 17 00:00:00 2001 From: lgromero Date: Tue, 27 May 2025 09:49:07 +0200 Subject: [PATCH] refs #2092 adds new parameter bootfilename to create and update host --- .../DhcpBundle/Controller/DhcpController.php | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/api/src/DhcpBundle/Controller/DhcpController.php b/api/src/DhcpBundle/Controller/DhcpController.php index a65e318..79e36a9 100644 --- a/api/src/DhcpBundle/Controller/DhcpController.php +++ b/api/src/DhcpBundle/Controller/DhcpController.php @@ -1382,6 +1382,8 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse $host = htmlspecialchars($input->host); $macAddress = htmlspecialchars($input->macAddress); $address = htmlspecialchars($input->address); + // $bootFileName= htmlspecialchars($input->bootFileName); + $bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null; } catch (Exception $e) { $errorText = $e->getMessage(); $this->logger->error(json_encode([ @@ -1406,7 +1408,8 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse $newHost = [ "hostname" => $host, "hw-address" => $macAddress, - "ip-address" => $address + "ip-address" => $address, + "boot-file-name" => $bootFileName ]; $subnetFound = false; @@ -1415,7 +1418,12 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse if ($subnet['id'] == $subnetId) { $subnetFound = true; - if (isset($subnet['boot-file-name'])) { + // Si la subred tiene boot-file-name, lo añadimos a la reserva + // Si hemos recibido bootFileName como parámetro de entrada, lo asignamos al host. + if (!empty($bootFileName)) { + $newHost['boot-file-name'] = $bootFileName; + } elseif (isset($subnet['boot-file-name'])) { + // Si no, usamos el de la subred si existe. $newHost['boot-file-name'] = $subnet['boot-file-name']; } if (isset($subnet['next-server'])) { @@ -1862,6 +1870,8 @@ public function updateDhcpHost(Request $request, $subnetId): JsonResponse $oldMacAddress = htmlspecialchars($input->oldMacAddress); $macAddress = htmlspecialchars($input->macAddress); $address = htmlspecialchars($input->address); + //Verifica si el campo bootFileName está presente, si no, lo deja como null + $bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null; } catch (Exception $e) { $errorText = $e->getMessage(); $this->logger->error(json_encode([ @@ -1898,7 +1908,14 @@ public function updateDhcpHost(Request $request, $subnetId): JsonResponse if ($reservation['hw-address'] == $oldMacAddress) { $hostFound = true; - $bootFileName = $reservation['boot-file-name'] ?? $subnet['boot-file-name'] ?? null; + // Si nos llega bootFileName en el input, lo usamos; si no, asignamos el tenga la subred + if ($bootFileName !== null) { + $reservation['boot-file-name'] = $bootFileName; + } elseif (isset($subnet['boot-file-name'])) { + $bootFileName = $subnet['boot-file-name']; + } else { + $bootFileName = null; + } $nextServer = $reservation['next-server'] ?? $subnet['next-server'] ?? null; $reservation['hw-address'] = $macAddress;