From e8b996802920f0f369c2ddb70dc40c4e29a609d9 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 18 Mar 2017 12:22:54 +0100 Subject: [PATCH] dyndns: move to plugins.inc.d #1478 Also try to unclog the use of requires and naming, we don't want stuff like "dyndns/dyndns.class" so let's go back to the roots and call the file phpdns.inc like the original prjoject was. --- plist | 5 +- src/etc/inc/plugins.inc.d/dyndns.inc | 140 ++++++++++++++++++ .../dyndns/phpdns.inc} | 4 - .../dyndns/r53.inc} | 0 src/etc/inc/services.inc | 99 +------------ src/etc/rc.dyndns.update | 6 +- src/etc/rc.newwanip | 3 - src/etc/rc.newwanipv6 | 3 - src/etc/rc.reload_all | 1 - src/www/services_dyndns.php | 4 +- src/www/services_dyndns_edit.php | 5 +- .../widgets/widgets/dyn_dns_status.widget.php | 3 +- 12 files changed, 154 insertions(+), 119 deletions(-) create mode 100644 src/etc/inc/plugins.inc.d/dyndns.inc rename src/etc/inc/{dyndns.class => plugins.inc.d/dyndns/phpdns.inc} (99%) rename src/etc/inc/{dyndns.r53.class => plugins.inc.d/dyndns/r53.inc} (100%) diff --git a/plist b/plist index 17e0da83f..3d6cf7672 100644 --- a/plist +++ b/plist @@ -15,8 +15,6 @@ /usr/local/etc/inc/config.inc /usr/local/etc/inc/config.lib.inc /usr/local/etc/inc/crypt.inc -/usr/local/etc/inc/dyndns.class -/usr/local/etc/inc/dyndns.r53.class /usr/local/etc/inc/filter.inc /usr/local/etc/inc/filter.lib.inc /usr/local/etc/inc/filter_log.inc @@ -36,6 +34,9 @@ /usr/local/etc/inc/notices.smtp.inc /usr/local/etc/inc/plugins.inc /usr/local/etc/inc/plugins.inc.d/dnsmasq.inc +/usr/local/etc/inc/plugins.inc.d/dyndns.inc +/usr/local/etc/inc/plugins.inc.d/dyndns/phpdns.inc +/usr/local/etc/inc/plugins.inc.d/dyndns/r53.inc /usr/local/etc/inc/plugins.inc.d/ipfw.inc /usr/local/etc/inc/plugins.inc.d/ipsec.inc /usr/local/etc/inc/plugins.inc.d/ipsec/auth-user.php diff --git a/src/etc/inc/plugins.inc.d/dyndns.inc b/src/etc/inc/plugins.inc.d/dyndns.inc new file mode 100644 index 000000000..cdf91a5b5 --- /dev/null +++ b/src/etc/inc/plugins.inc.d/dyndns.inc @@ -0,0 +1,140 @@ + + Copyright (C) 2010 Ermal Luci + Copyright (C) 2005-2006 Colin Smith + Copyright (C) 2003-2004 Manuel Kasper + 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('plugins.inc.d/dyndns/phpdns.inc'); +require_once('plugins.inc.d/dyndns/r53.inc'); + +function dyndns_configure() +{ + return array( + 'local' => array('dyndns_configure_do'), + 'interface' => array('dyndns_configure_do:2'), + ); +} + +function dyndns_list() +{ + return array( + 'citynetwork' => 'City Network', + 'cloudflare' => 'CloudFlare', + 'custom' => 'Custom', + 'custom-v6' => 'Custom (v6)', + 'dhs' => 'DHS', + 'dnsexit' => 'DNSexit', + 'dnsomatic' => 'DNS-O-Matic', + 'duckdns' => 'Duck DNS', + 'dyndns' => 'DynDNS (dynamic)', + 'dyndns-static' => 'DynDNS (static)', + 'dyndns-custom' => 'DynDNS (custom)', + 'dyns' => 'DyNS', + 'easydns' => 'easyDNS', + 'eurodns' => 'EuroDNS', + 'freedns' => 'freeDNS', + 'gratisdns' => 'GratisDNS', + 'googledomains' => 'Google Domains', + 'he-net' => 'HE.net', + 'he-net-v6' => 'HE.net (v6)', + 'he-net-tunnelbroker' => 'HE.net Tunnelbroker', + 'loopia' => 'Loopia', + 'namecheap' => 'Namecheap', + 'noip' => 'No-IP', + 'noip-free' => 'No-IP (free)', + 'ods' => 'ODS.org', + 'opendns' => 'OpenDNS', + 'ovh-dynhost' => 'OVH DynHOST', + 'route53' => 'Route 53', + 'selfhost' => 'SelfHost', + 'zoneedit' => 'ZoneEdit', + ); +} + +function dyndns_configure_client($conf) +{ + if (!isset($conf['enable'])) { + return; + } + + $dns = new updatedns($dnsService = $conf['type'], + $dnsHost = $conf['host'], + $dnsUser = $conf['username'], + $dnsPass = $conf['password'], + $dnsWilcard = $conf['wildcard'], + $dnsMX = $conf['mx'], + $dnsIf = "{$conf['interface']}", + $dnsBackMX = NULL, + $dnsServer = NULL, + $dnsPort = NULL, + $dnsUpdateURL = "{$conf['updateurl']}", + $forceUpdate = $conf['force'], + $dnsZoneID=$conf['zoneid'], + $dnsTTL=$conf['ttl'], + $dnsResultMatch = "{$conf['resultmatch']}", + $dnsRequestIf = "{$conf['requestif']}", + $dnsID = "{$conf['id']}", + $dnsVerboseLog = $conf['verboselog'], + $curlIpresolveV4 = $conf['curl_ipresolve_v4'], + $curlSslVerifypeer = $conf['curl_ssl_verifypeer'] + ); +} + +function dyndns_configure_do($verbose = false, $int = '') +{ + global $config; + + if (!isset($config['dyndnses']['dyndns'])) { + return; + } + + $dyndnscfg = $config['dyndnses']['dyndns']; + $gwgroups = return_gateway_groups_array(); + if (!is_array($dyndnscfg)) { + return; + } + + if ($verbose) { + echo 'Starting dynamic DNS clients...'; + flush(); + } + + foreach ($dyndnscfg as $dyndns) { + if ((empty($int)) || ($int == $dyndns['interface']) || (is_array($gwgroups[$dyndns['interface']]))) { + $dyndns['verboselog'] = isset($dyndns['verboselog']); + $dyndns['curl_ipresolve_v4'] = isset($dyndns['curl_ipresolve_v4']); + $dyndns['curl_ssl_verifypeer'] = isset($dyndns['curl_ssl_verifypeer']); + dyndns_configure_client($dyndns); + sleep(1); + } + } + + if ($verbose) { + echo "done.\n"; + } +} diff --git a/src/etc/inc/dyndns.class b/src/etc/inc/plugins.inc.d/dyndns/phpdns.inc similarity index 99% rename from src/etc/inc/dyndns.class rename to src/etc/inc/plugins.inc.d/dyndns/phpdns.inc index c4799671a..db42321b4 100644 --- a/src/etc/inc/dyndns.class +++ b/src/etc/inc/plugins.inc.d/dyndns/phpdns.inc @@ -544,10 +544,6 @@ $NewIP=$this->_dnsIP; $NewTTL=$this->_dnsTTL; - /* Include Route 53 Library Class (and util.inc for log_error) */ - require_once('util.inc'); - require_once('dyndns.r53.class'); - /* Set Amazon AWS Credentials for this record */ $r53 = new Route53($AccessKeyId, $SecretAccessKey); diff --git a/src/etc/inc/dyndns.r53.class b/src/etc/inc/plugins.inc.d/dyndns/r53.inc similarity index 100% rename from src/etc/inc/dyndns.r53.class rename to src/etc/inc/plugins.inc.d/dyndns/r53.inc diff --git a/src/etc/inc/services.inc b/src/etc/inc/services.inc index f8c76dc1a..78fd722a4 100644 --- a/src/etc/inc/services.inc +++ b/src/etc/inc/services.inc @@ -44,7 +44,7 @@ * targets in the future: */ require_once('plugins.inc.d/dnsmasq.inc'); -require_once('dyndns.class'); /* XXX move to plugin */ +require_once('plugins.inc.d/dyndns.inc'); require_once('plugins.inc.d/ipsec.inc'); require_once('plugins.inc.d/openvpn.inc'); require_once('plugins.inc.d/rfc2136.inc'); @@ -1550,103 +1550,6 @@ function services_dhcrelay6_configure($verbose = false) } } -function services_dyndns_list() -{ - return array( - 'citynetwork' => 'City Network', - 'cloudflare' => 'CloudFlare', - 'custom' => 'Custom', - 'custom-v6' => 'Custom (v6)', - 'dhs' => 'DHS', - 'dnsexit' => 'DNSexit', - 'dnsomatic' => 'DNS-O-Matic', - 'duckdns' => 'Duck DNS', - 'dyndns' => 'DynDNS (dynamic)', - 'dyndns-static' => 'DynDNS (static)', - 'dyndns-custom' => 'DynDNS (custom)', - 'dyns' => 'DyNS', - 'easydns' => 'easyDNS', - 'eurodns' => 'EuroDNS', - 'freedns' => 'freeDNS', - 'gratisdns' => 'GratisDNS', - 'googledomains' => 'Google Domains', - 'he-net' => 'HE.net', - 'he-net-v6' => 'HE.net (v6)', - 'he-net-tunnelbroker' => 'HE.net Tunnelbroker', - 'loopia' => 'Loopia', - 'namecheap' => 'Namecheap', - 'noip' => 'No-IP', - 'noip-free' => 'No-IP (free)', - 'ods' => 'ODS.org', - 'opendns' => 'OpenDNS', - 'ovh-dynhost' => 'OVH DynHOST', - 'route53' => 'Route 53', - 'selfhost' => 'SelfHost', - 'zoneedit' => 'ZoneEdit', - ); -} - -function services_dyndns_configure_client($conf) -{ - if (!isset($conf['enable'])) { - return; - } - - $dns = new updatedns($dnsService = $conf['type'], - $dnsHost = $conf['host'], - $dnsUser = $conf['username'], - $dnsPass = $conf['password'], - $dnsWilcard = $conf['wildcard'], - $dnsMX = $conf['mx'], - $dnsIf = "{$conf['interface']}", - $dnsBackMX = NULL, - $dnsServer = NULL, - $dnsPort = NULL, - $dnsUpdateURL = "{$conf['updateurl']}", - $forceUpdate = $conf['force'], - $dnsZoneID=$conf['zoneid'], - $dnsTTL=$conf['ttl'], - $dnsResultMatch = "{$conf['resultmatch']}", - $dnsRequestIf = "{$conf['requestif']}", - $dnsID = "{$conf['id']}", - $dnsVerboseLog = $conf['verboselog'], - $curlIpresolveV4 = $conf['curl_ipresolve_v4'], - $curlSslVerifypeer = $conf['curl_ssl_verifypeer'] - ); -} - -function services_dyndns_configure($int = '', $verbose = false) -{ - global $config; - - if (isset($config['dyndnses']['dyndns'])) { - $dyndnscfg = $config['dyndnses']['dyndns']; - $gwgroups = return_gateway_groups_array(); - if (is_array($dyndnscfg)) { - if ($verbose) { - echo 'Starting dynamic DNS clients...'; - flush(); - } - - foreach ($dyndnscfg as $dyndns) { - if ((empty($int)) || ($int == $dyndns['interface']) || (is_array($gwgroups[$dyndns['interface']]))) { - $dyndns['verboselog'] = isset($dyndns['verboselog']); - $dyndns['curl_ipresolve_v4'] = isset($dyndns['curl_ipresolve_v4']); - $dyndns['curl_ssl_verifypeer'] = isset($dyndns['curl_ssl_verifypeer']); - services_dyndns_configure_client($dyndns); - sleep(1); - } - } - - if ($verbose) { - echo "done.\n"; - } - } - } - - return 0; -} - function dyndnsCheckIP($int) { global $config; diff --git a/src/etc/rc.dyndns.update b/src/etc/rc.dyndns.update index 737c77d88..8f15d6e20 100755 --- a/src/etc/rc.dyndns.update +++ b/src/etc/rc.dyndns.update @@ -42,13 +42,13 @@ if (isset($argv[1])) { } if (empty($argument)) { - services_dyndns_configure(); - rfc2136_configure_do(false); + dyndns_configure_do(); + rfc2136_configure_do(); } else { $interface = lookup_gateway_interface_by_name($argument); if (empty($interface)) { $interface = $argument; } - services_dyndns_configure($interface); + dyndns_configure_do(false, $interface); rfc2136_configure_do(false, $interface); } diff --git a/src/etc/rc.newwanip b/src/etc/rc.newwanip index 16a98177e..a017d8f23 100755 --- a/src/etc/rc.newwanip +++ b/src/etc/rc.newwanip @@ -181,9 +181,6 @@ if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interface @file_put_contents("/var/db/{$interface}_cacheip", $curwanip); } - /* signal dyndns update */ - services_dyndns_configure($interface); - /* start OpenVPN server & clients */ if (substr($interface_real, 0, 4) != "ovpn") { openvpn_resync_all($interface); diff --git a/src/etc/rc.newwanipv6 b/src/etc/rc.newwanipv6 index 771f6a1f6..1849facde 100755 --- a/src/etc/rc.newwanipv6 +++ b/src/etc/rc.newwanipv6 @@ -137,9 +137,6 @@ if (is_ipaddrv6($oldipv6)) { file_put_contents("/var/db/{$interface}_cacheipv6", $curwanipv6); } -/* signal dyndns update */ -services_dyndns_configure($interface); - /* start OpenVPN server & clients */ if (substr($interface_real, 0, 4) != 'ovpn') { openvpn_resync_all($interface); diff --git a/src/etc/rc.reload_all b/src/etc/rc.reload_all index 641f4a181..be429a844 100755 --- a/src/etc/rc.reload_all +++ b/src/etc/rc.reload_all @@ -60,7 +60,6 @@ system_hosts_generate(true); system_resolvconf_generate(true); services_dhcpd_configure('all', array(), true); interfaces_configure(true); -services_dyndns_configure('', true); system_cron_configure(true); mwexec_bg('/usr/local/etc/rc.sshd'); diff --git a/src/www/services_dyndns.php b/src/www/services_dyndns.php index bd97504cb..c6dd653bf 100644 --- a/src/www/services_dyndns.php +++ b/src/www/services_dyndns.php @@ -30,7 +30,7 @@ require_once("guiconfig.inc"); require_once("interfaces.inc"); require_once("services.inc"); -require_once("interfaces.inc"); +require_once("plugins.inc.d/dyndns.inc"); if (empty($config['dyndnses']['dyndns']) || !isset($config['dyndnses']['dyndns'])) { $config['dyndnses']['dyndns'] = array(); @@ -136,7 +136,7 @@ $main_buttons = array( - +