Skip to content

Commit

Permalink
Fixed broken validation
Browse files Browse the repository at this point in the history
Previously this script would accept NS record targets such as `1.0.2.` which BIND failed on.
This change also temporarily breaks TXT records (none will be added).
  • Loading branch information
jonaharagon authored Oct 23, 2018
1 parent 26488fd commit 23937d9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions generate-zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def is_valid_ipv6(ip_addr):

def is_valid_domain(name):
try:
if re.match('^([a-zA-Z0-9._-]+\.)*[a-zA-Z0-9._-]+\.?$', name) and len(name) < 64 and name[:1].isalnum():
if re.match('^([a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.)*[a-zA-Z]+([-.]+[a-zA-Z0-9]+)*\.?$', name) and len(name) < 64 and name[:1].isalnum():
return True
else:
return False
Expand All @@ -26,11 +26,11 @@ def is_valid_domain(name):
return False

def is_valid_txt(txt):
if len(txt) < 255:
if len(txt) < 250:
return True
else:
return False

def make_list(input_data):
if type(input_data) is list:
return input_data
Expand Down Expand Up @@ -90,10 +90,10 @@ def process_name(self, domain, name_json):
for target in make_list(values):
if is_valid_domain(target):
self.others.append({'type': 'dname', 'domain': domain, 'target': make_fqdn(target)})
elif record_type == 'info':
for target in make_list(values):
if(is_valid_txt(target)):
self.others.append({'type': 'txt', 'domain': domain, 'target': json.dumps(target).replace('"', '\\"').encode('ascii', 'ignore')})
# elif record_type == 'info':
# for target in make_list(values):
# if(is_valid_txt(target)):
# self.others.append({'type': 'txt', 'domain': domain, 'target': json.dumps(target).replace('"', '\\"').encode('ascii', 'ignore')})
elif record_type == 'map':
for subdomain, value in values.items():
if subdomain:
Expand Down Expand Up @@ -150,7 +150,7 @@ def generate_zone(names):
def main():
try:
config = ConfigParser.ConfigParser()
config.read("nmczone.conf")
config.read("/opt/nmczone/nmczone.conf")
json_rpc = config.get('nmczone', 'json_rpc')
zonefile = config.get('nmczone', 'zonefile')
block_count = config.get('nmczone', 'block_count')
Expand All @@ -161,7 +161,7 @@ def main():

names_data = get_names(json_rpc)

with open("zone-template.conf", 'r') as f:
with open("/opt/nmczone/zone-template.conf", 'r') as f:
template = f.read()

generate_zone(names_data['names'])
Expand Down

0 comments on commit 23937d9

Please sign in to comment.