|
@@ -0,0 +1,81 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace KeaBundle\Controller\REST;
|
|
|
+
|
|
|
+use KeaBundle\Form\ConfigType;
|
|
|
+use FOS\RestBundle\Controller\Annotations\RouteResource;
|
|
|
+use WebserviceBundle\Controller\RESTController;
|
|
|
+
|
|
|
+use FOS\RestBundle\Controller\Annotations\Patch;
|
|
|
+use FOS\RestBundle\Controller\Annotations\Get;
|
|
|
+use FOS\RestBundle\Controller\Annotations\View;
|
|
|
+use Symfony\Component\HttpFoundation\Request;
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Config controller.
|
|
|
+ * @RouteResource("Config")
|
|
|
+ */
|
|
|
+class ConfigRESTController extends RESTController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @return string Retorna el nombre de la Entity de trabajo.
|
|
|
+ */
|
|
|
+ public function getRepository()
|
|
|
+ {
|
|
|
+ return 'KeaBundle:Config';
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string Retorna el tipo de la clase.
|
|
|
+ */
|
|
|
+ public function getFormEntityType()
|
|
|
+ {
|
|
|
+ return get_class(new ConfigType());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * GET Route annotation.
|
|
|
+ * @Get("/config/dhcp/{id}/action/{action}")
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @param $action
|
|
|
+ *
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ public function applyAction(Request $request, Int $id, String $action)
|
|
|
+ {
|
|
|
+ $dhcp = $this->get("doctrine.orm.entity_manager")->getRepository("DHCPBundle\Entity\DHCP")->findOneById($id);
|
|
|
+ $translator = $this->get('translator');
|
|
|
+ $keaConfigService = $this->get('kea.config');
|
|
|
+
|
|
|
+ if($action == "help") {
|
|
|
+ return array("help" => array(
|
|
|
+ 'id' => $translator->trans("api.dhcp_id", array(), "KeaBundle"),
|
|
|
+ 'action' => array(
|
|
|
+ 'get' => $translator->trans("api.get_config_help", array(), "KeaBundle"),
|
|
|
+ 'generate' => $translator->trans("api.generate_config_help", array(), "KeaBundle"),
|
|
|
+ 'set' => $translator->trans("api.set_config_help", array(), "KeaBundle")
|
|
|
+ )));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(is_null($dhcp)) {
|
|
|
+ return array("error" => $translator->trans("api.dhcp_not_found", array(), "KeaBundle"));
|
|
|
+ }
|
|
|
+
|
|
|
+ if($action == "get") {
|
|
|
+ $config = $keaConfigService->getRemoteConfig($dhcp);
|
|
|
+ } elseif($action == "generate") {
|
|
|
+ $config = $keaConfigService->getConfig($id);
|
|
|
+ } elseif($action == "set") {
|
|
|
+ $config = $keaConfigService->getConfig($id);
|
|
|
+ $config = $keaConfigService->setConfig($dhcp, $config);
|
|
|
+ } else {
|
|
|
+ return array("error" => $translator->trans("api.config_action_not_found", array(), "KeaBundle"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return json_decode($config,true);
|
|
|
+ }
|
|
|
+}
|