refs #2092 adds new parameter bootfilename to create and update host
ogdhcp/pipeline/head There was a failure building this commit Details

tls
Luis Gerardo Romero Garcia 2025-05-27 09:49:07 +02:00
parent 271bcbb05d
commit 3fe53d35fd
1 changed files with 20 additions and 3 deletions

View File

@ -1382,6 +1382,8 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse
$host = htmlspecialchars($input->host); $host = htmlspecialchars($input->host);
$macAddress = htmlspecialchars($input->macAddress); $macAddress = htmlspecialchars($input->macAddress);
$address = htmlspecialchars($input->address); $address = htmlspecialchars($input->address);
// $bootFileName= htmlspecialchars($input->bootFileName);
$bootFileName = isset($input->bootFileName) ? htmlspecialchars($input->bootFileName) : null;
} catch (Exception $e) { } catch (Exception $e) {
$errorText = $e->getMessage(); $errorText = $e->getMessage();
$this->logger->error(json_encode([ $this->logger->error(json_encode([
@ -1406,7 +1408,8 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse
$newHost = [ $newHost = [
"hostname" => $host, "hostname" => $host,
"hw-address" => $macAddress, "hw-address" => $macAddress,
"ip-address" => $address "ip-address" => $address,
"boot-file-name" => $bootFileName
]; ];
$subnetFound = false; $subnetFound = false;
@ -1415,7 +1418,12 @@ public function addDhcpHost(Request $request, $subnetId): JsonResponse
if ($subnet['id'] == $subnetId) { if ($subnet['id'] == $subnetId) {
$subnetFound = true; $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']; $newHost['boot-file-name'] = $subnet['boot-file-name'];
} }
if (isset($subnet['next-server'])) { if (isset($subnet['next-server'])) {
@ -1862,6 +1870,8 @@ public function updateDhcpHost(Request $request, $subnetId): JsonResponse
$oldMacAddress = htmlspecialchars($input->oldMacAddress); $oldMacAddress = htmlspecialchars($input->oldMacAddress);
$macAddress = htmlspecialchars($input->macAddress); $macAddress = htmlspecialchars($input->macAddress);
$address = htmlspecialchars($input->address); $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) { } catch (Exception $e) {
$errorText = $e->getMessage(); $errorText = $e->getMessage();
$this->logger->error(json_encode([ $this->logger->error(json_encode([
@ -1898,7 +1908,14 @@ public function updateDhcpHost(Request $request, $subnetId): JsonResponse
if ($reservation['hw-address'] == $oldMacAddress) { if ($reservation['hw-address'] == $oldMacAddress) {
$hostFound = true; $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; $nextServer = $reservation['next-server'] ?? $subnet['next-server'] ?? null;
$reservation['hw-address'] = $macAddress; $reservation['hw-address'] = $macAddress;