ascension

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

commit 1fb4d54b0140366e8709eb28f02edda9008e8c15
parent 470912f735f69dd1e4b34881068565c1915e44cd
Author: rexxnor <rexxnor+gnunet@brief.li>
Date:   Thu, 11 Oct 2018 23:23:18 +0200

fixed some minor bugs

Diffstat:
Mgnsmigrator/gnsmigrator.py | 49+++++++++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 10 deletions(-)

diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py @@ -203,23 +203,21 @@ class BaseMigrator(): :param domain: full domain of zone """ for record in zone.iterate_rdatas(): - # fancy dictionary because switch case does not exist in python dnsname_str = str(record[0]) rtype_str = dns.rdatatype.to_text(record[2].rdtype) - print(dnsname_str) - print(rtype_str) if dnsname_str == '@': if rtype_str == 'SOA': BaseMigrator.add_soa_record_to_gns(record, zonename, domain) - print("Record type %s is not yet supported" % rtype_str) else: if rtype_str == 'NS' and dnsname_str != '@': BaseMigrator.add_ns_record_to_gns(record, zonename, domain) elif rtype_str == 'MX': BaseMigrator.add_mx_record_to_gns(record, zonename) + #elif rtype_str == 'SRV': + # BaseMigrator.add_srv_record_to_gns(record, zonename) elif rtype_str in ['A', 'AAAA']: BaseMigrator.add_a_aaaa_record_to_gns(record, zonename, domain) - elif rtype_str in ['TXT', 'SRV', 'CNAME']: + elif rtype_str in ['TXT', 'CNAME']: BaseMigrator.add_gen_record_to_gns(record, zonename) else: print("Record type %s is not yet supported" % rtype_str) @@ -232,24 +230,50 @@ class BaseMigrator(): """ if not BaseMigrator.check_if_record_exists_in_zone(record, zonename): dnsname, ttl, rdata = record + rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) sp.run([GNUNET_NAMESTORE_COMMAND, '-z', zonename, '-a', '-n', str(dnsname), - '-t', dns.rdatatype.to_text(rdata.rdtype), + '-t', rtype_str, '-V', str(rdata), '-e', '%ds' % ttl]) @staticmethod + def add_srv_record_to_gns(record, zonename): + # TODO Add support for SRV records + """ + Adds a SRV record to GNS + """ + if not BaseMigrator.check_if_record_exists_in_zone(record, zonename): + value, ttl, rdata = record + rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) + dnsname_str = str(rdata).split(' ')[3] + debug = " ".join([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', dnsname_str, + '-t', rtype_str, + '-V', str(value), + '-e', '%ds' % ttl]) + print(debug) + sp.run([GNUNET_NAMESTORE_COMMAND, + '-z', zonename, + '-a', '-n', dnsname_str, + '-t', rtype_str, + '-V', str(value), + '-e', '%ds' % ttl]) + + @staticmethod def add_a_aaaa_record_to_gns(record, zonename, domain): """ Adds A and AAAA records to GNS """ if not BaseMigrator.check_if_record_exists_in_zone(record, zonename): dnsname, ttl, rdata = record + rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) sp.run([GNUNET_NAMESTORE_COMMAND, '-z', zonename, '-a', '-n', str(dnsname), - '-t', str(dns.rdatatype.to_text(rdata.rdtype)), + '-t', rtype_str, '-V', str(rdata), '-e', '%ds' % ttl]) sp.run([GNUNET_NAMESTORE_COMMAND, @@ -270,6 +294,10 @@ class BaseMigrator(): zonetuple = str(rdata).split(' ') domain = str(".".join(domain.split('.')[:-1])) authns, owner, serial, refresh, retry, expiry, irefresh = zonetuple + if authns[-1] == '.': + authns = authns[:-1] + if owner[-1] == '.': + owner = owner[:-1] sp.call([GNUNET_NAMESTORE_COMMAND, '-z', zonename, '-a', '-n', '@', @@ -344,13 +372,14 @@ class BaseMigrator(): """ Checks if the given record exists in GNS """ - dnsname, _, rtype = record + dnsname, _, rdata = record + rtype_str = str(dns.rdatatype.to_text(rdata.rdtype)) ret = sp.check_output([GNUNET_GNS_COMMAND, - '-t', str(rtype), + '-t', rtype_str, '-u', '%s.%s' % (dnsname, zonename)] ) - if 'Got:'.encode() in ret: + if 'Got '.encode() in ret: return True return False