summaryrefslogtreecommitdiff
path: root/src/op_mode/dynamic_dns.py
diff options
context:
space:
mode:
authorIndrajit Raychaudhuri <irc@indrajit.com>2023-04-17 16:19:26 -0500
committerIndrajit Raychaudhuri <irc@indrajit.com>2023-04-17 18:09:36 -0500
commit84e9b48405017f718daa35a0e8b5d5c07d40ae3f (patch)
tree3652c055f398d9b15a2b3cd12ef51d052110904e /src/op_mode/dynamic_dns.py
parentcdad13fecc8eae760634069218bd33c1bc6f767a (diff)
downloadvyos-1x-84e9b48405017f718daa35a0e8b5d5c07d40ae3f.tar.gz
vyos-1x-84e9b48405017f718daa35a0e8b5d5c07d40ae3f.zip
dns: T5144: Make dns dynamic status output legacy format compatible
Adjust the output of dynamic dns status to be compatible with both legacy and new ddclient cache format. This is necessary because the legacy format is still used by some of the dyndns2 family of protocols. This is a follow-up to commit 3f3621b6874354.
Diffstat (limited to 'src/op_mode/dynamic_dns.py')
-rwxr-xr-xsrc/op_mode/dynamic_dns.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/op_mode/dynamic_dns.py b/src/op_mode/dynamic_dns.py
index 2cba33cc8..d41a74db3 100755
--- a/src/op_mode/dynamic_dns.py
+++ b/src/op_mode/dynamic_dns.py
@@ -21,6 +21,7 @@ import time
from tabulate import tabulate
from vyos.config import Config
+from vyos.template import is_ipv4, is_ipv6
from vyos.util import call
cache_file = r'/run/ddclient/ddclient.cache'
@@ -46,7 +47,7 @@ def _get_formatted_host_records(host_data):
def show_status():
- # A ddclient status file must not always exist
+ # A ddclient status file might not always exist
if not os.path.exists(cache_file):
sys.exit(0)
@@ -62,9 +63,20 @@ def show_status():
# we pick up the ones we are interested in
for kvraw in line.split(' ')[0].split(','):
k, v = kvraw.split('=')
- if k in columns.keys():
+ if k in list(columns.keys()) + ['ip', 'status']: # ip and status are legacy 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(