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

zonedl: compat with new dnsadmin portal design

parent 5f2f20f3
No related branches found
No related tags found
No related merge requests found
......@@ -19,7 +19,7 @@ parser.add_argument('dest', action='store', default='-', help='destination to st
args = parser.parse_args()
DNS_ADMIN = 'https://noc-portal.rz.rwth-aachen.de/dnsadmin'
ZONE_FILE = 'https://noc-portal.rz.rwth-aachen.de/dnsadmin/zones/{}/print'
ZONE_FILE = 'https://noc-portal.rz.rwth-aachen.de/dnsadmin/zones/{}-{}/pre_deploy_preview'
SHIB_PREFIX = 'https://sso.rwth-aachen.de'
SHIB_AUTH = 'https://sso.rwth-aachen.de/idp/profile/SAML2/Redirect/SSO'
SHIB_REDIRECT = 'https://noc-portal.rz.rwth-aachen.de/Shibboleth.sso/SAML2/POST'
......@@ -44,17 +44,17 @@ def get_zones(session):
for zone in z.find_all('tr'):
a = zone.find('td').find('a')
#d[int(a['href'].split('/')[-1])] = a.text
d[a.text] = int(a['href'].split('/')[-1])
d[a.text] = int(a['href'].split('/')[-1].split('-', maxsplit=1)[0])
return d
def get_zone_file(session, zone):
r = session.get(ZONE_FILE.format(str(zone)))
r = session.get(ZONE_FILE.format(str(zone[0]), str(zone[1].replace('.', '-'))))
if r.url.startswith(SHIB_AUTH):
res,session,r = shib_auth(session, r)
if not res:
return ''
b = bs4.BeautifulSoup(r.text, 'lxml')
t = b.find(id='extra-wrapper').find('span').text
t = b.find(id='content-wrapper').find('div', class_='zone-content').text
return t.replace('<br>', '').replace('\n\n', '\n') # \n
def shib_auth(session, resp, iterations=0):
......@@ -108,21 +108,23 @@ wanted = []
if args.domain:
for k in d:
if k in args.domain:
wanted.append(d[k])
wanted.append((d[k], k))
for a in args.domain:
if a not in d:
print('Domain {} is not available, skipping'.format(a), file=sys.stderr)
else:
zones = []
for k in d:
if d[k] in args.zone:
wanted.append(d[k])
wanted.append((d[k], k))
zones.append(d[k])
for a in args.zone:
if a not in wanted:
if a not in zones:
print('Zone {} is not available, skipping'.format(a), file=sys.stderr)
if fp is None:
for w in wanted:
with open(str(Path(args.dest) / str(w)), 'w') as fp:
with open(str(Path(args.dest) / str(w[0])), 'w') as fp:
fp.write(get_zone_file(s, w))
else:
for w in wanted:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment