2015-04-03 15:38:41 +02:00
|
|
|
#! /usr/bin/env python3
|
2014-09-19 19:43:11 +02:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import json
|
|
|
|
import re
|
2015-04-03 15:38:41 +02:00
|
|
|
import ipaddress
|
2014-09-19 19:43:11 +02:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
def str_to_domainlabel(s):
|
|
|
|
label = re.sub("[^0-9a-zA-Z-]", "-", s)
|
|
|
|
label = re.sub("-+", "-", label)
|
|
|
|
label = re.sub("^-*", "", label)
|
|
|
|
label = re.sub("-*$", "", label)
|
|
|
|
|
2014-12-30 10:54:56 +01:00
|
|
|
if not re.match("^[a-zA-Z][a-zA-Z0-9-]{,61}[a-zA-Z0-9]$", label):
|
2014-09-19 19:43:11 +02:00
|
|
|
raise RuntimeError("Not convertable to a domain label: %s" % s)
|
|
|
|
return label
|
|
|
|
|
|
|
|
def ipv6_addr_to_rdns(addr):
|
2015-04-03 15:38:41 +02:00
|
|
|
return ".".join(reversed(addr.exploded.replace(':', ''))) + ".ip6.arpa."
|
2014-09-19 19:43:11 +02:00
|
|
|
|
|
|
|
data = json.load(sys.stdin)
|
|
|
|
domain = sys.argv[1]
|
|
|
|
if not domain.startswith("."):
|
|
|
|
domain = "." + domain
|
|
|
|
|
|
|
|
if not domain.endswith("."):
|
|
|
|
domain = domain + "."
|
|
|
|
|
|
|
|
print("""$TTL 1h
|
2015-04-03 15:40:26 +02:00
|
|
|
@ IN SOA vpn03.bremen.freifunk.net. noc.bremen.freifunk.net. (
|
2014-09-19 19:43:11 +02:00
|
|
|
%s ; serial
|
|
|
|
1h ; refresh
|
|
|
|
30m ; retry
|
|
|
|
2d ; expiration
|
|
|
|
1h ; caching
|
|
|
|
)
|
|
|
|
|
2015-04-03 15:40:26 +02:00
|
|
|
NS vpn02.bremen.freifunk.net.
|
|
|
|
NS vpn03.bremen.freifunk.net.
|
2014-09-19 19:43:11 +02:00
|
|
|
""" % datetime.now().strftime("%Y%m%d%H%M"))
|
|
|
|
|
|
|
|
for node in data.values():
|
|
|
|
try:
|
|
|
|
for address in node['network']['addresses']:
|
2015-04-03 15:38:41 +02:00
|
|
|
try:
|
|
|
|
address = ipaddress.IPv6Address(address)
|
|
|
|
except ValueError:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if address.is_link_local or address.is_private:
|
2014-09-19 19:43:11 +02:00
|
|
|
continue
|
|
|
|
|
|
|
|
rdns = ipv6_addr_to_rdns(address)
|
|
|
|
|
|
|
|
if rdns.endswith(domain):
|
2015-04-03 15:38:41 +02:00
|
|
|
print("%s PTR %s.nodes.ffhb.de." % (rdns[0:-len(domain)], str_to_domainlabel(node['hostname'])))
|
|
|
|
except (KeyError, RuntimeError):
|
2014-09-19 19:43:11 +02:00
|
|
|
pass
|