mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-16 17:44:41 +00:00
Services: Kea DHCP: Kea DHCPv4 - Add Custom Options tab to assign "vendor-encapsulated-options-space" options to subnets, for https://github.com/opnsense/core/pull/7361
This commit is contained in:
parent
8f6499e33d
commit
3f184a695f
1
plist
1
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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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>Code</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>
|
||||
@ -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'][] = [
|
||||
|
||||
@ -158,5 +158,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">
|
||||
@ -176,6 +186,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._('Code') }}</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">
|
||||
@ -220,3 +256,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…
x
Reference in New Issue
Block a user