2013-06-16 01:06:25 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2013-06-17 10:40:53 +02:00
|
|
|
### Configuration ###
|
2013-06-16 01:06:25 +02:00
|
|
|
|
2013-06-17 10:08:26 +02:00
|
|
|
conf_file = '/etc/bind/named.conf.local' # Include this filename in '/etc/bind/named.conf'
|
|
|
|
zone_dir = '/var/named/data/' # Do not forget the trailing '/'
|
|
|
|
subs_urls = ['http://dyndns.yunohost.org'] # 127.0.0.1 if you install subscribe server locally
|
|
|
|
ns1 = 'dynhost.yunohost.org' # Name servers
|
|
|
|
ns2 = 'hostmaster.yunohost.org'
|
|
|
|
|
|
|
|
allowed_operations = {
|
|
|
|
'.' : ['A', 'TXT', 'MX'],
|
|
|
|
'pubsub.' : ['A'],
|
|
|
|
'muc.' : ['A'],
|
2013-06-17 10:11:03 +02:00
|
|
|
'vjud.' : ['A'],
|
2013-06-17 10:08:26 +02:00
|
|
|
'_xmpp-client._tcp.' : ['SRV'],
|
|
|
|
'_xmpp-server._tcp.' : ['SRV']
|
|
|
|
}
|
|
|
|
|
2013-06-16 09:45:02 +02:00
|
|
|
|
2013-06-17 10:40:53 +02:00
|
|
|
### Script ###
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
from urllib import urlopen
|
|
|
|
|
|
|
|
lines = ['// Generated by Dynette CRON']
|
2013-06-17 10:08:26 +02:00
|
|
|
for url in subs_urls:
|
2013-06-16 09:45:02 +02:00
|
|
|
domains = json.loads(str(urlopen(url +'/domains').read()))
|
|
|
|
|
|
|
|
for domain in domains:
|
2013-06-16 10:39:41 +02:00
|
|
|
result = json.loads(str(urlopen(url +'/all/'+ domain).read()))
|
2013-06-17 10:08:26 +02:00
|
|
|
if not os.path.exists(zone_dir + domain +'.db'):
|
2013-06-16 14:31:31 +02:00
|
|
|
db_lines = [
|
|
|
|
'$ORIGIN .',
|
|
|
|
'$TTL 10 ; 10 seconds',
|
2013-06-17 10:08:26 +02:00
|
|
|
domain+'. IN SOA '+ ns1 +'. '+ ns2 +'. (',
|
2013-06-16 14:31:31 +02:00
|
|
|
' 18 ; serial',
|
|
|
|
' 10800 ; refresh (3 hours)',
|
|
|
|
' 3600 ; retry (1 hour)',
|
|
|
|
' 604800 ; expire (1 week)',
|
|
|
|
' 10 ; minimum (10 seconds)',
|
|
|
|
' )',
|
|
|
|
'$TTL 3600 ; 1 hour',
|
2013-06-17 10:08:26 +02:00
|
|
|
' NS '+ ns1 +'.',
|
|
|
|
' NS '+ ns2 +'.',
|
2013-06-16 14:31:31 +02:00
|
|
|
'',
|
|
|
|
'$ORIGIN '+ domain +'.',
|
|
|
|
]
|
2013-06-17 10:08:26 +02:00
|
|
|
with open(zone_dir + domain +'.db', 'w') as zone:
|
2013-06-16 14:31:31 +02:00
|
|
|
for line in db_lines:
|
|
|
|
zone.write(line + '\n')
|
2013-06-16 09:45:02 +02:00
|
|
|
lines.extend([
|
|
|
|
'zone "'+ domain +'" {',
|
|
|
|
' type master;',
|
2013-06-17 10:08:26 +02:00
|
|
|
' file "'+ zone_dir + domain +'.db"; ',
|
2013-06-16 09:45:02 +02:00
|
|
|
' update-policy {',
|
|
|
|
])
|
|
|
|
|
|
|
|
for entry in result:
|
2013-06-17 10:08:26 +02:00
|
|
|
for subd, type in allowed_operations.items():
|
|
|
|
if subd == '.': subd = ''
|
|
|
|
lines.append(' grant '+ entry['subdomain'] +'. name '+ subd + entry['subdomain'] +'. ' + ' '.join(type) +';')
|
2013-06-16 09:45:02 +02:00
|
|
|
|
|
|
|
lines.extend([
|
|
|
|
' };',
|
|
|
|
'};',
|
|
|
|
])
|
|
|
|
|
|
|
|
for entry in result:
|
|
|
|
lines.extend([
|
2013-06-17 10:08:26 +02:00
|
|
|
'key '+ entry['subdomain'] +'. {',
|
2013-06-16 09:45:02 +02:00
|
|
|
' algorithm hmac-md5;',
|
|
|
|
' secret "'+ entry['public_key'] +'";',
|
|
|
|
'};',
|
|
|
|
])
|
|
|
|
|
|
|
|
|
2013-06-17 10:08:26 +02:00
|
|
|
os.system('cp '+ conf_file +' '+ conf_file +'.back')
|
2013-06-16 01:06:25 +02:00
|
|
|
|
2013-06-17 10:08:26 +02:00
|
|
|
with open(conf_file, 'w') as zone:
|
2013-06-16 01:06:25 +02:00
|
|
|
for line in lines:
|
|
|
|
zone.write(line + '\n')
|
|
|
|
|
2013-06-17 10:08:26 +02:00
|
|
|
os.system('chown -R bind:bind '+ zone_dir +' '+ conf_file)
|
2013-07-07 10:24:15 +02:00
|
|
|
if os.system('/usr/sbin/rndc reload') == 0:
|
2013-06-16 09:45:02 +02:00
|
|
|
exit(0)
|
|
|
|
else:
|
2013-06-17 10:08:26 +02:00
|
|
|
os.system('cp '+ conf_file +' '+ conf_file +'.bad')
|
|
|
|
os.system('cp '+ conf_file +'.back '+ conf_file)
|
2013-07-07 10:24:15 +02:00
|
|
|
os.system('/usr/sbin/rndc reload')
|
2013-06-16 09:45:02 +02:00
|
|
|
print("An error occured ! Please check daemon.log and your conf.bad")
|
|
|
|
exit(1)
|