Skip to content
Snippets Groups Projects
Commit 2d4a1f50 authored by Ferenc Schulcz's avatar Ferenc Schulcz
Browse files

Fix API endpoints

parent 3657ad76
No related branches found
No related tags found
No related merge requests found
......@@ -45,9 +45,9 @@ async def sendRequest(session, url, urlparams):
print(f"Could not reach {url}: {e}")
return (url, 600)
async def sendAllRequests(urls, urlparams):
async def sendAllRequests(hosts, endpoint, urlparams):
async with aiohttp.ClientSession() as session:
requests = [sendRequest(session, url, urlparams) for url in urls]
requests = [sendRequest(session, host + endpoint, urlparams) for host in hosts]
return await asyncio.gather(*requests)
def dyndnsRegister(**kwargs):
......@@ -66,7 +66,7 @@ def dyndnsRegister(**kwargs):
return rqtools.redirect(rqtools.url_for('service', servicename='dyndns'))
tokenseed = str(random.randint(1, 2**32)) + str(random.randint(1, 2**32))
domain = request.form['domainname']
registrationStatuses = asyncio.run(sendAllRequests(config.get('DYNDNS_SERVER_URLS'), {'domain': domain, 'tokenseed': tokenseed}))
registrationStatuses = asyncio.run(sendAllRequests(config.get('DYNDNS_SERVER_URLS'), '/register', {'domain': domain, 'tokenseed': tokenseed}))
allFail = True
allSuccess = True
for s in registrationStatuses:
......@@ -101,7 +101,7 @@ def dyndnsUpdate(**kwargs):
x = db.db['dyndns-records'].find_one({'token': request.args['token']})
if x['ip'] == ip:
return {'message': 'Already set.'}, 200
updateStatuses = asyncio.run(sendAllRequests(config.get('DYNDNS_SERVER_URLS'), {'token': request.args['token'], 'ip': ip}))
updateStatuses = asyncio.run(sendAllRequests(config.get('DYNDNS_SERVER_URLS'), '/update', {'token': request.args['token'], 'ip': ip}))
allFail = True
allSuccess = True
for s in updateStatuses:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment