From 87acdfaf80b54f820ff044cb424466a3f2c29781 Mon Sep 17 00:00:00 2001 From: opi Date: Tue, 26 Apr 2016 12:03:18 +0200 Subject: [PATCH] [enh] Add some comments. --- dynette.cron.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/dynette.cron.py b/dynette.cron.py index f3c0089..8662f5b 100755 --- a/dynette.cron.py +++ b/dynette.cron.py @@ -30,7 +30,10 @@ from urllib import urlopen master_key_path = os.path.join(os.path.dirname(__file__), 'master.key') master_key = open(master_key_path).read().rstrip() +# Bind configuration lines = ['// Generated by Dynette CRON'] + +# Loop through Dynette servers for url in subs_urls: lines.extend([ @@ -40,9 +43,11 @@ for url in subs_urls: '};', ]) + # Get available DynDNS domains domains = json.loads(str(urlopen(url +'/domains').read())) for domain in domains: - result = json.loads(str(urlopen(url +'/all/'+ domain).read())) + + # Create zone database if not present if not os.path.exists(zone_dir + domain +'.db'): db_lines = [ '$ORIGIN .', @@ -63,6 +68,7 @@ for url in subs_urls: with open(zone_dir + domain +'.db', 'w') as zone: for line in db_lines: zone.write(line + '\n') + lines.extend([ 'zone "'+ domain +'" {', ' type master;', @@ -71,6 +77,8 @@ for url in subs_urls: ' grant dynette. wildcard *.'+ domain +'. ANY;', ]) + # Get registered sub-domains + result = json.loads(str(urlopen(url +'/all/'+ domain).read())) for entry in result: for subd, type in allowed_operations.items(): if subd == '.': subd = '' @@ -90,13 +98,18 @@ for url in subs_urls: '};', ]) +# Backup old Bind configuration file. os.system('cp '+ conf_file +' '+ conf_file +'.back') +# Write Bind configuration file. with open(conf_file, 'w') as zone: for line in lines: zone.write(line + '\n') +# Restore ownership os.system('chown -R bind:bind '+ zone_dir +' '+ conf_file) + +# Reload Bind if os.system('/usr/sbin/rndc reload') == 0: exit(0) else: