|
@@ -2,14 +2,27 @@
|
|
|
|
|
|
namespace KeaBundle\Services;
|
|
|
|
|
|
+use IPv4Bundle\Entity\Host;
|
|
|
+
|
|
|
class BaseKea
|
|
|
{
|
|
|
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
public $subnet4 = [];
|
|
|
|
|
|
+ /**
|
|
|
+ * @var array
|
|
|
+ */
|
|
|
+ public $hooks_libraries = [];
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @param array $data
|
|
|
+ * @param boolean $logging
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function getConfig($data = array(), $logging = false)
|
|
|
{
|
|
@@ -17,9 +30,16 @@ class BaseKea
|
|
|
$this->subnetConfig($data['subnets']);
|
|
|
}
|
|
|
|
|
|
+ if (isset($data['dhcp']) && isset($data['library'])) {
|
|
|
+ $this->hooksLibrariesConfig($data);
|
|
|
+ }
|
|
|
+
|
|
|
return json_encode([
|
|
|
- 'Dhcp4' => $this,
|
|
|
- 'Logging' => $this->loggingConfig()
|
|
|
+ 'Dhcp4' => [
|
|
|
+ 'subnet4' => $this->subnet4,
|
|
|
+ 'hooks-libraries' => $this->hooks_libraries,
|
|
|
+ ],
|
|
|
+ 'Logging' => $this->loggingConfig(),
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -42,6 +62,56 @@ class BaseKea
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ private function hooksLibrariesConfig($data)
|
|
|
+ {
|
|
|
+ $dhcp = $data['dhcp'];
|
|
|
+ $hosts = $data['hosts'];
|
|
|
+
|
|
|
+ $hook = [
|
|
|
+ 'library' => $data['library'],
|
|
|
+ ];
|
|
|
+
|
|
|
+ $dhcpModelParams = $dhcp->getDhcpModel()->getData('parameters');
|
|
|
+
|
|
|
+ $option122 = isset($dhcpModelParams['option122']) ? $dhcpModelParams['option122'] : null;
|
|
|
+ $ip = isset($dhcpModelParams['ip']) ? $dhcpModelParams['ip'] : null;
|
|
|
+ if ($option122 && $ip) {
|
|
|
+ $macs = [];
|
|
|
+ foreach ($hosts as $host) {
|
|
|
+ $macs[] = $host->getMac();
|
|
|
+ }
|
|
|
+
|
|
|
+ $hook['parameters']['option122'] = [
|
|
|
+ $ip => $macs
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $remote_id_map = isset($dhcpModelParams['remote-id-map']) ? $dhcpModelParams['remote-id-map'] : null;
|
|
|
+ if ($remote_id_map) {
|
|
|
+ $active = [];
|
|
|
+ $suspended = [];
|
|
|
+ foreach ($hosts as $host) {
|
|
|
+ $mac = $host->getMac();
|
|
|
+ $state = $host->getState();
|
|
|
+ if ($state == Host::STATE_ACTIVE) {
|
|
|
+ $active[] = $mac;
|
|
|
+ } elseif ($state == Host::STATE_SUSPENDED) {
|
|
|
+ $suspended[] = $mac;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $hook['parameters']['remote-id-map'] = [
|
|
|
+ 'active' => $active,
|
|
|
+ 'suspended' => $suspended,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->hooks_libraries[] = $hook;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @return string
|
|
|
*/
|