summaryrefslogtreecommitdiff
path: root/src/conf_mode/dynamic_dns.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2018-07-29 20:22:48 +0200
committerChristian Poessinger <christian@poessinger.com>2018-07-29 20:22:48 +0200
commit078b328685493e27c2ea48206b3f72a3a0c42e20 (patch)
tree9f9306702282da57e15f2f1dcaf896b3c31fa2b2 /src/conf_mode/dynamic_dns.py
parent3a02c31b5bc271f215faf5a7bdb0b4c6c21ef7d6 (diff)
downloadvyos-1x-078b328685493e27c2ea48206b3f72a3a0c42e20.tar.gz
vyos-1x-078b328685493e27c2ea48206b3f72a3a0c42e20.zip
T758: refactor ddclient configuration file amd startup
Since version 3.8.0 ddclient support the update of multiple ip's. The need for running multiple ddclient instances with different configuration files is thus no longer necessary. More information can be found on the ddclient forum: https://sourceforge.net/p/ddclient/mailman/message/20383414/
Diffstat (limited to 'src/conf_mode/dynamic_dns.py')
-rwxr-xr-xsrc/conf_mode/dynamic_dns.py47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/conf_mode/dynamic_dns.py b/src/conf_mode/dynamic_dns.py
index aabd2c499..90d4ff567 100755
--- a/src/conf_mode/dynamic_dns.py
+++ b/src/conf_mode/dynamic_dns.py
@@ -23,23 +23,28 @@ import jinja2
from vyos.config import Config
from vyos import ConfigError
-config_dir = r'/etc/ddclient/'
-config_file = config_dir + 'ddclient_{0}.conf'
+config_file = r'/etc/ddclient.conf'
config_tmpl = """
### Autogenerated by dynamic_dns.py ###
daemon=1m
syslog=yes
ssl=yes
-pid=/var/run/ddclient/ddclient_{{ interface }}.pid
-cache=/var/cache/ddclient/ddclient_{{ interface }}.cache
-{% if web_url and web_skip -%}
-use=web, web={{ web_url}}, web-skip={{ web_skip }}
+pid=/var/run/ddclient/ddclient.pid
+cache=/var/cache/ddclient/ddclient.cache
+
+{% for interface in interfaces -%}
+
+#
+# ddclient configuration for interface "{{ interface.interface }}":
+#
+{% if interface.web_url and interface.web_skip -%}
+use=web, web={{ interface.web_url}}, web-skip={{ interface.web_skip }}
{% else -%}
-use=if, if={{ interface }}
+use=if, if={{ interface.interface }}
{% endif -%}
-{% for rfc in rfc2136 -%}
+{% for rfc in interface.rfc2136 -%}
{% for record in rfc.record %}
# RFC2136 dynamic DNS configuration for {{ record }}.{{ rfc.zone }}
server={{ rfc.server }}
@@ -48,10 +53,10 @@ password={{ rfc.keyfile }}
ttl={{ rfc.ttl }}
zone={{ rfc.zone }}
{{ record }}
-{% endfor %}
+{% endfor -%}
{% endfor -%}
-{% for srv in service %}
+{% for srv in interface.service %}
{% for host in srv.host %}
# DynDNS provider configuration for {{ host }}
protocol={{ srv.protocol }}
@@ -61,6 +66,8 @@ password='{{ srv.password }}'
{{ host }}
{% endfor %}
{% endfor %}
+
+{% endfor %}
"""
# Mapping of service name to service protocol
@@ -226,20 +233,20 @@ def generate(dyndns):
if dyndns is None:
return None
- if not os.path.exists(config_dir):
- os.makedirs(config_dir)
-
- for node in dyndns['interfaces']:
- tmpl = jinja2.Template(config_tmpl)
+ tmpl = jinja2.Template(config_tmpl)
- config_text = tmpl.render(node)
- with open(config_file.format(node['interface']), 'w') as f:
- f.write(config_text)
+ config_text = tmpl.render(dyndns)
+ with open(config_file, 'w') as f:
+ f.write(config_text)
return None
-def apply(dns):
- raise ConfigError("error")
+def apply(dyndns):
+ if dyndns is None:
+ os.system('/etc/init.d/ddclient stop')
+ else:
+ os.system('/etc/init.d/ddclient restart')
+
return None
if __name__ == '__main__':