dns/ddclient - work in progress, replacement for dyndns using ddclient package

This commit is contained in:
Ad Schellevis
2021-12-29 22:18:50 +01:00
parent 0b05f1d71b
commit bb3f06227f
15 changed files with 493 additions and 0 deletions
+7
View File
@@ -0,0 +1,7 @@
PLUGIN_NAME= ddclient
PLUGIN_VERSION= 1
PLUGIN_REVISION= 1
PLUGIN_COMMENT= Dynamic DNS client
PLUGIN_MAINTAINER= ad@opnsense.org
.include "../../Mk/plugins.mk"
+1
View File
@@ -0,0 +1 @@
Support for numerous Dynamic DNS services using ddclient
@@ -0,0 +1,73 @@
<?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\DynDNS\Api;
use OPNsense\Base\ApiMutableModelControllerBase;
class AccountsController extends ApiMutableModelControllerBase
{
protected static $internalModelName = 'account';
protected static $internalModelClass = 'OPNsense\DynDNS\DynDNS';
public function searchItemAction()
{
return $this->searchBase(
"accounts.account",
['enabled', 'service', 'description', 'username', 'hostnames'],
"description"
);
}
public function setItemAction($uuid)
{
return $this->setBase("account", "accounts.account", $uuid);
}
public function addItemAction()
{
return $this->addBase("account", "accounts.account");
}
public function getItemAction($uuid = null)
{
return $this->getBase("account", "accounts.account", $uuid);
}
public function delItemAction($uuid)
{
return $this->delBase("accounts.account", $uuid);
}
public function toggleItemAction($uuid, $enabled = null)
{
return $this->toggleBase("accounts.account", $uuid, $enabled);
}
}
@@ -0,0 +1,49 @@
<?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\DynDNS\Api;
use OPNsense\Base\ApiMutableServiceControllerBase;
/**
* {@inheritdoc}
*/
class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\OPNsense\DynDNS\DynDNS';
protected static $internalServiceEnabled = 'general.enabled';
protected static $internalServiceTemplate = 'OPNsense/ddclient';
protected static $internalServiceName = 'ddclient';
protected function reconfigureForceRestart()
{
return 0;
}
}
@@ -0,0 +1,46 @@
<?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\DynDNS;
/**
* Class IndexController
* @package OPNsense\DynDNS
*/
class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
// link dialogs
$this->view->formDialogAccount = $this->getForm("dialogAccount");
// choose template
$this->view->pick('OPNsense/DynDNS/index');
}
}
@@ -0,0 +1,39 @@
<form>
<field>
<id>account.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Enable this virtual server</help>
</field>
<field>
<id>account.service</id>
<label>Service</label>
<type>dropdown</type>
<help>Select the service to use.</help>
</field>
<field>
<id>account.username</id>
<label>Username</label>
<type>text</type>
<help>Username or login to use</help>
</field>
<field>
<id>account.password</id>
<label>Password</label>
<type>password</type>
<help>Password associated with this account</help>
</field>
<field>
<id>account.hostnames</id>
<label>Hostname(s)</label>
<type>select_multiple</type>
<style>tokenize</style>
<allownew>true</allownew>
<help>Hostname to update</help>
</field>
<field>
<id>account.description</id>
<label>Description</label>
<type>text</type>
</field>
</form>
@@ -0,0 +1,9 @@
<acl>
<page-services-dyndns>
<name>Services: Dynamic DNS</name>
<patterns>
<pattern>ui/dyndns/*</pattern>
<pattern>api/dyndns/*</pattern>
</patterns>
</page-services-dyndns>
</acl>
@@ -0,0 +1,39 @@
<?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\DynDNS;
use OPNsense\Base\BaseModel;
/**
* Class DynDNS
* @package OPNsense\DynDNS
*/
class DynDNS extends BaseModel
{
}
@@ -0,0 +1,52 @@
<model>
<mount>//OPNsense/DynDNS</mount>
<version>1.0.0</version>
<description>
Dynamic DNS client
</description>
<items>
<general>
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
</general>
<accounts>
<account type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<service type="OptionField">
<Required>Y</Required>
<ValidationMessage>A service type is required.</ValidationMessage>
<OptionValues>
<noip>Noip</noip>
<nsupdatev4>nsupdate (IPv4)</nsupdatev4>
<nsupdatev6>nsupdate (IPv6)</nsupdatev6>
</OptionValues>
</service>
<username type="TextField">
<Required>Y</Required>
<mask>/^([a-z0-9\-.@_:+])*$/u</mask>
<ValidationMessage>The username contains invalid characters.</ValidationMessage>
</username>
<password type="UpdateOnlyTextField">
<Required>Y</Required>
<mask>/^[^\n]*$/</mask>
</password>
<hostnames type="HostnameField">
<Required>Y</Required>
<IpAllowed>N</IpAllowed>
<AsList>Y</AsList>
<FieldSeparator>,</FieldSeparator>
</hostnames>
<description type="TextField">
<Required>N</Required>
<mask>/^([\t\n\v\f\r 0-9a-zA-Z.,_\x{00A0}-\x{FFFF}]){1,255}$/u</mask>
<ValidationMessage>Description should be a string between 1 and 255 characters</ValidationMessage>
</description>
</account>
</accounts>
</items>
</model>
@@ -0,0 +1,5 @@
<menu>
<Services>
<DynamicDNS VisibleName="Dynamic DNS" url="/ui/dyndns/" cssClass="fa fa-tags fa-fw"/>
</Services>
</menu>
@@ -0,0 +1,96 @@
{#
OPNsense® is Copyright © 2021 by 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.
#}
<script>
$( document ).ready(function() {
$("#grid-accounts").UIBootgrid(
{ search:'/api/dyndns/accounts/search_item',
get:'/api/dyndns/accounts/get_item/',
set:'/api/dyndns/accounts/set_item/',
add:'/api/dyndns/accounts/add_item/',
del:'/api/dyndns/accounts/del_item/',
toggle:'/api/dyndns/accounts/toggle_item/'
}
);
$("#reconfigureAct").SimpleActionButton();
updateServiceControlUI('dyndns');
});
</script>
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" id="destinations" href="#tab_destinations">{{ lang._('Accounts') }}</a></li>
</ul>
<div class="tab-content content-box">
<div id="tab_accounts" class="tab-pane fade in active">
<!-- tab page "accounts" -->
<table id="grid-accounts" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogAccount" data-editAlert="ddclientChangeMessage">
<thead>
<tr>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="service" data-type="string">{{ lang._('Service') }}</th>
<th data-column-id="username" data-type="string">{{ lang._('Username') }}</th>
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</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>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-fw fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
</div>
<div class="col-md-12">
<div id="ddclientChangeMessage" class="alert alert-info" style="display: none" role="alert">
{{ lang._('After changing settings, please remember to apply them with the button below') }}
</div>
<hr/>
<button class="btn btn-primary" id="reconfigureAct"
data-endpoint='/api/dyndns/service/reconfigure'
data-label="{{ lang._('Apply') }}"
data-service-widget="dyndns"
data-error-title="{{ lang._('Error reconfiguring DynDNS') }}"
type="button"
></button>
<br/><br/>
</div>
</div>
{# include dialogs #}
{{ partial("layout_partials/base_dialog",['fields':formDialogAccount,'id':'DialogAccount','label':lang._('Edit Account')])}}
@@ -0,0 +1,25 @@
[start]
command:/usr/local/etc/rc.d/ddclient start
type:script
message:starting ddclient
[stop]
command:/usr/local/etc/rc.d/ddclient stop
type:script
message:stopping ddclient
[status]
command:/usr/local/etc/rc.d/ddclient status; exit 0
type:script_output
message:get ddclient status
[restart]
command:/usr/local/etc/rc.d/ddclient restart
type:script
message:restarting ddclient
description:Restart ddclient service
[reload]
command:/usr/local/etc/rc.d/ddclient reload
type:script
message:reload ddclient configuration
@@ -0,0 +1,2 @@
rc.conf.d:/etc/rc.conf.d/ddclient
ddclient.conf:/usr/local/etc/ddclient.conf
@@ -0,0 +1,45 @@
daemon=300 # check every 300 seconds
syslog=yes # log update msgs to syslog
pid=/var/run/ddclient.pid # record PID in file.
{% set websettings = {
'noip': 'use=web,',
'nsupdate': 'use=web, web=http://ipv4.nsupdate.info/myip,'
} %}
{% if helpers.exists('OPNsense.DynDNS.accounts.account') %}
{% for account in helpers.toList('OPNsense.DynDNS.accounts.account') %}
{% if account.enabled|default('0') == '1' %}
{% if account.service == 'noip' %}
protocol=noip, \
use=web, \
ssl=yes, \
login={{account.username}}, \
password={{account.password}} \
{{account.hostnames}}
{% elif account.service == 'nsupdatev4' %}
protocol=dyndns2, \
use=web, web=https://ipv4.nsupdate.info/myip, \
ssl=yes, \
server=ipv4.nsupdate.info, \
login={{account.username}}, \
password='{{account.password}}' \
{{account.hostnames}}
{% elif account.service == 'nsupdatev6' %}
protocol=dyndns2, \
use=web, web=https://ipv6.nsupdate.info/myip, \
ssl=yes, \
server=ipv6.nsupdate.info, \
login={{account.username}}, \
password='{{account.password}}' \
{{account.hostnames}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
@@ -0,0 +1,5 @@
{% if not helpers.empty('OPNsense.DynDNS.general.enabled') %}
ddclient_enable="YES"
{% else %}
ddclient_enable="NO"
{% endif %}