diff --git a/plist b/plist index 89b8f38ed..ae87156fc 100644 --- a/plist +++ b/plist @@ -392,6 +392,7 @@ /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/Api/ServiceController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/DhcpController.php /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/forms/agentSettings.xml +/usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogPeer4.xml /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogReservation4.xml /usr/local/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogSubnet4.xml diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Kea/Api/Dhcpv4Controller.php b/src/opnsense/mvc/app/controllers/OPNsense/Kea/Api/Dhcpv4Controller.php index ee9a15420..43f23bbde 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Kea/Api/Dhcpv4Controller.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Kea/Api/Dhcpv4Controller.php @@ -54,7 +54,7 @@ class Dhcpv4Controller extends ApiMutableModelControllerBase public function searchSubnetAction() { - return $this->searchBase("subnets.subnet4", ['subnet'], "subnet"); + return $this->searchBase("subnets.subnet4", null, "subnet"); } public function setSubnetAction($uuid) @@ -79,11 +79,7 @@ class Dhcpv4Controller extends ApiMutableModelControllerBase public function searchReservationAction() { - return $this->searchBase( - "reservations.reservation", - ['subnet', 'ip_address', 'hw_address', 'hostname', 'description'], - "hw_address" - ); + return $this->searchBase("reservations.reservation", null, "hw_address"); } public function setReservationAction($uuid) @@ -144,7 +140,7 @@ class Dhcpv4Controller extends ApiMutableModelControllerBase public function searchPeerAction() { - return $this->searchBase("ha_peers.peer", ['name', 'role'], "name"); + return $this->searchBase("ha_peers.peer", null, "name"); } public function setPeerAction($uuid) @@ -166,4 +162,29 @@ class Dhcpv4Controller extends ApiMutableModelControllerBase { return $this->delBase("ha_peers.peer", $uuid); } + + public function searchOptionAction() + { + return $this->searchBase("custom_options.option", null, "name"); + } + + public function setOptionAction($uuid) + { + return $this->setBase("option", "custom_options.option", $uuid); + } + + public function addOptionAction() + { + return $this->addBase("option", "custom_options.option"); + } + + public function getOptionAction($uuid = null) + { + return $this->getBase("option", "custom_options.option", $uuid); + } + + public function delOptionAction($uuid) + { + return $this->delBase("custom_options.option", $uuid); + } } diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Kea/DhcpController.php b/src/opnsense/mvc/app/controllers/OPNsense/Kea/DhcpController.php index c01a11adb..cc33ae94b 100644 --- a/src/opnsense/mvc/app/controllers/OPNsense/Kea/DhcpController.php +++ b/src/opnsense/mvc/app/controllers/OPNsense/Kea/DhcpController.php @@ -53,6 +53,7 @@ class DhcpController extends \OPNsense\Base\IndexController $this->view->formDialogSubnet = $this->getForm("dialogSubnet4"); $this->view->formDialogReservation = $this->getForm("dialogReservation4"); $this->view->formDialogPeer = $this->getForm("dialogPeer4"); + $this->view->formDialogOption = $this->getForm("dialogOption4"); } public function leases4Action() diff --git a/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml b/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml new file mode 100644 index 000000000..b72bfbdde --- /dev/null +++ b/src/opnsense/mvc/app/controllers/OPNsense/Kea/forms/dialogOption4.xml @@ -0,0 +1,39 @@ +
\ No newline at end of file diff --git a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php index 7d908a4c2..3c4330919 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php +++ b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.php @@ -89,6 +89,36 @@ class KeaDhcpv4 extends BaseModel $messages->appendMessage(new Message(gettext("Address not in specified subnet"), $key . ".ip_address")); } } + + foreach ($this->custom_options->option->iterateItems() as $option) { + if (!$option && !$option->isFieldChanged()) { + continue; + } + $key = $option->__reference; + foreach ($this->custom_options->option->iterateItems() as $checkopt) { + if ( + (string)$checkopt->code == (string)$option->code && + (string)$checkopt->space == (string)$option->space + ) { + if ((string)$checkopt->type != (string)$option->type) { + $messages->appendMessage(new Message( + sprintf( + gettext("Unable to redefine code %s, defined as %s in another option."), + $option->code, + $checkopt->type + ), $key . ".type" + )); + } + if ((string)$checkopt->array != (string)$option->array) { + $messages->appendMessage(new Message( + sprintf(gettext("Unable to redefine code %s with different definition"),$option->code), + $key . ".array" + )); + } + } + } + } + return $messages; } @@ -159,6 +189,17 @@ class KeaDhcpv4 extends BaseModel ]; } } + /* custom dhcp options */ + foreach ($this->custom_options->option->iterateItems() as $option) { + if (in_array($subnet_uuid, explode(',', $option->subnet))) { + $record['option-data'][] = [ + "name" => sprintf("%s_%s", $option->space, $option->code), + "code" => (int)((string)$option->code), + "space" => (string)$option->space, + "data" => (string)$option->data + ]; + } + } /* add pools */ foreach (array_filter(explode("\n", $subnet->pools)) as $pool) { $record['pools'][] = ['pool' => $pool]; @@ -211,6 +252,21 @@ class KeaDhcpv4 extends BaseModel 'subnet4' => $this->getConfigSubnets(), ] ]; + $option_def = []; + foreach ($this->custom_options->option->iterateItems() as $option) { + $option_def[sprintf("%s_%s", $option->space, $option->code)] = [ + "name" => sprintf("%s_%s", $option->space, $option->code), + "code" => (int)((string)$option->code), + "type" => (string)$option->type, + "array" => !empty((string)$option->array), + "record-types" => "", + "space" => (string)$option->space, + "encapsulate" => "" + ]; + } + if (!empty($option_def)) { + $cnf['Dhcp4']['option-def'] = array_values($option_def); + } if (!empty((string)(new KeaCtrlAgent())->general->enabled)) { $cnf['Dhcp4']['hooks-libraries'] = []; $cnf['Dhcp4']['hooks-libraries'][] = [ diff --git a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml index 5f2b62d81..4faa34360 100644 --- a/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml +++ b/src/opnsense/mvc/app/models/OPNsense/Kea/KeaDhcpv4.xml @@ -158,5 +158,61 @@ +| {{ lang._('ID') }} | +{{ lang._('Description') }} | +{{ lang._('Code') }} | +{{ lang._('Space') }} | +{{ lang._('Type') }} | +{{ lang._('Data') }} | +{{ lang._('Commands') }} | +
|---|---|---|---|---|---|---|
| + | + + | +