diff --git a/src/DhcpBundle/Controller/DhcpController.php b/src/DhcpBundle/Controller/DhcpController.php index c5b498f..525835d 100644 --- a/src/DhcpBundle/Controller/DhcpController.php +++ b/src/DhcpBundle/Controller/DhcpController.php @@ -173,8 +173,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Configuración cargada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Configuración cargada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error kea configuration invalid: " . $responseTest[0]["text"]; @@ -253,8 +259,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Subred eliminada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Subred eliminada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error kea configuration invalid: " . $responseTest[0]["text"]; @@ -360,8 +372,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Subred modificada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Subred modificada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error kea configuration invalid: " . $responseTest[0]["text"]; @@ -558,8 +576,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Configuración cargada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Configuración cargada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error kea configuration invalid: " . $responseTest[0]["text"]; @@ -652,8 +676,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Configuración cargada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Configuración cargada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseTest[0]["text"]; @@ -768,8 +798,14 @@ class DhcpController $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseSet[0]["text"]; return new JsonResponse(['error' => $responseError], 400); } else { - $responseSuccess = "Configuración cargada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Configuración cargada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } else { $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseTest[0]["text"]; @@ -806,7 +842,6 @@ class DhcpController $backup_file = reset($backup_files); $config = file_get_contents($backup_file); $configuration = json_decode($config); - $test_command = 'config-test'; $test_output = $this->curlKeaService->executeCurlCommand($test_command, $configuration); if ($test_output == false || $test_output[0]["result"] != 0) { @@ -817,11 +852,17 @@ class DhcpController $set_output = $this->curlKeaService->executeCurlCommand($set_command, $configuration, false); if ($set_output == false || $set_output[0]["result"] != 0) { $responseError = "Error al guardar la última configuración de Kea: " . $set_output[0]["text"]; - return new JsonResponse(['error' => $responseError], 400); + return new JsonResponse(['error' => $responseError], 400); } else { unlink($backup_file); - $responseSuccess = "última configuración cargada correctamente"; - return new JsonResponse(['success' => $responseSuccess], 200); + $responseWrite = $this->curlKeaService->executeCurlCommand('config-write', $configuration); + if ($responseWrite == false || $responseWrite[0]["result"] != 0) { + $responseError = "Error al guardar la configuración en Kea DHCP: " . $responseWrite[0]["text"]; + return new JsonResponse(['error' => $responseError], 400); + } else { + $responseSuccess = "Configuración cargada correctamente"; + return new JsonResponse(['success' => $responseSuccess], 200); + } } } }