mirror of
https://github.com/opnsense/core.git
synced 2026-05-28 04:34:51 -04:00
services: migrate opendns page to MVC/API
Also consolidate registration / apply logic, as well as save/restore previous DNS settings
This commit is contained in:
parent
0460e24e29
commit
c2253fa062
14 changed files with 449 additions and 242 deletions
12
plist
12
plist
|
|
@ -432,6 +432,10 @@
|
|||
/usr/local/opnsense/mvc/app/controllers/OPNsense/Monit/forms/tests.xml
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/Ntpd/Api/ServiceController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/Ntpd/StatusController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenDNS/Api/ServiceController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenDNS/Api/SettingsController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenDNS/SettingsController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenDNS/forms/general.xml
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ClientOverwritesController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/ExportController.php
|
||||
/usr/local/opnsense/mvc/app/controllers/OPNsense/OpenVPN/Api/InstancesController.php
|
||||
|
|
@ -866,6 +870,10 @@
|
|||
/usr/local/opnsense/mvc/app/models/OPNsense/Monit/Monit.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Ntpd/ACL/ACL.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/Ntpd/Menu/Menu.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenDNS/ACL/ACL.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenDNS/Menu/Menu.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenVPN/Export.php
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenVPN/Export.xml
|
||||
/usr/local/opnsense/mvc/app/models/OPNsense/OpenVPN/FieldTypes/InstanceField.php
|
||||
|
|
@ -1016,6 +1024,7 @@
|
|||
/usr/local/opnsense/mvc/app/views/OPNsense/Monit/index.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/Monit/status.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/Ntpd/status.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/OpenDNS/settings.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/OpenVPN/cso.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/OpenVPN/export.volt
|
||||
/usr/local/opnsense/mvc/app/views/OPNsense/OpenVPN/instances.volt
|
||||
|
|
@ -1327,6 +1336,7 @@
|
|||
/usr/local/opnsense/scripts/netflow/lib/parse.py
|
||||
/usr/local/opnsense/scripts/ntpd/ntpd_status.php
|
||||
/usr/local/opnsense/scripts/openssh/ssh_query.py
|
||||
/usr/local/opnsense/scripts/opendns/configure.php
|
||||
/usr/local/opnsense/scripts/openvpn/client_connect.php
|
||||
/usr/local/opnsense/scripts/openvpn/client_disconnect.sh
|
||||
/usr/local/opnsense/scripts/openvpn/genkey.py
|
||||
|
|
@ -1455,6 +1465,7 @@
|
|||
/usr/local/opnsense/service/conf/actions.d/actions_monit.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_netflow.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_ntpd.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_opendns.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_openssh.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_openvpn.conf
|
||||
/usr/local/opnsense/service/conf/actions.d/actions_radvd.conf
|
||||
|
|
@ -2550,7 +2561,6 @@
|
|||
/usr/local/www/services_ntpd.php
|
||||
/usr/local/www/services_ntpd_gps.php
|
||||
/usr/local/www/services_ntpd_pps.php
|
||||
/usr/local/www/services_opendns.php
|
||||
/usr/local/www/status_wireless.php
|
||||
/usr/local/www/system_advanced_admin.php
|
||||
/usr/local/www/system_advanced_firewall.php
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* Copyright (C) 2019 Deciso B.V.
|
||||
* All rights reserved.
|
||||
*
|
||||
|
|
@ -37,12 +38,17 @@ function opendns_configure()
|
|||
|
||||
function opendns_configure_do($verbose = false)
|
||||
{
|
||||
global $config;
|
||||
$mdl = new \OPNsense\OpenDNS\OpenDNS();
|
||||
|
||||
if (!empty($config['opendns']['enable'])) {
|
||||
if (!$mdl->enable->isEmpty()) {
|
||||
service_log('Configure OpenDNS...', $verbose);
|
||||
|
||||
$result = opendns_register($config['opendns']);
|
||||
$pconfig = [
|
||||
'username' => (string)$mdl->username,
|
||||
'password' => (string)$mdl->password,
|
||||
'host' => (string)$mdl->host,
|
||||
];
|
||||
$result = opendns_register($pconfig);
|
||||
log_msg("opendns response: $result");
|
||||
|
||||
service_log("done.\n", $verbose);
|
||||
|
|
@ -53,7 +59,7 @@ function opendns_xmlrpc_sync()
|
|||
{
|
||||
return [[
|
||||
'description' => gettext('OpenDNS'),
|
||||
'section' => 'opendns',
|
||||
'section' => 'OPNsense.OpenDNS',
|
||||
'id' => 'opendns',
|
||||
]];
|
||||
}
|
||||
|
|
@ -64,6 +70,7 @@ function opendns_register($pconfig)
|
|||
curl_setopt($ch, CURLOPT_URL, sprintf('https://updates.opendns.com/nic/update?hostname=%s', $pconfig['host']));
|
||||
curl_setopt($ch, CURLOPT_USERPWD, sprintf('%s:%s', $pconfig['username'], $pconfig['password']));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* 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\OpenDNS\Api;
|
||||
|
||||
use OPNsense\Base\ApiControllerBase;
|
||||
use OPNsense\Core\Backend;
|
||||
|
||||
class ServiceController extends ApiControllerBase
|
||||
{
|
||||
/**
|
||||
* apply OpenDNS configuration
|
||||
* @return array
|
||||
*/
|
||||
public function reconfigureAction()
|
||||
{
|
||||
$result = ['status' => 'failed'];
|
||||
if ($this->request->isPost()) {
|
||||
$result['status'] = trim((new Backend())->configdRun('opendns configure'));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* 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\OpenDNS\Api;
|
||||
|
||||
use OPNsense\Base\ApiMutableModelControllerBase;
|
||||
|
||||
class SettingsController extends ApiMutableModelControllerBase
|
||||
{
|
||||
protected static $internalModelName = 'opendns';
|
||||
protected static $internalModelClass = '\OPNsense\OpenDNS\OpenDNS';
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* 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\OpenDNS;
|
||||
|
||||
/**
|
||||
* Class SettingsController
|
||||
* @package OPNsense\OpenDNS
|
||||
*/
|
||||
class SettingsController extends \OPNsense\Base\IndexController
|
||||
{
|
||||
public function indexAction()
|
||||
{
|
||||
$this->view->generalForm = $this->getForm('general');
|
||||
$this->view->pick('OPNsense/OpenDNS/settings');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<form>
|
||||
<field>
|
||||
<id>opendns.enable</id>
|
||||
<label>Enable OpenDNS</label>
|
||||
<type>checkbox</type>
|
||||
<help><![CDATA[If this option is enabled, DNS requests will be filtered using the DNS servers from <a href="https://www.opendns.com/" target="_blank">OpenDNS.com</a>, unless Standalone mode is enabled. The DNS servers configured under <a href="/system_general.php">System: Settings: General</a> will be overwritten, and any DNS servers learned by DHCP/PPP on WAN will be ignored. The previous DNS settings will be saved, and later restored when OpenDNS is disabled.]]></help>
|
||||
</field>
|
||||
<field>
|
||||
<id>opendns.standalone</id>
|
||||
<label>Standalone mode</label>
|
||||
<type>checkbox</type>
|
||||
<help>If this option is enabled, the system's DNS server settings will not be altered to use the DNS servers from OpenDNS.com. This mode is useful when the OpenDNS servers are used by a different network component but the periodic update behavior is still desired.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>opendns.username</id>
|
||||
<label>OpenDNS.com username</label>
|
||||
<type>text</type>
|
||||
<help>Login username for the OpenDNS.com dashboard. Used to automatically update the IP address of the registered network.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>opendns.password</id>
|
||||
<label>OpenDNS.com password</label>
|
||||
<type>password</type>
|
||||
<help>Login password for the OpenDNS.com dashboard.</help>
|
||||
</field>
|
||||
<field>
|
||||
<id>opendns.host</id>
|
||||
<label>OpenDNS.com network label</label>
|
||||
<type>text</type>
|
||||
<help><![CDATA[Network label (or 'friendly name') on the <a href="https://dashboard.opendns.com/settings/" target="_blank">settings dashboard of OpenDNS.com</a>. Used to update the node's IP address whenever the WAN interface changes its IP address.]]></help>
|
||||
</field>
|
||||
</form>
|
||||
10
src/opnsense/mvc/app/models/OPNsense/OpenDNS/ACL/ACL.xml
Normal file
10
src/opnsense/mvc/app/models/OPNsense/OpenDNS/ACL/ACL.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<acl>
|
||||
<page-services-opendns>
|
||||
<name>Services: OpenDNS</name>
|
||||
<patterns>
|
||||
<pattern>ui/opendns/settings</pattern>
|
||||
<pattern>api/opendns/settings/*</pattern>
|
||||
<pattern>api/opendns/service/*</pattern>
|
||||
</patterns>
|
||||
</page-services-opendns>
|
||||
</acl>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<menu>
|
||||
<Services>
|
||||
<OpenDNS VisibleName="OpenDNS" url="/ui/opendns/settings" cssClass="fa fa-tags fa-fw"/>
|
||||
</Services>
|
||||
</menu>
|
||||
58
src/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.php
Normal file
58
src/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.php
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* 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\OpenDNS;
|
||||
|
||||
use OPNsense\Base\BaseModel;
|
||||
use OPNsense\Base\Messages\Message;
|
||||
|
||||
class OpenDNS extends BaseModel
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function performValidation($validateFullModel = false)
|
||||
{
|
||||
$messages = parent::performValidation($validateFullModel);
|
||||
if ($this->enable->isEmpty()) {
|
||||
return $messages;
|
||||
}
|
||||
foreach (['username', 'password', 'host'] as $fieldname) {
|
||||
$node = $this->$fieldname;
|
||||
if ($validateFullModel || $node->isFieldChanged()) {
|
||||
if (trim((string)$node) === '') {
|
||||
$messages->appendMessage(new Message(
|
||||
gettext('A value is required when OpenDNS is enabled.'),
|
||||
$fieldname
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
28
src/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.xml
Normal file
28
src/opnsense/mvc/app/models/OPNsense/OpenDNS/OpenDNS.xml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<model>
|
||||
<mount>//opendns</mount>
|
||||
<version>1.0.0</version>
|
||||
<description>OpenDNS configuration</description>
|
||||
<items>
|
||||
<enable type="BooleanField">
|
||||
<Default>0</Default>
|
||||
</enable>
|
||||
<standalone type="BooleanField">
|
||||
<Default>0</Default>
|
||||
</standalone>
|
||||
<username type="TextField"/>
|
||||
<password type="TextField"/>
|
||||
<host type="TextField">
|
||||
<Mask>/^[a-zA-Z0-9 _\-\.]+$/</Mask>
|
||||
<ValidationMessage>Please specify a valid OpenDNS network label.</ValidationMessage>
|
||||
</host>
|
||||
<backup>
|
||||
<has_backup type="BooleanField">
|
||||
<Default>0</Default>
|
||||
</has_backup>
|
||||
<dnsservers type="TextField"/>
|
||||
<dnsallowoverride type="BooleanField">
|
||||
<Default>1</Default>
|
||||
</dnsallowoverride>
|
||||
</backup>
|
||||
</items>
|
||||
</model>
|
||||
48
src/opnsense/mvc/app/views/OPNsense/OpenDNS/settings.volt
Normal file
48
src/opnsense/mvc/app/views/OPNsense/OpenDNS/settings.volt
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
{#
|
||||
# Copyright (C) 2026 Greelan
|
||||
# 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.
|
||||
#}
|
||||
|
||||
<script>
|
||||
$( document ).ready(function() {
|
||||
let data_get_map = {'frm_settings':"/api/opendns/settings/get"};
|
||||
mapDataToFormUI(data_get_map).done(function(){
|
||||
formatTokenizersUI();
|
||||
$('.selectpicker').selectpicker('refresh');
|
||||
});
|
||||
|
||||
$("#reconfigureAct").SimpleActionButton({
|
||||
onPreAction: function() {
|
||||
const dfObj = new $.Deferred();
|
||||
saveFormToEndpoint("/api/opendns/settings/set", 'frm_settings', function () { dfObj.resolve(); }, true, function () { dfObj.reject(); });
|
||||
return dfObj;
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<div class="content-box">
|
||||
{{ partial("layout_partials/base_form",['fields':generalForm,'id':'frm_settings'])}}
|
||||
</div>
|
||||
{{ partial('layout_partials/base_apply_button', {'data_endpoint': '/api/opendns/service/reconfigure', 'data_error_title': lang._('Error applying OpenDNS configuration')}) }}
|
||||
115
src/opnsense/scripts/opendns/configure.php
Normal file
115
src/opnsense/scripts/opendns/configure.php
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
#!/usr/local/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2026 Greelan
|
||||
* Copyright (c) 2015-2021 Franco Fichtner <franco@opnsense.org>
|
||||
* Copyright (c) 2008 Tellnet AG
|
||||
* 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.
|
||||
*/
|
||||
|
||||
require_once('config.inc');
|
||||
require_once('util.inc');
|
||||
require_once('plugins.inc.d/opendns.inc');
|
||||
|
||||
use OPNsense\OpenDNS\OpenDNS;
|
||||
|
||||
$mdl = new OpenDNS();
|
||||
$enabled = !$mdl->enable->isEmpty();
|
||||
$standalone = !$mdl->standalone->isEmpty();
|
||||
$has_backup = (string)$mdl->backup->has_backup == '1';
|
||||
|
||||
if ($enabled) {
|
||||
$result = trim(opendns_register([
|
||||
'username' => (string)$mdl->username,
|
||||
'password' => (string)$mdl->password,
|
||||
'host' => (string)$mdl->host,
|
||||
]));
|
||||
$errors = [];
|
||||
foreach (explode("\n", $result) as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '' || strpos($line, 'good') === 0 || $line === 'noop') {
|
||||
continue;
|
||||
}
|
||||
$errors[] = $line;
|
||||
}
|
||||
if (!empty($errors)) {
|
||||
echo "OpenDNS.com registration failed: " . implode("\n", $errors);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
$system = &config_read_array('system');
|
||||
|
||||
if ($enabled && $standalone) {
|
||||
/* standalone mode: do not alter DNS server settings */
|
||||
} elseif ($enabled) {
|
||||
/* capture current DNS settings before overwriting,
|
||||
* but only if we don't already have a backup
|
||||
* (avoids re-capturing OpenDNS servers on subsequent applies) */
|
||||
if (!$has_backup) {
|
||||
$mdl->backup->has_backup = '1';
|
||||
$mdl->backup->dnsservers = implode(',', $system['dnsserver'] ?? []);
|
||||
$mdl->backup->dnsallowoverride = $system['dnsallowoverride'] ?? '1';
|
||||
$mdl->serializeToConfig(false, true);
|
||||
}
|
||||
|
||||
$system['dnsserver'] = [];
|
||||
$v4_server = ['208.67.222.222', '208.67.220.220'];
|
||||
$v6_server = ['2620:119:35::35', '2620:119:53::53'];
|
||||
if (isset($system['prefer_ipv4'])) {
|
||||
$system['dnsserver'][] = $v4_server[0];
|
||||
$system['dnsserver'][] = $v4_server[1];
|
||||
if (is_ipv6_allowed()) {
|
||||
$system['dnsserver'][] = $v6_server[0];
|
||||
$system['dnsserver'][] = $v6_server[1];
|
||||
}
|
||||
} else {
|
||||
if (is_ipv6_allowed()) {
|
||||
$system['dnsserver'][] = $v6_server[0];
|
||||
$system['dnsserver'][] = $v6_server[1];
|
||||
}
|
||||
$system['dnsserver'][] = $v4_server[0];
|
||||
$system['dnsserver'][] = $v4_server[1];
|
||||
}
|
||||
$system['dnsallowoverride'] = '0';
|
||||
} else {
|
||||
/* disabled: restore backup if available, otherwise fall back to defaults */
|
||||
if ($has_backup) {
|
||||
$servers = explode(',', (string)$mdl->backup->dnsservers);
|
||||
$system['dnsserver'] = !empty(array_filter($servers)) ? $servers : [''];
|
||||
$system['dnsallowoverride'] = (string)$mdl->backup->dnsallowoverride;
|
||||
|
||||
/* clear the backup */
|
||||
$mdl->backup->has_backup = '0';
|
||||
$mdl->backup->dnsservers = '';
|
||||
$mdl->backup->dnsallowoverride = '1';
|
||||
$mdl->serializeToConfig(false, true);
|
||||
} else {
|
||||
$system['dnsserver'] = [''];
|
||||
$system['dnsallowoverride'] = '1';
|
||||
}
|
||||
}
|
||||
|
||||
write_config('OpenDNS filter configuration change');
|
||||
4
src/opnsense/service/conf/actions.d/actions_opendns.conf
Normal file
4
src/opnsense/service/conf/actions.d/actions_opendns.conf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[configure]
|
||||
command:/usr/local/opnsense/scripts/opendns/configure.php && { /usr/local/sbin/pluginctl -c dns_reload > /dev/null || { echo "dns_reload failed"; exit 1; }; } && { /usr/local/sbin/pluginctl -c dhcp > /dev/null || { echo "dhcp reload failed"; exit 1; }; } && echo ok
|
||||
type:script_output
|
||||
message:Configuring OpenDNS
|
||||
|
|
@ -1,237 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2015-2021 Franco Fichtner <franco@opnsense.org>
|
||||
* Copyright (c) 2008 Tellnet AG
|
||||
* 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.
|
||||
*/
|
||||
|
||||
require_once("guiconfig.inc");
|
||||
require_once("system.inc");
|
||||
require_once("interfaces.inc");
|
||||
require_once("plugins.inc.d/opendns.inc");
|
||||
|
||||
config_read_array('opendns');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
$pconfig['enable'] = isset($config['opendns']['enable']);
|
||||
$pconfig['standalone'] = isset($config['opendns']['standalone']);
|
||||
$pconfig['username'] = !empty($config['opendns']['username']) ? $config['opendns']['username'] : null;
|
||||
$pconfig['password'] = !empty($config['opendns']['password']) ? $config['opendns']['password'] : null;
|
||||
$pconfig['host'] = !empty($config['opendns']['host']) ? $config['opendns']['host'] : null;
|
||||
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$input_errors = array();
|
||||
$pconfig = $_POST;
|
||||
|
||||
/* input validation */
|
||||
$reqdfields = array();
|
||||
$reqdfieldsn = array();
|
||||
if (!empty($pconfig['enable'])) {
|
||||
$reqdfields = array_merge($reqdfields, explode(" ", "host username password"));
|
||||
$reqdfieldsn = array_merge($reqdfieldsn, explode(",", "Network,Username,Password"));
|
||||
}
|
||||
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
||||
|
||||
if (!empty($pconfig['host']) && !is_domain($pconfig['host'])) {
|
||||
$input_errors[] = 'The host name contains invalid characters.';
|
||||
}
|
||||
if (empty($pconfig['username'])) {
|
||||
$input_errors[] = 'The username cannot be empty.';
|
||||
}
|
||||
|
||||
if (!empty($pconfig['test'])) {
|
||||
$test_results = explode("\r\n", opendns_register($pconfig));
|
||||
} elseif (count($input_errors) == 0) {
|
||||
$config['opendns']['enable'] = !empty($pconfig['enable']);
|
||||
$config['opendns']['standalone'] = !empty($pconfig['standalone']);
|
||||
$config['opendns']['username'] = $pconfig['username'];
|
||||
$config['opendns']['password'] = $pconfig['password'];
|
||||
$config['opendns']['host'] = $pconfig['host'];
|
||||
if ($config['opendns']['standalone']) {
|
||||
/* nothing to do, keep system state */
|
||||
} elseif ($config['opendns']['enable']) {
|
||||
$config['system']['dnsserver'] = array();
|
||||
$v4_server = array('208.67.222.222', '208.67.220.220');
|
||||
$v6_server = array('2620:119:35::35', '2620:119:53::53');
|
||||
if (isset($config['system']['prefer_ipv4'])) {
|
||||
$config['system']['dnsserver'][] = $v4_server[0];
|
||||
$config['system']['dnsserver'][] = $v4_server[1];
|
||||
if (is_ipv6_allowed()) {
|
||||
$config['system']['dnsserver'][] = $v6_server[0];
|
||||
$config['system']['dnsserver'][] = $v6_server[1];
|
||||
}
|
||||
} else {
|
||||
if (is_ipv6_allowed()) {
|
||||
$config['system']['dnsserver'][] = $v6_server[0];
|
||||
$config['system']['dnsserver'][] = $v6_server[1];
|
||||
}
|
||||
$config['system']['dnsserver'][] = $v4_server[0];
|
||||
$config['system']['dnsserver'][] = $v4_server[1];
|
||||
}
|
||||
$config['system']['dnsallowoverride'] = '0';
|
||||
} else {
|
||||
$config['system']['dnsserver'] = [];
|
||||
$config['system']['dnsserver'][] = '';
|
||||
$config['system']['dnsallowoverride'] = '1';
|
||||
}
|
||||
write_config('OpenDNS filter configuration change');
|
||||
system_resolver_configure();
|
||||
plugins_configure('dhcp');
|
||||
$savemsg = get_std_save_message();
|
||||
}
|
||||
}
|
||||
|
||||
legacy_html_escape_form_data($pconfig);
|
||||
|
||||
include 'head.inc';
|
||||
|
||||
?>
|
||||
<body>
|
||||
|
||||
<?php include 'fbegin.inc'; ?>
|
||||
<section class="page-content-main">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<?php
|
||||
if (isset($input_errors) && count($input_errors) > 0) {
|
||||
print_input_errors($input_errors);
|
||||
}
|
||||
if (isset($savemsg)) {
|
||||
print_info_box($savemsg);
|
||||
}?>
|
||||
<section class="col-xs-12">
|
||||
<div class="content-box table-responsive">
|
||||
<form method="post">
|
||||
<table class="table table-striped opnsense_standard_table_form">
|
||||
<thead>
|
||||
<tr>
|
||||
<td style="width:22%"><strong><?=gettext('OpenDNS Setup'); ?></strong></td>
|
||||
<td style="width:78%; text-align:right">
|
||||
<small><?=gettext("full help"); ?> </small>
|
||||
<i class="fa fa-toggle-off text-danger" style="cursor: pointer;" id="show_all_help_page"></i>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a id="help_for_enable" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Enable'); ?></td>
|
||||
<td>
|
||||
<input name="enable" type="checkbox" id="enable" value="yes" <?=!empty($pconfig['enable']) ? 'checked="checked"' : "";?> />
|
||||
<?= gettext('Filter DNS requests using OpenDNS') ?>
|
||||
<div class="hidden" data-for="help_for_enable">
|
||||
<?= sprintf(gettext(
|
||||
'Enabling the OpenDNS service will overwrite DNS servers configured ' .
|
||||
'via the General Setup page as well as ignore any DNS servers learned ' .
|
||||
'by DHCP/PPP on WAN and use the DNS servers from %s instead.'),
|
||||
'<a href="https://www.opendns.com/" target="_blank">OpenDNS.com</a>'
|
||||
) ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a id="help_for_standalone" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Standalone'); ?></td>
|
||||
<td>
|
||||
<input name="standalone" type="checkbox" id="standalone" value="yes" <?=!empty($pconfig['standalone']) ? 'checked="checked"' : "";?> />
|
||||
<?= gettext('Do not alter system DNS server settings') ?>
|
||||
<div class="hidden" data-for="help_for_standalone">
|
||||
<?= sprintf(gettext(
|
||||
'Enable this mode when the OpenDNS servers are used by a different ' .
|
||||
'network component but the periodic update behaviour is still desired.'
|
||||
)) ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a id="help_for_username" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Username'); ?></td>
|
||||
<td>
|
||||
<input name="username" type="text" id="username" size="20" value="<?=$pconfig['username'];?>" />
|
||||
<div class="hidden" data-for="help_for_username">
|
||||
<?=gettext(
|
||||
'Signon Username to log into your OpenDNS dashboard. ' .
|
||||
'It is used to automatically update the IP address of ' .
|
||||
'the registered network.'
|
||||
); ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Password'); ?></td>
|
||||
<td>
|
||||
<input name="password" type="password" autocomplete="new-password" id="password" size="20" value="<?=$pconfig['password'];?>" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a id="help_for_host" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext('Network'); ?></td>
|
||||
<td>
|
||||
<input name="host" type="text" id="host" size="30" value="<?=$pconfig['host'];?>" />
|
||||
<div class="hidden" data-for="help_for_host">
|
||||
<?= sprintf(gettext(
|
||||
'Enter the network name configured on the %sNetworks ' .
|
||||
'Dashboard of OpenDNS%s under \'Manage your networks\'. ' .
|
||||
'Used to update the node\'s IP address whenever the ' .
|
||||
'WAN interface changes its IP address.'),
|
||||
'<a href="https://www.opendns.com/dashboard/networks/" target="_blank">', '</a>'
|
||||
) ?>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if (isset($test_results) && is_array($test_results)): ?>
|
||||
<tr>
|
||||
<td><i class="fa fa-info-circle text-muted"></i> <?=gettext('Test result');?></td>
|
||||
<td>
|
||||
<?php
|
||||
foreach ($test_results as $result) {
|
||||
if (!strlen($result)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo sprintf(
|
||||
'<i class="fa fa-%s"></i> %s<br />',
|
||||
strpos($result, 'good') === 0 ? 'check text-success' : 'times text-danger',
|
||||
$result
|
||||
);
|
||||
}?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif; ?>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>
|
||||
<input name="submit" type="submit" class="btn btn-primary" value="<?=html_safe(gettext('Save'));?>" />
|
||||
<input name="test" type="submit" class="btn btn-primary" value="<?=html_safe(gettext('Test/Update'));?>" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php include 'foot.inc'; ?>
|
||||
Loading…
Reference in a new issue