|
@@ -2,38 +2,41 @@
|
|
|
|
|
|
namespace KeaBundle\Services;
|
|
|
|
|
|
-use KeaBundle\Interfaces\KeaConfigInterface;
|
|
|
+use Doctrine\ORM\EntityManager;
|
|
|
+use Doctrine\ORM\EntityRepository;
|
|
|
use DHCPBundle\Entity\DHCP;
|
|
|
+use KeaBundle\Interfaces\KeaConfigInterface;
|
|
|
+use WebserviceBundle\Services\Webservice;
|
|
|
|
|
|
class KeaConfigService
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
- * @var Repository
|
|
|
+ * @var EntityRepository
|
|
|
*/
|
|
|
private $dhcpRepository;
|
|
|
|
|
|
/**
|
|
|
- * @var Repository
|
|
|
+ * @var EntityRepository
|
|
|
*/
|
|
|
private $subnetRepository;
|
|
|
|
|
|
/**
|
|
|
- * @var Repository
|
|
|
+ * @var EntityRepository
|
|
|
*/
|
|
|
private $hostRepository;
|
|
|
|
|
|
/**
|
|
|
- * @var Service
|
|
|
+ * @var Webservice
|
|
|
*/
|
|
|
private $webService;
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
+ * @param Webservice $ws
|
|
|
* @param EntityManager $em
|
|
|
*/
|
|
|
- public function __construct($ws, $em)
|
|
|
+ public function __construct(Webservice $ws, EntityManager $em)
|
|
|
{
|
|
|
$this->dhcpRepository = $em->getRepository('DHCPBundle:DHCP');
|
|
|
$this->subnetRepository = $em->getRepository('IPv4Bundle:SubNet');
|
|
@@ -70,62 +73,71 @@ class KeaConfigService
|
|
|
|
|
|
/**
|
|
|
* @param DHCP $dhcp
|
|
|
+ * @param string $service
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function getRemoteConfig(DHCP $dhcp, $service = null)
|
|
|
+ public function getRemoteConfig(DHCP $dhcp, $service = "dhcp4")
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
- if(is_null($host)) $host = "kea:8080";
|
|
|
+ if (is_null($host)) $host = "kea:8080";
|
|
|
|
|
|
- $_params = array("command" => "config-get", "service" => array("dhcp4"));
|
|
|
+ $_params = array(
|
|
|
+ "command" => "config-get",
|
|
|
+ "service" => array($service),
|
|
|
+ );
|
|
|
|
|
|
$params = json_encode($_params);
|
|
|
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param DHCP $dhcp
|
|
|
+ * @param string $service
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function reloadConfig(DHCP $dhcp, $service = null)
|
|
|
+ public function reloadConfig(DHCP $dhcp, $service = "dhcp4")
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
if(is_null($host)) $host = "kea:8080";
|
|
|
|
|
|
- $_params = array("command" => "config-reload", "service" => array("dhcp4"));
|
|
|
+ $_params = array(
|
|
|
+ "command" => "config-reload",
|
|
|
+ "service" => array($service),
|
|
|
+ );
|
|
|
|
|
|
$params = json_encode($_params);
|
|
|
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param DHCP $dhcp
|
|
|
+ * @param string $service
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
- public function reloadHook(DHCP $dhcp, $service = null)
|
|
|
+ public function reloadHook(DHCP $dhcp, $service = "dhcp4")
|
|
|
{
|
|
|
$host = $dhcp->getHost();
|
|
|
if(is_null($host)) $host = "kea:8080";
|
|
|
|
|
|
- $_params = array("command" => "libreload", "service" => array("dhcp4"));
|
|
|
+ $_params = array(
|
|
|
+ "command" => "libreload",
|
|
|
+ "service" => array($service),
|
|
|
+ );
|
|
|
|
|
|
$params = json_encode($_params);
|
|
|
|
|
|
$config = $this->curlPost($host, $params);
|
|
|
|
|
|
return $config;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -143,7 +155,10 @@ class KeaConfigService
|
|
|
$json = json_encode($_params);
|
|
|
|
|
|
if(isset($_params[0]) && isset($_params[0]['arguments'])) {
|
|
|
- $_params = array("command" => "config-set", "service" => array("dhcp4"), "arguments" => $_params[0]['arguments']);
|
|
|
+ $_params = array(
|
|
|
+ "command" => "config-set",
|
|
|
+ "service" => array("dhcp4"),
|
|
|
+ "arguments" => $_params[0]['arguments']);
|
|
|
} else {
|
|
|
return json_encode(array("error" => "Config Error. Check template DHCP"));
|
|
|
}
|
|
@@ -151,9 +166,14 @@ class KeaConfigService
|
|
|
$config = $this->curlPost($host, json_encode($_params));
|
|
|
|
|
|
return $config;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param string $host
|
|
|
+ * @param array $params
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
private function curlPost($host, $params)
|
|
|
{
|
|
|
$ch = curl_init();
|
|
@@ -167,12 +187,10 @@ class KeaConfigService
|
|
|
try {
|
|
|
$return = curl_exec($ch);
|
|
|
} catch (\Exception $ex) {
|
|
|
- // $ex->getMessage()
|
|
|
return json_encode(array("error" => "Kea Connection Error."));
|
|
|
}
|
|
|
|
|
|
return $return;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|