[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [ascension] 10/57: added incremental zone transfer logic
From: |
gnunet |
Subject: |
[GNUnet-SVN] [ascension] 10/57: added incremental zone transfer logic |
Date: |
Sat, 13 Apr 2019 13:32:07 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository ascension.
commit d1ff79f3355b55498b55b08b2d6bec5dbd69e82e
Author: rexxnor <address@hidden>
AuthorDate: Thu Sep 27 22:05:29 2018 +0200
added incremental zone transfer logic
---
gnsmigrator/gnsmigrator.py | 68 ++++++++++++++++++++++++++++++++++------------
1 file changed, 50 insertions(+), 18 deletions(-)
diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py
index 804891a..c09f945 100644
--- a/gnsmigrator/gnsmigrator.py
+++ b/gnsmigrator/gnsmigrator.py
@@ -16,6 +16,8 @@ Options:
"""
# imports
+import sys
+import time
import subprocess
import csv
import dns.query
@@ -53,12 +55,13 @@ class GNSMigrator():
master_answer = dns.resolver.query(soa_answer[0].mname, 'A')
try:
- zone =
dns.zone.from_xfr(dns.query.xfr(master_answer[0].address, domain))
+ zone = dns.zone.from_xfr(dns.query.xfr(
+ master_answer[0].address, domain))
except dns.resolver.NoAnswer:
- print("the domain '%s' did not answer our xfr request" %
domain)
+ print("nameserver for '%s' did not answer" % domain)
continue
except dns.exception.FormError:
- print("the domain '%s' does not allow xfr requests from your
ip" % domain)
+ print("domain '%s' does not allow xfr requests" % domain)
continue
cls.zones[domain] = (zone, (master_answer[0].address, domain))
@@ -72,13 +75,16 @@ class GNSMigrator():
# building list with arguments
reverse_parsing = domain.split('.')[::-1]
for domainpart in reverse_parsing:
- pkey_lookup = subprocess.Popen([GNUNET_ZONE_CREATION_COMMAND,
'-d'],
+ 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()
+ pkey_zone = subprocess.check_output(['cut', '-d',
+ ' ', '-f3'],
+ stdin=pkey_line.stdout)
+ pkey_zone = pkey_zone.decode().strip()
pkey_lookup.stdout.close()
pkey_line.stdout.close()
# Create identity in GNUnet
@@ -86,22 +92,26 @@ class GNSMigrator():
subprocess.run([GNUNET_ZONE_CREATION_COMMAND,
'-C', domainpart])
- pkey_lookup = subprocess.Popen([GNUNET_ZONE_CREATION_COMMAND,
'-d'],
+ 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()
+ pkey_zone = subprocess.check_output(['cut', '-d',
+ ' ', '-f3'],
+ stdin=pkey_line.stdout)
+ pkey_zone = pkey_zone.decode().strip()
pkey_lookup.stdout.close()
pkey_line.stdout.close()
- # If it is TLD, don't add PKEY to higher zone as they do not
exist
+ # If it is TLD, don't add PKEY to higher zone
if counter > 0:
result = subprocess.check_output([GNUNET_GNS_COMMAND,
'-t', 'PKEY',
'-u', '%s.%s' %
- (domainpart,
reverse_parsing[counter - 1])])
+ (domainpart,
+ reverse_parsing[counter
- 1])])
if "No results." in result.decode():
subprocess.run([GNUNET_NAMESTORE_COMMAND,
@@ -115,7 +125,7 @@ class GNSMigrator():
@staticmethod
def add_records_to_gns(zonename, zone, domain, dnsresolver):
"""
- Checks if records are present
+ Checks if records are present and adds them if not
:param zonename: zonename of zone to add records to
:param zone: the transfered zone
:param domain: full domain of zone
@@ -186,6 +196,31 @@ class GNSMigrator():
"""
return domain.split('.')[0]
+ @classmethod
+ def refresh_zone(cls, domain, zonetuple, dnsresolver):
+ """
+ Refresh the zone using IXFR and the previous serial as reference
+
+ Returns 0 on unchanged and 1 on changed
+
+ :param domain: The domain to transfer and migrate
+ :param zonetuple: The necessary data tuple for the transfer
+ :param dnsresolver: Optional user specified resolver for subdomains
+ """
+ zone, xfrinfo = zonetuple
+ zonename = cls.get_lowest_domain_part(domain)
+ cls.add_records_to_gns(zonename, zone, domain, dnsresolver)
+
+ # Ugly way to get serial
+ serial = int(str(zone.get_rdataset('@', dns.rdatatype.SOA)).split('
')[5])
+ newzone = dns.zone.from_xfr(dns.query.xfr(xfrinfo[0],
+ xfrinfo[1],
+ rdtype=dns.rdatatype.IXFR,
+ serial=serial))
+ if newzone == zone:
+ return 1
+ return 0
+
def main():
"""
@@ -202,7 +237,7 @@ def main():
print('Exiting...')
return 1
- dnsresolver = args['<resolver>']
+ dnsresolver = args.get('<resolver>', None)
domainlist = []
@@ -225,11 +260,8 @@ def main():
gnsmigrator.initial_zone_transfer()
for domain, zonetuple in gnsmigrator.zones.items():
- zone, xfrinfo = zonetuple
- zonename = gnsmigrator.get_lowest_domain_part(domain)
- gnsmigrator.add_records_to_gns(zonename, zone, domain, dnsresolver)
- # retain the information needed for a second zone transfer
- #print(xfrinfo)
+ # Returns a value 0 if not changed and 1 if changed
+ gnsmigrator.refresh_zone(domain, zonetuple, dnsresolver)
if __name__ == '__main__':
main()
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [ascension] 21/57: fixed serial fetching and added serialization of zone, (continued)
- [GNUnet-SVN] [ascension] 21/57: fixed serial fetching and added serialization of zone, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 13/57: added zone merging of full and incremental zones, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 29/57: added warnings to logging if records failed to be added, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 27/57: unstable version, port specification possible, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 02/57: Added LICENSE, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 18/57: refactored adding of records, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 08/57: added GNS2DNS support and rudimentary Unittests (incomplete), gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 23/57: fixed non existing file, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 42/57: added dnscurve detection and log it, fix ttl bug with hierarchy, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 07/57: fixes, added a few tests, updated README and requirements, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 10/57: added incremental zone transfer logic,
gnunet <=
- [GNUnet-SVN] [ascension] 54/57: lint manpage, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 39/57: added daemonization, bumped version, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 57/57: ascension.1: remove texinfo syntax, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 49/57: minor cleanup, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 51/57: removed daemonization, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 26/57: added definitive support for IXFR, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 37/57: updated README, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 22/57: finished refactoring, fixed a few bugs, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 30/57: updated gnsmigrator and removed c rebuilds, gnunet, 2019/04/13
- [GNUnet-SVN] [ascension] 44/57: updated README, cleanup, PEP8, gnunet, 2019/04/13