mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-13 08:09:41 +00:00
dhcp: DHCRelay model migration #6983
It would be nice to have both IPv4 and IPv6 in here but it may be less desirable in practice. For now use a shared namespace and only migrate IPv4 switching the binary and breaking everything in the process.
This commit is contained in:
parent
f673d7f01b
commit
7d80f955de
2
Makefile
2
Makefile
@ -132,6 +132,7 @@ CORE_DEPENDS?= ca_root_nss \
|
||||
choparp \
|
||||
cpustats \
|
||||
dhcp6c \
|
||||
dhcrelay \
|
||||
dnsmasq \
|
||||
dpinger \
|
||||
expiretable \
|
||||
@ -141,7 +142,6 @@ CORE_DEPENDS?= ca_root_nss \
|
||||
hostapd \
|
||||
ifinfo \
|
||||
iftop \
|
||||
isc-dhcp44-relay \
|
||||
isc-dhcp44-server \
|
||||
kea \
|
||||
lighttpd \
|
||||
|
||||
3
plist
3
plist
@ -593,6 +593,9 @@
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_2.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_3.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Cron/Migrations/M1_0_4.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/DHCRelay/Migrations/M1_0_0.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/ACL/ACL.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/DnsDiagnostics.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Diagnostics/DnsDiagnostics.xml
|
||||
|
||||
@ -400,7 +400,7 @@ function core_xmlrpc_sync()
|
||||
);
|
||||
$result[] = array(
|
||||
'description' => gettext('DHCPv4: Relay'),
|
||||
'section' => 'dhcrelay',
|
||||
'section' => 'dhcrelay,OPNsense.DHCRelay',
|
||||
'id' => 'dhcrelay',
|
||||
'services' => ["dhcrelay"],
|
||||
);
|
||||
|
||||
35
src/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.php
Normal file
35
src/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\DHCRelay;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
|
||||
class DHCRelay extends BaseModel
|
||||
{
|
||||
}
|
||||
40
src/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
Normal file
40
src/opnsense/mvc/app/models/OPNsense/DHCRelay/DHCRelay.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<model>
|
||||
<mount>//OPNsense/DHCRelay</mount>
|
||||
<version>1.0.0</version>
|
||||
<description>DHCRelay configuration</description>
|
||||
<items>
|
||||
<relays type="ArrayField">
|
||||
<enabled type="BooleanField">
|
||||
<Required>Y</Required>
|
||||
</enabled>
|
||||
<interface type="InterfaceField">
|
||||
<Required>Y</Required>
|
||||
</interface>
|
||||
<destination type="ModelRelationField">
|
||||
<Model>
|
||||
<template>
|
||||
<source>OPNsense.DHCRelay.DHCRelay</source>
|
||||
<items>destinations</items>
|
||||
<display>description</display>
|
||||
</template>
|
||||
</Model>
|
||||
<Required>Y</Required>
|
||||
</destination>
|
||||
<agent_info type="BooleanField">
|
||||
<Required>Y</Required>
|
||||
</agent_info>
|
||||
</relays>
|
||||
<destinations type="ArrayField">
|
||||
<server type="NetworkField">
|
||||
<Required>Y</Required>
|
||||
<NetMaskAllowed>N</NetMaskAllowed>
|
||||
<AddressFamily>ipv4</AddressFamily>
|
||||
<AsList>Y</AsList>
|
||||
<FieldSeparator>,</FieldSeparator>
|
||||
</server>
|
||||
<description type="TextField">
|
||||
<Required>Y</Required>
|
||||
</description>
|
||||
</destinations>
|
||||
</items>
|
||||
</model>
|
||||
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2023 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
namespace OPNsense\DHCRelay\Migrations;
|
||||
|
||||
use OPNsense\Base\BaseModelMigration;
|
||||
use OPNsense\Base\FieldTypes\BooleanField;
|
||||
use OPNsense\Base\FieldTypes\NetworkField;
|
||||
use OPNsense\Base\FieldTypes\PortField;
|
||||
use OPNsense\Core\Config;
|
||||
|
||||
class M1_0_0 extends BaseModelMigration
|
||||
{
|
||||
/**
|
||||
* Migrate older models into shared model
|
||||
* @param $model
|
||||
*/
|
||||
public function run($model)
|
||||
{
|
||||
$config = Config::getInstance()->object();
|
||||
|
||||
$legacy = $config->dhcrelay;
|
||||
if (empty($legacy->interface) || empty($legacy->server)) {
|
||||
/* no value in partial migration so skip all */
|
||||
return;
|
||||
}
|
||||
|
||||
$node = $model->destinations->add();
|
||||
$node->setNodes([
|
||||
'server' => (string)$legacy->server,
|
||||
'description' => 'Migrated server entry',
|
||||
]);
|
||||
$dest_uuid = $node->getAttribute('uuid');
|
||||
|
||||
foreach (explode(',', (string)$legacy->interface) as $interface) {
|
||||
$node = $model->relays->add();
|
||||
$node->setNodes([
|
||||
'agent_info' => !empty($legacy->agentoption),
|
||||
'enabled' => !empty($legacy->enable),
|
||||
'interface' => (string)$interface,
|
||||
'destination' => $dest_uuid,
|
||||
]);
|
||||
$node->interface->normalizeValue();
|
||||
if (empty((string)$node->interface)) {
|
||||
$model->relays->del($node->getAttribute('uuid'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function post($model)
|
||||
{
|
||||
$config = Config::getInstance()->object();
|
||||
// XXX later
|
||||
//unset($config->dhcrelay);
|
||||
}
|
||||
}
|
||||
@ -102,11 +102,6 @@ include("head.inc");
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<?php
|
||||
if ($dhcpd_enabled) {
|
||||
print_info_box(gettext('DHCP Server is currently enabled. Cannot enable the DHCP Relay service while the DHCP Server is enabled on any interface.'));
|
||||
} else {
|
||||
?>
|
||||
<?php if (isset($input_errors) && count($input_errors) > 0) print_input_errors($input_errors); ?>
|
||||
<?php if (isset($savemsg)) print_info_box($savemsg); ?>
|
||||
<section class="col-xs-12">
|
||||
@ -179,7 +174,6 @@ include("head.inc");
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user