[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [ascension] 10/45: added incremental zone transfer logic
From: |
gnunet |
Subject: |
[GNUnet-SVN] [ascension] 10/45: added incremental zone transfer logic |
Date: |
Fri, 25 Jan 2019 10:02:10 +0100 |
This is an automated email from the git hooks/post-receive script.
rexxnor 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] 09/45: updated README, (continued)
- [GNUnet-SVN] [ascension] 09/45: updated README, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 23/45: fixed non existing file, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 19/45: fixed some minor bugs, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 16/45: fixed special cases with GNS2DNS, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 25/45: fixed bugs, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 20/45: fixed zonemaster to zonedata in README, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 13/45: added zone merging of full and incremental zones, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 05/45: initial prototype, bootstrapping zones and zone transfer, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 17/45: updated requirements and README, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 22/45: finished refactoring, fixed a few bugs, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 10/45: added incremental zone transfer logic,
gnunet <=
- [GNUnet-SVN] [ascension] 06/45: working prototype for A, AAAA, MX, CNAME, TXT and more records, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 15/45: created baseclass and separated small from big zones, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 27/45: unstable version, port specification possible, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 28/45: refactored code, added debug mode, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 26/45: added definitive support for IXFR, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 44/45: updated README, cleanup, PEP8, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 43/45: updated dependencies, setup.py, removed TODOs, improved error handling, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 12/45: bumped version to 0.1.0, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 03/45: removed GNU from heading in README, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 02/45: Added LICENSE, gnunet, 2019/01/25
- Prev by Date:
[GNUnet-SVN] [ascension] 22/45: finished refactoring, fixed a few bugs
- Next by Date:
[GNUnet-SVN] [ascension] 06/45: working prototype for A, AAAA, MX, CNAME, TXT and more records
- Previous by thread:
[GNUnet-SVN] [ascension] 22/45: finished refactoring, fixed a few bugs
- Next by thread:
[GNUnet-SVN] [ascension] 06/45: working prototype for A, AAAA, MX, CNAME, TXT and more records
- Index(es):