[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [ascension] 05/45: initial prototype, bootstrapping zones a
From: |
gnunet |
Subject: |
[GNUnet-SVN] [ascension] 05/45: initial prototype, bootstrapping zones and zone transfer |
Date: |
Fri, 25 Jan 2019 10:02:05 +0100 |
This is an automated email from the git hooks/post-receive script.
rexxnor pushed a commit to branch master
in repository ascension.
commit bc7fed5c8452baccfe0767c8fcf075d4fc8afd3f
Author: rexxnor <address@hidden>
AuthorDate: Thu Sep 20 10:19:17 2018 +0200
initial prototype, bootstrapping zones and zone transfer
---
.gitignore | 1 +
gnsmigrator/__init__.py | 0
gnsmigrator/gnsmigrator.py | 144 +++++++++++++++++++++++++++++++++++++++++++++
requirements.txt | 4 ++
4 files changed, 149 insertions(+)
diff --git a/.gitignore b/.gitignore
index ff65a43..23ff70e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,3 +95,4 @@ ENV/
# mkdocs documentation
/site
+.idea/
diff --git a/gnsmigrator/__init__.py b/gnsmigrator/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/gnsmigrator/gnsmigrator.py b/gnsmigrator/gnsmigrator.py
new file mode 100644
index 0000000..f31fe3f
--- /dev/null
+++ b/gnsmigrator/gnsmigrator.py
@@ -0,0 +1,144 @@
+#!/usr/bin/env python3
+"""GNS Migrator
+
+Usage:
+ gnsmigrator.py <file>
+ gnsmigrator.py -h | --help
+ gnsmigrator.py --version
+
+Options:
+ -h --help Show this screen.
+ --version Show version.
+"""
+
+# imports
+import subprocess
+import csv
+import dns.query
+import dns.resolver
+import dns.zone
+import docopt
+
+# GLOBALS
+GNUNET_ZONE_CREATION_COMMAND = 'gnunet-identity'
+GNUNET_NAMESTORE_COMMAND = 'gnunet-namestore'
+GNUNET_GNS_COMMAND = 'gnunet-gns'
+
+class GNSMigrator():
+ """
+ Class that provides functionality to migrate zones
+ """
+
+ @classmethod
+ def __init__(cls, domainlist):
+ cls.domainlist = domainlist
+ cls.zones = {}
+
+ @classmethod
+ def initial_zone_transfer(cls):
+ """
+ Fetch all the zones via zone transfer
+ """
+ for domain in cls.domainlist:
+ try:
+ soa_answer = dns.resolver.query(domain, 'SOA')
+ except dns.resolver.NoAnswer:
+ print("the domain '%s' does not exist" % domain)
+ continue
+
+ master_answer = dns.resolver.query(soa_answer[0].mname, 'A')
+
+ try:
+ 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)
+ continue
+ except dns.exception.FormError:
+ print("the domain '%s' does not allow xfr requests from your
ip" % domain)
+ continue
+ cls.zones[domain] = (zone, (master_answer[0].address, domain))
+
+ @classmethod
+ def bootstrap_zones(cls):
+ """
+ Bootstrap the zone structure into GNS
+ """
+ for domain in cls.domainlist:
+ counter = 0
+ # building list with arguments
+ reverse_parsing = domain.split('.')[::-1]
+ for domainpart in reverse_parsing:
+ 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()
+ # Create identity in GNUnet
+ if not pkey_zone:
+ subprocess.run([GNUNET_ZONE_CREATION_COMMAND,
+ '-C', domainpart])
+
+ # 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,
+ '-t', 'PKEY',
+ '-u', '%s.%s' %
+ (domainpart,
reverse_parsing[counter - 1])])
+
+ if "No results." in result.decode():
+ subprocess.run([GNUNET_NAMESTORE_COMMAND,
+ '-z', reverse_parsing[counter - 1],
+ '-a', '-n', domainpart,
+ '-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):
+ """
+ Checks if records are present
+ :param param1: zone to lookup
+ :returns: parts of zone that are not in GNS
+ """
+ for record in zone.iterate_rdatas():
+ print(record)
+ return ""
+
+
+def main():
+ """
+ Initializes object and handles arguments
+ """
+ args = docopt.docopt(__doc__, version='GNS Migrator 0.1a')
+ csvfile = args['<file>']
+ domainlist = []
+ with open(csvfile, 'r') as openedcsv:
+ linereader = csv.reader(openedcsv, delimiter=' ', quotechar='|')
+ for domain in linereader:
+ domainlist += domain
+
+ gnsmigrator = GNSMigrator(domainlist)
+ gnsmigrator.bootstrap_zones()
+ gnsmigrator.initial_zone_transfer()
+
+ for domain, zonetuple in gnsmigrator.zones.items():
+ zone, xfrinfo = zonetuple
+ remaining_records = gnsmigrator.check_records_existing(zone)
+ # gnsmigrator.add_records_to_gns(remaining_records)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..9f7a9d9
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,4 @@
+cffi==1.11.5
+dnspython==1.15.0
+docopt==0.6.2
+pycparser==2.18
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [ascension] 07/45: fixes, added a few tests, updated README and requirements, (continued)
- [GNUnet-SVN] [ascension] 07/45: fixes, added a few tests, updated README and requirements, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 14/45: reworked the incremental zone transfer, added notice for bind, gnunet, 2019/01/25
- [GNUnet-SVN] [ascension] 11/45: added ttl of SOA to zone for later implementation of timer, gnunet, 2019/01/25
- [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 <=
- [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, 2019/01/25
- [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