💩 starting to write handlers and more
This commit is contained in:
parent
34e9f4605a
commit
63fc14ed72
1 changed files with 98 additions and 0 deletions
98
main.py
98
main.py
|
@ -5,12 +5,74 @@ import configparser
|
|||
import dns.name
|
||||
import dns.rdataset
|
||||
import dns.rdatatype
|
||||
from dns.rdtypes import *
|
||||
|
||||
import collections
|
||||
|
||||
from re2oapi import Re2oAPIClient
|
||||
|
||||
|
||||
def format_rname(mail: str):
|
||||
"""
|
||||
Format a email given by re2o API to a rname dnspython object.
|
||||
|
||||
Given an email address in the standard string format `mail@example.tld`
|
||||
return an email address in the format required by RFC 1035
|
||||
`mail.example.tld.`
|
||||
|
||||
Return a `dns.name.Name` object.
|
||||
"""
|
||||
|
||||
local, domain = mail.split('@')
|
||||
rname = dns.name.Name((local, *dns.name.from_text(domain)))
|
||||
|
||||
return rname
|
||||
|
||||
def format_mname(name : str):
|
||||
"""
|
||||
Format a zone name given by the re2o API to a mname dnspython object.
|
||||
|
||||
Given a a name of the format `.zone.domain.tld` output the
|
||||
`.zone.domain.tld.`, formatted accordingly to the RFC 1035.
|
||||
|
||||
Return a `dns.name.name` object.
|
||||
"""
|
||||
|
||||
if name[0] == '.':
|
||||
name = name[1:]
|
||||
|
||||
mname = dns.name.from_text(name)
|
||||
|
||||
return mname
|
||||
|
||||
def in_class_record(*args):
|
||||
return dns.rdata.from_text(dns.rdataclass.IN, *args)
|
||||
|
||||
|
||||
def a_record(address):
|
||||
return in_class_record(dns.rdataclass.A, address)
|
||||
|
||||
|
||||
def aaaa_record(address):
|
||||
return in_class_record(dns.rdataclass.AAAA, address)
|
||||
|
||||
|
||||
def ns_record(address):
|
||||
return in_class_record(dns.rdataclass.NS, address)
|
||||
|
||||
|
||||
def sshfp_record(algo_id, fp_type, fp):
|
||||
return in_class_record(dns.rdatatype.SSHFP, algo_id, fp_type, fp)
|
||||
|
||||
|
||||
def mx_record(priority, target):
|
||||
return in_class_record(dns.rdatatype.MX, priority, target)
|
||||
|
||||
|
||||
def txt_record(data):
|
||||
return in_data_record(dns.rdatatype.TXT, data)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument("-c", "--config", help="Path to the config file", type=str,
|
||||
|
@ -25,3 +87,39 @@ api_client = Re2oAPIClient(config['Re2o']['hostname'], config['Re2o']['username'
|
|||
use_tls=False)
|
||||
|
||||
zones = api_client.list("dns/zones")
|
||||
|
||||
records = collections.defaultdict(list)
|
||||
|
||||
# zone = zones[0]
|
||||
|
||||
HANDLERS = {
|
||||
'soa' : soa_handler,
|
||||
'originv4': originv4_handler,
|
||||
'originv6': originv6_handler,
|
||||
'sshfp': sshfp_handler,
|
||||
'mx_records': mx_records_handler,
|
||||
'txt_records': txt_records_handler,
|
||||
'srv_records': srv_records_handler,
|
||||
'a_records': a_records_handler,
|
||||
'aaaa_records': aaaa_records_handler,
|
||||
}
|
||||
|
||||
records['@'].append(
|
||||
dns.rdtypes.ANY.SOA.SOA(
|
||||
dns.rdataclass.IN,
|
||||
dns.rdatatype.SOA,
|
||||
format_mname(zone['soa']['name']),
|
||||
format_rname(zone['soa']['mail']),
|
||||
zone['soa']['serial'],
|
||||
zone['soa']['refresh'],
|
||||
zone['soa']['retry'],
|
||||
zone['soa']['expire'],
|
||||
zone['soa']['ttl']
|
||||
)
|
||||
)
|
||||
|
||||
if zone['originv4'] is not None:
|
||||
records['@'].append(
|
||||
a_record(zone['originv4']['ipv4'])
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue