From 6c12c28d50538265ad41b1be1015ea6acfaf26b2 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Thu, 30 Nov 2023 19:29:53 -0600 Subject: ddclient: T5791: Update dynamic dns configuration path Modify the configuration path to be consistent with the usual dialects of VyoS configuration (wireguard, dns, firewall, etc.) This would also shorten the configuration path and have a unified treatment for RFC2136-based updates and other 'web-service' based updates. While at it, add support for per-service web-options. This would allow for probing different external URLs on a per-service basis. --- interface-definitions/dns-dynamic.xml.in | 226 +++++++++++++++++++------------ 1 file changed, 138 insertions(+), 88 deletions(-) (limited to 'interface-definitions') diff --git a/interface-definitions/dns-dynamic.xml.in b/interface-definitions/dns-dynamic.xml.in index 32c5af9b6..f089f0e52 100644 --- a/interface-definitions/dns-dynamic.xml.in +++ b/interface-definitions/dns-dynamic.xml.in @@ -12,27 +12,48 @@ Dynamic DNS - + - Obtain IP address to send Dynamic DNS update for + Dynamic DNS configuration txt - Use interface to obtain the IP address + Dynamic DNS service name - - web - Use HTTP(S) web request to obtain the IP address - - - - web - - - #include - web - + #include + + + ddclient protocol used for Dynamic DNS service + + + + + + + + + + + Obtain IP address to send Dynamic DNS update for + + txt + Use interface to obtain the IP address + + + web + Use HTTP(S) web request to obtain the IP address + + + + web + + + #include + web + + + Options when using HTTP(S) web request to obtain the IP address @@ -50,88 +71,117 @@ - + - RFC2136 nsupdate configuration + IP address version to use - txt - RFC2136 nsupdate service name + _ipv4 + Use only IPv4 address + + + _ipv6 + Use only IPv6 address + + both + Use both IPv4 and IPv6 address + + + ipv4 ipv6 both + + + (ipv[46]|both) + + IP Version must be literal 'ipv4', 'ipv6' or 'both' - - #include - #include - #include - - - File containing the TSIG secret key shared with remote DNS server - - filename - File in /config/auth directory - - - - - - - #include - #include - - - + ipv4 + + + + Hostname to register with Dynamic DNS service + + #include + (\@|\*)[-.A-Za-z0-9]* + + Host-name must be alphanumeric, can contain hyphens and can be prefixed with '@' or '*' + + + + - Dynamic DNS configuration + Remote Dynamic DNS server to send updates to + + ipv4 + IPv4 address of the remote server + + + ipv6 + IPv6 address of the remote server + + + hostname + Fully qualified domain name of the remote server + + + + + + Remote server must be IP address or fully qualified domain name + + + + + DNS zone to be updated txt - Dynamic DNS service name + Name of DNS zone + + + - - #include - #include - #include - #include - #include - #include - - - ddclient protocol used for Dynamic DNS service - - - - - - - - - #include - - - IP address version to use - - _ipv4 - Use only IPv4 address - - - _ipv6 - Use only IPv6 address - - - both - Use both IPv4 and IPv6 address - - - ipv4 ipv6 both - - - (ipv[46]|both) - - IP Version must be literal 'ipv4', 'ipv6' or 'both' - - ipv4 - - - + + #include + #include + + + File containing TSIG authentication key for RFC2136 nsupdate on remote DNS server + + filename + File in /config/auth directory + + + + + + + #include + + + Time in seconds to wait between update attempts + + u32:60-86400 + Time in seconds + + + + + Wait time must be between 60 and 86400 seconds + + + + + Time in seconds for the hostname to be marked expired in cache + + u32:300-2160000 + Time in seconds + + + + + Expiry time must be between 300 and 2160000 seconds + + -- cgit v1.2.3 From 54591d0c477c188a95edafeb5ebb5ec5a2bf66eb Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Thu, 30 Nov 2023 19:31:00 -0600 Subject: ddclient: T5791: Remove XML includes that aren't used anymore As followup to interface definition change, remove XML snippets that aren't used anymore. They were there because they were 'include'-ed multiple times in the interface definition `dynamic-dns.xml.in`. Since that's not the case anymore, they can be removed. --- .../dns/dynamic-service-host-name-server.xml.i | 35 ---------------------- .../dns/dynamic-service-wait-expiry-time.xml.i | 28 ----------------- .../include/dns/dynamic-service-zone.xml.i | 14 --------- 3 files changed, 77 deletions(-) delete mode 100644 interface-definitions/include/dns/dynamic-service-host-name-server.xml.i delete mode 100644 interface-definitions/include/dns/dynamic-service-wait-expiry-time.xml.i delete mode 100644 interface-definitions/include/dns/dynamic-service-zone.xml.i (limited to 'interface-definitions') diff --git a/interface-definitions/include/dns/dynamic-service-host-name-server.xml.i b/interface-definitions/include/dns/dynamic-service-host-name-server.xml.i deleted file mode 100644 index 9dd14f97c..000000000 --- a/interface-definitions/include/dns/dynamic-service-host-name-server.xml.i +++ /dev/null @@ -1,35 +0,0 @@ - - - - Hostname to register with Dynamic DNS service - - #include - (\@|\*)[-.A-Za-z0-9]* - - Host-name must be alphanumeric, can contain hyphens and can be prefixed with '@' or '*' - - - - - - Remote Dynamic DNS server to send updates to - - ipv4 - IPv4 address of the remote server - - - ipv6 - IPv6 address of the remote server - - - hostname - Fully qualified domain name of the remote server - - - - - - Remote server must be IP address or fully qualified domain name - - - diff --git a/interface-definitions/include/dns/dynamic-service-wait-expiry-time.xml.i b/interface-definitions/include/dns/dynamic-service-wait-expiry-time.xml.i deleted file mode 100644 index 866690cbe..000000000 --- a/interface-definitions/include/dns/dynamic-service-wait-expiry-time.xml.i +++ /dev/null @@ -1,28 +0,0 @@ - - - - Time in seconds to wait between update attempts - - u32:60-86400 - Time in seconds - - - - - Wait time must be between 60 and 86400 seconds - - - - - Time in seconds for the hostname to be marked expired in cache - - u32:300-2160000 - Time in seconds - - - - - Expiry time must be between 300 and 2160000 seconds - - - diff --git a/interface-definitions/include/dns/dynamic-service-zone.xml.i b/interface-definitions/include/dns/dynamic-service-zone.xml.i deleted file mode 100644 index 0cc00468f..000000000 --- a/interface-definitions/include/dns/dynamic-service-zone.xml.i +++ /dev/null @@ -1,14 +0,0 @@ - - - - DNS zone to be updated - - txt - Name of DNS zone - - - - - - - -- cgit v1.2.3 From 7cf735e11033bfaebf68c8544b7e77c8b28c5670 Mon Sep 17 00:00:00 2001 From: Indrajit Raychaudhuri Date: Thu, 30 Nov 2023 19:16:53 -0600 Subject: ddclient: T5791: Migration script for dynamic dns config path change --- .../include/version/dns-dynamic-version.xml.i | 2 +- src/migration-scripts/dns-dynamic/2-to-3 | 85 ++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 src/migration-scripts/dns-dynamic/2-to-3 (limited to 'interface-definitions') diff --git a/interface-definitions/include/version/dns-dynamic-version.xml.i b/interface-definitions/include/version/dns-dynamic-version.xml.i index 7bdb90a35..773a6ab51 100644 --- a/interface-definitions/include/version/dns-dynamic-version.xml.i +++ b/interface-definitions/include/version/dns-dynamic-version.xml.i @@ -1,3 +1,3 @@ - + diff --git a/src/migration-scripts/dns-dynamic/2-to-3 b/src/migration-scripts/dns-dynamic/2-to-3 new file mode 100644 index 000000000..02bc9324a --- /dev/null +++ b/src/migration-scripts/dns-dynamic/2-to-3 @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2023 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# T5791: +# - migrate "service dns dynamic address web web-options ..." +# to "service dns dynamic name address web ..." (per service) +# - migrate "service dns dynamic address
rfc2136 ..." +# to "service dns dynamic name address protocol 'nsupdate'" +# - migrate "service dns dynamic address service ..." +# to "service dns dynamic name address ..." + +import sys +from vyos.configtree import ConfigTree + +if len(sys.argv) < 2: + print("Must specify file name!") + sys.exit(1) + +file_name = sys.argv[1] + +with open(file_name, 'r') as f: + config_file = f.read() + +config = ConfigTree(config_file) + +base_path = ['service', 'dns', 'dynamic'] +address_path = base_path + ['address'] +name_path = base_path + ['name'] + +if not config.exists(address_path): + # Nothing to do + sys.exit(0) + +# config.copy does not recursively create a path, so initialize the name path +if not config.exists(name_path): + config.set(name_path) + +for address in config.list_nodes(address_path): + + # Move web-option as a configuration in each service instead of top level web-option + if config.exists(address_path + [address, 'web-options']) and address == 'web': + for svc_type in ['service', 'rfc2136']: + if config.exists(address_path + [address, svc_type]): + for svc_cfg in config.list_nodes(address_path + [address, svc_type]): + config.copy(address_path + [address, 'web-options'], + address_path + [address, svc_type, svc_cfg, 'web-options']) + config.delete(address_path + [address, 'web-options']) + + for svc_type in ['service', 'rfc2136']: + if config.exists(address_path + [address, svc_type]): + # Move RFC2136 as service configuration, rename to avoid name conflict and set protocol to 'nsupdate' + if svc_type == 'rfc2136': + for rfc_cfg_old in config.list_nodes(address_path + [address, 'rfc2136']): + rfc_cfg_new = f'{rfc_cfg_old}-rfc2136' + config.rename(address_path + [address, 'rfc2136', rfc_cfg_old], rfc_cfg_new) + config.set(address_path + [address, 'rfc2136', rfc_cfg_new, 'protocol'], 'nsupdate') + + # Add address as config value in each service before moving the service path + # And then copy the services from 'address service ' to 'name ' + for svc_cfg in config.list_nodes(address_path + [address, svc_type]): + config.set(address_path + [address, svc_type, svc_cfg, 'address'], address) + config.copy(address_path + [address, svc_type, svc_cfg], name_path + [svc_cfg]) + +# Finally cleanup the old address path +config.delete(address_path) + +try: + with open(file_name, 'w') as f: + f.write(config.to_string()) +except OSError as e: + print("Failed to save the modified config: {}".format(e)) + sys.exit(1) -- cgit v1.2.3