From 078b328685493e27c2ea48206b3f72a3a0c42e20 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 29 Jul 2018 20:22:48 +0200 Subject: 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/ --- src/conf_mode/dynamic_dns.py | 47 +++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src') 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 }} @@ -60,6 +65,8 @@ login={{ srv.login }} password='{{ srv.password }}' {{ host }} {% endfor %} +{% endfor %} + {% endfor %} """ @@ -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__': -- cgit v1.2.3