ascension

Migrate DNS zones to the GNU Name System
Log | Files | Refs | README | LICENSE

commit 1d211abf5960635bd4c3135f80c0231120897b66
parent bc7fed5c8452baccfe0767c8fcf075d4fc8afd3f
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Fri, 21 Sep 2018 15:31:08 +0200

working prototype for A, AAAA, MX, CNAME, TXT and more records

Diffstat:
Mgnsmigrator/gnsmigrator.py | 64++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 50 insertions(+), 14 deletions(-)

diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py @@ -80,6 +80,14 @@ class GNSMigrator(): subprocess.run([GNUNET_ZONE_CREATION_COMMAND, '-C', domainpart]) + pkey_lookup = subprocess.Popen([GNUNET_ZONE_CREATION_COMMAND, '-d'], + stdout=subprocess.PIPE) + pkey_line = subprocess.Popen(['grep', domainpart], + stdin=pkey_lookup.stdout, + stdout=subprocess.PIPE) + pkey_zone = subprocess.check_output(['cut', '-d', ' ', '-f3'], + stdin=pkey_line.stdout).decode().strip() + # If it is TLD, don't add PKEY to higher zone as they do not exist if counter > 0: result = subprocess.check_output([GNUNET_GNS_COMMAND, @@ -94,28 +102,53 @@ class GNSMigrator(): '-t', 'PKEY', '-V', pkey_zone, '-e', 'never']) - #'-e', current+validity]) counter += 1 @staticmethod - def add_records_to_gns(zone): - """ - Adds the records from the zones to GNS with expiration - :param zone: zone to add to GNS - :returns: 0 on success, 1 on error - """ - pass - - @staticmethod - def check_records_existing(zone): + def add_records_to_gns(zonename, zone, domain): """ Checks if records are present :param param1: zone to lookup :returns: parts of zone that are not in GNS """ + # can optimize with for record in zone.iterate_rdatas.filter() for record in zone.iterate_rdatas(): - print(record) - return "" + dnsname, ttl, rtype = record + rtype_str = dns.rdatatype.to_text(rtype.rdtype) + dnsname_str = str(dnsname) + value = str(rtype) + if rtype_str == 'MX': + valuelist = value.split(' ') + value = '%s,%s' % (valuelist[0], valuelist[1]) + #if rtype_str != 'SOA': + if dnsname_str != '@': + ret = subprocess.run([GNUNET_GNS_COMMAND, + '-t', rtype_str, + '-u', '%s.%s' % (dnsname_str, zonename)], + stdout=subprocess.PIPE) + if 'Got'.encode() not in ret.stdout: + subprocess.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', dnsname_str, + '-t', rtype_str, + '-V', value, + '-e', '%ds' % ttl]) + if rtype_str in ['A', 'AAAA']: + # This is EXPERIMENTAL + subprocess.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', dnsname_str, + '-t', 'LEHO', + '-V', '%s.%s' % (dnsname_str, domain), + '-e', '%ds' % ttl]) + + + @staticmethod + def get_lowest_domain_part(domain): + """ + Returns the lowest domain part in hierarchy + """ + return domain.split('.')[0] def main(): @@ -136,9 +169,12 @@ def main(): for domain, zonetuple in gnsmigrator.zones.items(): zone, xfrinfo = zonetuple - remaining_records = gnsmigrator.check_records_existing(zone) + zonename = gnsmigrator.get_lowest_domain_part(domain) + gnsmigrator.add_records_to_gns(zonename, zone, domain) + print(xfrinfo) # gnsmigrator.add_records_to_gns(remaining_records) if __name__ == '__main__': + # ensure gnunet is runnning main()