diff options
Diffstat (limited to 'src')
| -rwxr-xr-x | src/completion/list_ddclient_protocols.sh | 2 | ||||
| -rwxr-xr-x | src/conf_mode/service_dns_dynamic.py | 204 | ||||
| -rw-r--r-- | src/migration-scripts/dns-dynamic/4-to-5 | 53 | ||||
| -rwxr-xr-x | src/op_mode/dns.py | 14 | ||||
| -rwxr-xr-x | src/validators/ddclient-protocol | 2 |
5 files changed, 214 insertions, 61 deletions
diff --git a/src/completion/list_ddclient_protocols.sh b/src/completion/list_ddclient_protocols.sh index 0c8c2712d..d92239270 100755 --- a/src/completion/list_ddclient_protocols.sh +++ b/src/completion/list_ddclient_protocols.sh @@ -14,4 +14,4 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -echo -n $(ddclient -list-protocols | grep -vE 'cloudns|porkbun') +echo -n $(ddclient --list-protocols | grep -vE 'cloudns|directnic|emailonly') diff --git a/src/conf_mode/service_dns_dynamic.py b/src/conf_mode/service_dns_dynamic.py index b321d5f51..b6daba6ff 100755 --- a/src/conf_mode/service_dns_dynamic.py +++ b/src/conf_mode/service_dns_dynamic.py @@ -27,33 +27,89 @@ from vyos.utils.process import call from vyos.utils.network import interface_exists from vyos import ConfigError from vyos import airbag + airbag.enable() config_file = r'/run/ddclient/ddclient.conf' systemd_override = r'/run/systemd/system/ddclient.service.d/override.conf' # Protocols that require zone -zone_necessary = ['cloudflare', 'digitalocean', 'godaddy', 'hetzner', 'gandi', - 'nfsn', 'nsupdate'] -zone_supported = zone_necessary + ['dnsexit2', 'zoneedit1'] +zone_necessary = [ + 'cloudflare', + 'digitalocean', + 'godaddy', + 'hetzner', + 'gandi', + 'nfsn', + 'nsupdate', +] +zone_supported = zone_necessary + ['dnsexit2', 'porkbun', 'zoneedit1'] # Protocols that do not require username -username_unnecessary = ['1984', 'cloudflare', 'cloudns', 'digitalocean', 'dnsexit2', - 'duckdns', 'freemyip', 'hetzner', 'keysystems', 'njalla', - 'nsupdate', 'regfishde'] +username_unnecessary = [ + '1984', + 'cloudflare', + 'cloudns', + 'ddns.fm', + 'digitalocean', + 'dnsexit2', + 'duckdns', + 'freemyip', + 'gandi', + 'he.net', + 'hetzner', + 'keysystems', + 'njalla', + 'nsupdate', + 'regfishde', +] # Protocols that support TTL -ttl_supported = ['cloudflare', 'dnsexit2', 'gandi', 'hetzner', 'godaddy', 'nfsn', - 'nsupdate'] +ttl_supported = [ + 'cloudflare', + 'dnsexit2', + 'gandi', + 'hetzner', + 'godaddy', + 'nfsn', + 'nsupdate', + 'porkbun', +] # Protocols that support both IPv4 and IPv6 -dualstack_supported = ['cloudflare', 'digitalocean', 'dnsexit2', 'duckdns', - 'dyndns2', 'easydns', 'freedns', 'hetzner', 'infomaniak', - 'njalla'] +dualstack_supported = [ + 'cloudflare', + 'ddns.fm', + 'digitalocean', + 'dnsexit2', + 'domeneshop', + 'duckdns', + 'dyndns2', + 'easydns', + 'freedns', + 'gandi', + 'godaddy', + 'he.net', + 'hetzner', + 'infomaniak', + 'inwx', + 'mythicdyn', + 'njalla', + 'noip', + 'nsupdate', + 'porkbun', + 'regfishde', +] # dyndns2 protocol in ddclient honors dual stack for selective servers # because of the way it is implemented in ddclient -dyndns_dualstack_servers = ['members.dyndns.org', 'dynv6.com'] +dyndns_dualstack_servers = [ + 'app.luadns.com', + 'dynv6.com', + 'members.dyndns.org', + 'update.dedyn.io', +] + def get_config(config=None): if config: @@ -65,14 +121,18 @@ def get_config(config=None): if not conf.exists(base): return None - dyndns = conf.get_config_dict(base, key_mangling=('-', '_'), - no_tag_node_value_mangle=True, - get_first_key=True, - with_recursive_defaults=True) + dyndns = conf.get_config_dict( + base, + key_mangling=('-', '_'), + no_tag_node_value_mangle=True, + get_first_key=True, + with_recursive_defaults=True, + ) dyndns['config_file'] = config_file return dyndns + def verify(dyndns): # bail out early - looks like removal from running config if not dyndns or 'name' not in dyndns: @@ -88,11 +148,15 @@ def verify(dyndns): raise ConfigError(f'"{field.replace("_", "-")}" {error_msg_req}') if not any(x in config['address'] for x in ['interface', 'web']): - raise ConfigError(f'Either "interface" or "web" {error_msg_req} ' - f'with protocol "{config["protocol"]}"') + raise ConfigError( + f'Either "interface" or "web" {error_msg_req} ' + f'with protocol "{config["protocol"]}"' + ) if all(x in config['address'] for x in ['interface', 'web']): - raise ConfigError(f'Both "interface" and "web" at the same time {error_msg_uns} ' - f'with protocol "{config["protocol"]}"') + raise ConfigError( + f'Both "interface" and "web" at the same time {error_msg_uns} ' + f'with protocol "{config["protocol"]}"' + ) # If dyndns address is an interface, ensure that the interface exists # and warn if a non-active dynamic interface is used @@ -101,22 +165,22 @@ def verify(dyndns): # exclude check interface for dynamic interfaces if tmp.match(config['address']['interface']): if not interface_exists(config['address']['interface']): - Warning(f'Interface "{config["address"]["interface"]}" does not exist yet and ' - f'cannot be used for Dynamic DNS service "{service}" until it is up!') + Warning( + f'Interface "{config["address"]["interface"]}" does not exist yet and ' + f'cannot be used for Dynamic DNS service "{service}" until it is up!' + ) else: verify_interface_exists(dyndns, config['address']['interface']) if 'web' in config['address']: # If 'skip' is specified, 'url' is required as well - if 'skip' in config['address']['web'] and 'url' not in config['address']['web']: - raise ConfigError(f'"url" along with "skip" {error_msg_req} ' - f'with protocol "{config["protocol"]}"') - if 'url' in config['address']['web']: - # Warn if using checkip.dyndns.org, as it does not support HTTPS - # See: https://github.com/ddclient/ddclient/issues/597 - if re.search("^(https?://)?checkip\.dyndns\.org", config['address']['web']['url']): - Warning(f'"checkip.dyndns.org" does not support HTTPS requests for IP address ' - f'lookup. Please use a different IP address lookup service.') + if ( + 'skip' in config['address']['web'] + and 'url' not in config['address']['web'] + ): + raise ConfigError( + f'"url" along with "skip" {error_msg_req} with protocol "{config["protocol"]}"' + ) # RFC2136 uses 'key' instead of 'password' if config['protocol'] != 'nsupdate' and 'password' not in config: @@ -125,47 +189,94 @@ def verify(dyndns): # Other RFC2136 specific configuration validation if config['protocol'] == 'nsupdate': if 'password' in config: - raise ConfigError(f'"password" {error_msg_uns} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"password" {error_msg_uns} with protocol "{config["protocol"]}"' + ) for field in ['server', 'key']: if field not in config: - raise ConfigError(f'"{field}" {error_msg_req} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"{field}" {error_msg_req} with protocol "{config["protocol"]}"' + ) if config['protocol'] in zone_necessary and 'zone' not in config: - raise ConfigError(f'"zone" {error_msg_req} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"zone" {error_msg_req} with protocol "{config["protocol"]}"' + ) if config['protocol'] not in zone_supported and 'zone' in config: - raise ConfigError(f'"zone" {error_msg_uns} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"zone" {error_msg_uns} with protocol "{config["protocol"]}"' + ) if config['protocol'] not in username_unnecessary and 'username' not in config: - raise ConfigError(f'"username" {error_msg_req} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"username" {error_msg_req} with protocol "{config["protocol"]}"' + ) if config['protocol'] not in ttl_supported and 'ttl' in config: - raise ConfigError(f'"ttl" {error_msg_uns} with protocol "{config["protocol"]}"') + raise ConfigError( + f'"ttl" {error_msg_uns} with protocol "{config["protocol"]}"' + ) if config['ip_version'] == 'both': if config['protocol'] not in dualstack_supported: - raise ConfigError(f'Both IPv4 and IPv6 at the same time {error_msg_uns} ' - f'with protocol "{config["protocol"]}"') + raise ConfigError( + f'Both IPv4 and IPv6 at the same time {error_msg_uns} ' + f'with protocol "{config["protocol"]}"' + ) # dyndns2 protocol in ddclient honors dual stack only for dyn.com (dyndns.org) - if config['protocol'] == 'dyndns2' and 'server' in config and config['server'] not in dyndns_dualstack_servers: - raise ConfigError(f'Both IPv4 and IPv6 at the same time {error_msg_uns} ' - f'for "{config["server"]}" with protocol "{config["protocol"]}"') - - if {'wait_time', 'expiry_time'} <= config.keys() and int(config['expiry_time']) < int(config['wait_time']): - raise ConfigError(f'"expiry-time" must be greater than "wait-time" for ' - f'Dynamic DNS service "{service}"') + if ( + config['protocol'] == 'dyndns2' + and 'server' in config + and config['server'] not in dyndns_dualstack_servers + ): + raise ConfigError( + f'Both IPv4 and IPv6 at the same time {error_msg_uns} ' + f'for "{config["server"]}" with protocol "{config["protocol"]}"' + ) + + if {'wait_time', 'expiry_time'} <= config.keys() and int( + config['expiry_time'] + ) < int(config['wait_time']): + raise ConfigError( + f'"expiry-time" must be greater than "wait-time" for ' + f'Dynamic DNS service "{service}"' + ) return None + def generate(dyndns): # bail out early - looks like removal from running config if not dyndns or 'name' not in dyndns: return None + # Adjust protocol specific keys + for name in dyndns['name']: + # nsupdate (RFC2136) uses: + # - 'password' in ddclient.conf instead of 'key' in vyos conf + if dyndns['name'][name]['protocol'] == 'nsupdate': + dyndns['name'][name]['password'] = dyndns['name'][name].pop('key') + + # porkbun uses: + # - 'root-domain' in ddclient.conf instead of 'zone' in vyos conf + # - 'apikey' in ddclient.conf instead of 'username' in vyos conf + # - 'secretapikey' in ddclient.conf instead of 'password' in vyos conf + if dyndns['name'][name]['protocol'] == 'porkbun': + dyndns['name'][name]['apikey'] = dyndns['name'][name].pop('username') + dyndns['name'][name]['secretapikey'] = dyndns['name'][name].pop('password') + if 'zone' in dyndns['name'][name]: + dyndns['name'][name]['root_domain'] = dyndns['name'][name].pop('zone') + + # Gandi API key is deprecated, enforce using personal access token + if dyndns['name'][name]['protocol'] == 'gandi': + dyndns['name'][name]['use_personal_access_token'] = 'yes' + render(config_file, 'dns-dynamic/ddclient.conf.j2', dyndns, permission=0o600) render(systemd_override, 'dns-dynamic/override.conf.j2', dyndns) return None + def apply(dyndns): systemd_service = 'ddclient.service' # Reload systemd manager configuration @@ -181,6 +292,7 @@ def apply(dyndns): return None + if __name__ == '__main__': try: c = get_config() diff --git a/src/migration-scripts/dns-dynamic/4-to-5 b/src/migration-scripts/dns-dynamic/4-to-5 new file mode 100644 index 000000000..3873c00af --- /dev/null +++ b/src/migration-scripts/dns-dynamic/4-to-5 @@ -0,0 +1,53 @@ +# Copyright VyOS maintainers and contributors <maintainers@vyos.io> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this library. If not, see <http://www.gnu.org/licenses/>. + +# T6981: +# - remove "service dns dynamic name <service> protocol googledomains" +# - remove "service dns dynamic name <service> protocol woima" +# - remove "service dns dynamic name <service> address web url ..." +# when url is https://domains.google.com/* + +import re +from vyos.base import Warning +from vyos.configtree import ConfigTree + +base_path = ['service', 'dns', 'dynamic', 'name'] + +def migrate(config: ConfigTree) -> None: + if not config.exists(base_path): + # Nothing to do + return + + for service in config.list_nodes(base_path): + + service_path = base_path + [service] + + # Remove configurations using protocol 'googledomains' and 'woima' + if config.exists(service_path + ['protocol']): + protocol = config.return_value(service_path + ['protocol']) + if protocol in ['googledomains', 'woima']: + Warning(f'Removing {service} using protocol "{protocol}" because the service has been shutdown') + config.delete(service_path) + + # Look for 'address web' with 'url' set to 'googledomains' or 'https://domains.google.com' + # and remove them so that ddclient defaults apply for 'address web' + if config.exists(service_path + ['address', 'web']): + web_addr_path = service_path + ['address', 'web'] + if config.exists(web_addr_path + ['url']): + url = config.return_value(web_addr_path + ['url']) + if url == 'googledomains' or re.search(r'^(https?://)?domains\.google\.com', url): + config.delete(web_addr_path + ['url']) + if config.exists(web_addr_path + ['skip']): + config.delete(web_addr_path + ['skip']) diff --git a/src/op_mode/dns.py b/src/op_mode/dns.py index ee213d5da..a495deff8 100755 --- a/src/op_mode/dns.py +++ b/src/op_mode/dns.py @@ -24,7 +24,6 @@ import vyos.opmode from tabulate import tabulate from vyos.configquery import ConfigTreeQuery from vyos.utils.process import cmdl, rc_cmd -from vyos.template import is_ipv4, is_ipv6 _dynamic_cache_file = r'/run/ddclient/ddclient.cache' @@ -84,20 +83,9 @@ def _get_dynamic_host_records_raw() -> dict: # we pick up the ones we are interested in for kvraw in line.split(' ')[0].split(','): k, v = kvraw.split('=') - if k in list(_dynamic_status_columns.keys()) + ['ip', 'status']: # ip and status are legacy keys + if k in list(_dynamic_status_columns.keys()): props[k] = v - # Extract IPv4 and IPv6 address and status from legacy keys - # Dual-stack isn't supported in legacy format, 'ip' and 'status' are for one of IPv4 or IPv6 - if 'ip' in props: - if is_ipv4(props['ip']): - props['ipv4'] = props['ip'] - props['status-ipv4'] = props['status'] - elif is_ipv6(props['ip']): - props['ipv6'] = props['ip'] - props['status-ipv6'] = props['status'] - del props['ip'] - # Convert mtime to human readable format if 'mtime' in props: props['mtime'] = time.strftime( diff --git a/src/validators/ddclient-protocol b/src/validators/ddclient-protocol index 0d28039d3..bcb2ab8ed 100755 --- a/src/validators/ddclient-protocol +++ b/src/validators/ddclient-protocol @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -ddclient -list-protocols | grep -vE 'cloudns|porkbun' | grep -qw $1 +ddclient --list-protocols | grep -vE 'cloudns|directnic|emailonly' | grep -qw $1 if [ $? -gt 0 ]; then echo "Error: $1 is not a valid protocol, please choose from the supported list of protocols" |
