unbound: migrate to single model #4327

This commit is contained in:
Franco Fichtner 2021-07-20 16:50:54 +02:00
parent 073681f895
commit 3e66f270b1
4 changed files with 84 additions and 3 deletions

1
plist
View File

@ -557,6 +557,7 @@
/usr/local/opnsense/mvc/app/models/OPNsense/TrafficShaper/TrafficShaper.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/ACL/ACL.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Menu/Menu.xml
/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Migrations/M1_0_0.php
/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.php
/usr/local/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml
/usr/local/opnsense/mvc/app/views/OPNsense/CaptivePortal/clients.volt

View File

@ -0,0 +1,80 @@
<?php
/*
* Copyright (C) 2021 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\Unbound\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();
if (empty($config->OPNsense->unboundplus)) {
return;
}
$mdlNode = $config->OPNsense->unboundplus;
foreach (['dnsbl', 'miscellaneous'] as $strip) {
if (!empty($mdlNode->$strip)) {
$model->$strip->setAttributeValue('version', null);
}
}
if (!empty($mdlNode->miscellaneous->dotservers)) {
foreach (explode(',', (string)$mdlNode->miscellaneous->dotservers) as $dot) {
$dotNode = $model->dots->dot->add();
$dotData = explode('@', $dot, 2);
$dotEnabled = new BooleanField('enabled', 'enabled');
$dotEnabled->setValue('1');
$dotNode->addChildNode('enabled', $dotEnabled);
$dotServer = new NetworkField('server', 'server');
$dotServer->setValue($dotData[0]);
$dotNode->addChildNode('server', $dotServer);
if (!empty($dotData[1])) {
$dotPort = new PortField('port', 'port');
$dotPort->setValue($dotData[1]);
$dotNode->addChildNode('port', $dotPort);
}
}
}
}
}

View File

@ -1,7 +1,7 @@
<model>
<mount>//OPNsense/unboundplus</mount>
<description>Unbound configuration</description>
<version>0.0.0</version>
<version>1.0.0</version>
<items>
<service_enabled type="LegacyLinkField">
<Source>unbound.enable</Source>
@ -65,7 +65,7 @@
<Required>Y</Required>
</server>
<port type="PortField">
<Required>Y</Required>
<Required>N</Required>
</port>
<verify type="HostnameField">
<Required>N</Required>

View File

@ -12,7 +12,7 @@ forward-zone:
name: "."
forward-tls-upstream: yes
{% for dot in dots %}
forward-addr: {{ dot.server }}@{{ dot.port }}{% if dot.verify %}#{{ dot.verify }}{% endif %}
forward-addr: {{ dot.server }}{% if dot.port %}@{{ dot.port }}{% endif %}{% if dot.verify %}#{{ dot.verify }}{% endif %}
{% endfor %}
{% endif %}