diff options
-rwxr-xr-x | src/conf_mode/dynamic_dns.py | 47 |
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__': |