mirror of
https://github.com/opnsense/core.git
synced 2026-02-03 20:39:42 -05:00
Services: Kea DHCP [new]: Kea DHCPv4 - add Custom options tab
Since our efforts to implement https://github.com/opnsense/core/pull/7361 hasn't reached a functional state, lets move the code into a separate branch to keep master clean.
This commit is contained in:
parent
526d747db7
commit
8acdcb3230
7 changed files with 215 additions and 0 deletions
1
plist
1
plist
|
|
@ -419,6 +419,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
|
||||
|
|
|
|||
|
|
@ -160,4 +160,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<form>
|
||||
<field>
|
||||
<id>option.description</id>
|
||||
<label>Description</label>
|
||||
<type>text</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.subnet</id>
|
||||
<label>Subnet</label>
|
||||
<type>select_multiple</type>
|
||||
<help>Subnet this custom option belongs to</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.code</id>
|
||||
<label>DHCP option</label>
|
||||
<type>text</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.space</id>
|
||||
<label>Space</label>
|
||||
<type>dropdown</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.type</id>
|
||||
<label>Type</label>
|
||||
<type>dropdown</type>
|
||||
<help><![CDATA[A <a rel="help" href="https://kea.readthedocs.io/en/latest/arm/dhcp4-srv.html#dhcp-types">DHCP option type</a>.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.array</id>
|
||||
<label>Array</label>
|
||||
<type>checkbox</type>
|
||||
</field>
|
||||
<field>
|
||||
<id>option.data</id>
|
||||
<label>Data</label>
|
||||
<type>text</type>
|
||||
</field>
|
||||
</form>
|
||||
|
|
@ -90,6 +90,36 @@ class KeaDhcpv4 extends BaseModel
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -162,6 +192,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];
|
||||
|
|
@ -215,6 +256,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'][] = [
|
||||
|
|
|
|||
|
|
@ -187,5 +187,61 @@
|
|||
</url>
|
||||
</peer>
|
||||
</ha_peers>
|
||||
<custom_options>
|
||||
<option type="ArrayField">
|
||||
<description type="DescriptionField"/>
|
||||
<code type="IntegerField">
|
||||
<Required>Y</Required>
|
||||
<MinimumValue>0</MinimumValue>
|
||||
<MaximumValue>255</MaximumValue>
|
||||
</code>
|
||||
<space type="OptionField">
|
||||
<Required>Y</Required>
|
||||
<Default>vendor</Default>
|
||||
<OptionValues>
|
||||
<vendor value='vendor-encapsulated-options-space'>vendor-encapsulated-options-space</vendor>
|
||||
</OptionValues>
|
||||
</space>
|
||||
<type type="OptionField">
|
||||
<Required>Y</Required>
|
||||
<OptionValues>
|
||||
<binary>binary</binary>
|
||||
<boolean>boolean</boolean>
|
||||
<fqdn>fqdn</fqdn>
|
||||
<ipv4_address>ipv4-address</ipv4_address>
|
||||
<ipv6_address>ipv6-address</ipv6_address>
|
||||
<ipv6_prefix>ipv6-prefix</ipv6_prefix>
|
||||
<psid>psid</psid>
|
||||
<string>string</string>
|
||||
<tuple>tuple</tuple>
|
||||
<uint8>uint8</uint8>
|
||||
<uint16>uint16</uint16>
|
||||
<uint32>uint32</uint32>
|
||||
<int8>int8</int8>
|
||||
<int16>int16</int16>
|
||||
<int32>int32</int32>
|
||||
</OptionValues>
|
||||
</type>
|
||||
<array type="BooleanField">
|
||||
<Required>Y</Required>
|
||||
<Default>0</Default>
|
||||
</array>
|
||||
<subnet type="ModelRelationField">
|
||||
<Model>
|
||||
<subnets>
|
||||
<source>OPNsense.Kea.KeaDhcpv4</source>
|
||||
<items>subnets.subnet4</items>
|
||||
<display>subnet</display>
|
||||
</subnets>
|
||||
</Model>
|
||||
<ValidationMessage>Related subnet not found</ValidationMessage>
|
||||
<Required>Y</Required>
|
||||
<Multiple>Y</Multiple>
|
||||
</subnet>
|
||||
<data type="TextField">
|
||||
<Required>Y</Required>
|
||||
</data>
|
||||
</option>
|
||||
</custom_options>
|
||||
</items>
|
||||
</model>
|
||||
|
|
|
|||
|
|
@ -69,6 +69,15 @@
|
|||
}
|
||||
);
|
||||
|
||||
$("#grid-options").UIBootgrid(
|
||||
{ search:'/api/kea/dhcpv4/search_option',
|
||||
get:'/api/kea/dhcpv4/get_option/',
|
||||
set:'/api/kea/dhcpv4/set_option/',
|
||||
add:'/api/kea/dhcpv4/add_option/',
|
||||
del:'/api/kea/dhcpv4/del_option/'
|
||||
}
|
||||
);
|
||||
|
||||
$("#reconfigureAct").SimpleActionButton({
|
||||
onPreAction: function() {
|
||||
const dfObj = new $.Deferred();
|
||||
|
|
@ -111,6 +120,7 @@
|
|||
<li class="active"><a data-toggle="tab" href="#settings" id="tab_settings">{{ lang._('Settings') }}</a></li>
|
||||
<li><a data-toggle="tab" href="#subnets" id="tab_pools"> {{ lang._('Subnets') }} </a></li>
|
||||
<li><a data-toggle="tab" href="#reservations" id="tab_reservations"> {{ lang._('Reservations') }} </a></li>
|
||||
<li><a data-toggle="tab" href="#options" id="tab_options"> {{ lang._('Custom Options') }} </a></li>
|
||||
<li><a data-toggle="tab" href="#ha-peers" id="tab_ha-peers"> {{ lang._('HA Peers') }} </a></li>
|
||||
</ul>
|
||||
<div class="tab-content content-box">
|
||||
|
|
@ -177,6 +187,32 @@
|
|||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- Options -->
|
||||
<div id="options" class="tab-pane fade in">
|
||||
<table id="grid-options" class="table table-condensed table-hover table-striped" data-editDialog="DialogOption">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
|
||||
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>
|
||||
<th data-column-id="code" data-type="number">{{ lang._('Option') }}</th>
|
||||
<th data-column-id="space" data-type="string">{{ lang._('Space') }}</th>
|
||||
<th data-column-id="type" data-type="string">{{ lang._('Type') }}</th>
|
||||
<th data-column-id="data" data-type="string">{{ lang._('Data') }}</th>
|
||||
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<button data-action="add" type="button" class="btn btn-xs btn-primary"><span class="fa fa-fw fa-plus"></span></button>
|
||||
</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
<!-- HA - peers -->
|
||||
<div id="ha-peers" class="tab-pane fade in">
|
||||
<table id="grid-ha-peers" class="table table-condensed table-hover table-striped" data-editDialog="DialogPeer" data-editAlert="keaChangeMessage">
|
||||
|
|
@ -223,3 +259,4 @@
|
|||
{{ partial("layout_partials/base_dialog",['fields':formDialogSubnet,'id':'DialogSubnet','label':lang._('Edit Subnet')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogReservation,'id':'DialogReservation','label':lang._('Edit Reservation')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogPeer,'id':'DialogPeer','label':lang._('Edit Peer')])}}
|
||||
{{ partial("layout_partials/base_dialog",['fields':formDialogOption,'id':'DialogOption','label':lang._('Edit Option')])}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue