Skip to content
Snippets Groups Projects
Commit ca603841 authored by Lars Beckers's avatar Lars Beckers
Browse files

zonedl: fix i/o bugs

parent 36247060
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,7 @@ import sys ...@@ -10,7 +10,7 @@ import sys
from pathlib import Path from pathlib import Path
parser = argparse.ArgumentParser(description='Downloads a zone file from RWTH DNS-Admin-Portal.') parser = argparse.ArgumentParser(description='Downloads a zone file from RWTH DNS-Admin-Portal.')
group = parser.add_mutual_exclusive_group(required=True) group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--list', action='store_true', default=False, help='list available zones') group.add_argument('--list', action='store_true', default=False, help='list available zones')
group.add_argument('--zone', type=int, nargs='+', help='download zone by id') group.add_argument('--zone', type=int, nargs='+', help='download zone by id')
group.add_argument('--domain', nargs='+', help='download zone by name') group.add_argument('--domain', nargs='+', help='download zone by name')
...@@ -26,8 +26,8 @@ SHIB_REDIRECT = 'https://noc-portal.rz.rwth-aachen.de/Shibboleth.sso/SAML2/POST' ...@@ -26,8 +26,8 @@ SHIB_REDIRECT = 'https://noc-portal.rz.rwth-aachen.de/Shibboleth.sso/SAML2/POST'
if args.passwordstore: if args.passwordstore:
prc = subprocess.run(['pass', 'show', args.passwordstore], stdout=subprocess.PIPE, check=True) prc = subprocess.run(['pass', 'show', args.passwordstore], stdout=subprocess.PIPE, check=True)
USERNAME = prc.splitlines()[1].strip() USERNAME = prc.stdout.splitlines()[1].strip()
PASSWORD = prc.splitlines()[0].strip() PASSWORD = prc.stdout.splitlines()[0].strip()
else: else:
USERNAME = input('Username: ') USERNAME = input('Username: ')
PASSWORD = getpass.getpass() PASSWORD = getpass.getpass()
...@@ -55,7 +55,7 @@ def get_zone_file(session, zone): ...@@ -55,7 +55,7 @@ def get_zone_file(session, zone):
return '' return ''
b = bs4.BeautifulSoup(r.text, 'lxml') b = bs4.BeautifulSoup(r.text, 'lxml')
t = b.find(id='extra-wrapper').find('span').text t = b.find(id='extra-wrapper').find('span').text
return t.replace('<br>', '\n') return t.replace('<br>', '').replace('\n\n', '\n') # \n
def shib_auth(session, resp, iterations=0): def shib_auth(session, resp, iterations=0):
b = bs4.BeautifulSoup(resp.text, 'lxml') b = bs4.BeautifulSoup(resp.text, 'lxml')
...@@ -120,8 +120,11 @@ else: ...@@ -120,8 +120,11 @@ else:
if a not in wanted: if a not in wanted:
print('Zone {} is not available, skipping'.format(a), file=sys.stderr) print('Zone {} is not available, skipping'.format(a), file=sys.stderr)
for w in wanted:
if fp is None: if fp is None:
fp = open(str(Path(args.dest) / w), 'w') for w in wanted:
print(get_zone_file(s, w), file=fp) with open(str(Path(args.dest) / str(w)), 'w') as fp:
fp.write(get_zone_file(s, w))
else:
for w in wanted:
fp.write(get_zone_file(s, w))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment