[enh] Add some comments.

This commit is contained in:
opi 2016-04-26 12:03:18 +02:00
parent c83fecdb08
commit 87acdfaf80

View file

@ -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: