parent
f5a4a1fc83
commit
925274da3e
|
@ -17,7 +17,7 @@ class DhcpController
|
|||
{
|
||||
private $logger;
|
||||
/**
|
||||
* @OA\Info(title="My API", version="1.0")
|
||||
* @OA\Info(title="Ogdhcp API", version="1.0")
|
||||
*/
|
||||
|
||||
private $curlKeaService;
|
||||
|
@ -28,65 +28,6 @@ class DhcpController
|
|||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/opengnsys3/rest/dhcp", methods={"GET"})
|
||||
*/
|
||||
public function getAllDhcp(): JsonResponse
|
||||
{
|
||||
$response = $this->curlKeaService->executeCurlCommand('config-get');
|
||||
return new JsonResponse($response);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ...
|
||||
|
||||
/**
|
||||
* @Route("/opengnsys3/rest/dhcp/save", methods={"POST"})
|
||||
*/
|
||||
public function saveDhcpConfiguration(Request $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$input = json_decode($request->getContent());
|
||||
$configurationText = htmlspecialchars($input->configurationText);
|
||||
} catch (Exception $e) {
|
||||
$response["message"] = $e->getMessage();
|
||||
return new JsonResponse(['error' => $response], 400);
|
||||
}
|
||||
|
||||
$configurationParsed = str_replace(' ', '', $configurationText);
|
||||
$configurationParsed = str_replace("\n", '', $configurationParsed);
|
||||
$configurationParsed = str_replace('"', '"', $configurationParsed);
|
||||
$configuration = json_decode($configurationParsed);
|
||||
|
||||
if ($configuration === null || json_last_error() !== JSON_ERROR_NONE) {
|
||||
$responseError = "Error: El texto proporcionado no es un JSON válido.";
|
||||
return new JsonResponse(['error' => $responseError], 400);
|
||||
} else {
|
||||
try {
|
||||
$responseTest = $this->curlKeaService->executeCurlCommand('config-test', $configuration);
|
||||
if ($responseTest[0]["result"] == 0) {
|
||||
$responseSet = $this->curlKeaService->executeCurlCommand('config-set', $configuration);
|
||||
if ($responseSet == false || $responseSet[0]["result"] != 0) {
|
||||
$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);
|
||||
}
|
||||
} else {
|
||||
$responseError = "Error al guardar la configuración en Kea DHCP: " . $responseTest[0]["text"];
|
||||
return new JsonResponse(['error' => $responseError], 400);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$responseError = "Error al obtener la configuración de Kea DHCP: " . $e->getMessage();
|
||||
return new JsonResponse(['error' => $responseError], 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @OA\Schema(
|
||||
|
@ -150,7 +91,7 @@ class DhcpController
|
|||
|
||||
/**
|
||||
* @OA\Post(
|
||||
* path="/opengnsys3/rest/dhcp/subnet",
|
||||
* path="/opengnsys3/rest/dhcp/subnets",
|
||||
* summary="Add a new DHCP subnet",
|
||||
* @OA\RequestBody(
|
||||
* description="JSON payload",
|
||||
|
@ -181,7 +122,7 @@ class DhcpController
|
|||
* )
|
||||
* )
|
||||
* )
|
||||
* @Route("/opengnsys3/rest/dhcp/subnet", methods={"POST"})
|
||||
* @Route("/opengnsys3/rest/dhcp/subnets", methods={"POST"})
|
||||
*/
|
||||
public function addDhcpSubnet(Request $request): JsonResponse
|
||||
{
|
||||
|
@ -249,9 +190,9 @@ class DhcpController
|
|||
|
||||
|
||||
/**
|
||||
* @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}", methods={"DELETE"})
|
||||
* @Route("/opengnsys3/rest/dhcp/subnets/{subnetId}", methods={"DELETE"})
|
||||
* @OA\Delete(
|
||||
* path="/opengnsys3/rest/dhcp/subnet/{subnetId}",
|
||||
* path="/opengnsys3/rest/dhcp/subnets/{subnetId}",
|
||||
* summary="Delete a DHCP subnet",
|
||||
* @OA\Parameter(
|
||||
* name="subnetId",
|
||||
|
@ -279,7 +220,7 @@ class DhcpController
|
|||
* )
|
||||
* )
|
||||
* )
|
||||
* @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}", methods={"DELETE"})
|
||||
* @Route("/opengnsys3/rest/dhcp/subnets/{subnetId}", methods={"DELETE"})
|
||||
*/
|
||||
public function deleteDhcpSubnet(Request $request): JsonResponse
|
||||
{
|
||||
|
@ -328,9 +269,9 @@ class DhcpController
|
|||
|
||||
|
||||
/**
|
||||
* @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}", methods={"PUT"})
|
||||
* @Route("/opengnsys3/rest/dhcp/subnets/{subnetId}", methods={"PUT"})
|
||||
* @OA\Put(
|
||||
* path="/opengnsys3/rest/dhcp/subnet/{subnetId}",
|
||||
* path="/opengnsys3/rest/dhcp/subnets/{subnetId}",
|
||||
* summary="Modify a DHCP subnet",
|
||||
* @OA\Parameter(
|
||||
* name="subnetId",
|
||||
|
@ -369,7 +310,7 @@ class DhcpController
|
|||
* )
|
||||
* )
|
||||
* )
|
||||
* @Route("/opengnsys3/rest/dhcp/subnet/{subnetId}", methods={"PUT"})
|
||||
* @Route("/opengnsys3/rest/dhcp/subnets/{subnetId}", methods={"PUT"})
|
||||
*/
|
||||
public function modifyDhcpSubnet(Request $request): JsonResponse
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue