main: Added function to get worker ip from worker name
All checks were successful
Build Docker / Build Master (push) Successful in 27s
Build Docker / Build Bot (push) Successful in 25s

This commit is contained in:
Nathan Woodburn 2023-08-17 13:43:15 +10:00
parent cda318eeeb
commit fccfddca51
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -181,8 +181,11 @@ def tlsa():
if worker == None:
return jsonify({'error': 'Domain does not exist', 'success': 'false'})
# Get worker ip
ip = workerIP(worker)
# Get TLSA record
resp=requests.get("http://"+worker + ":5000/tlsa?domain=" + domain,timeout=2)
resp=requests.get("http://"+ip + ":5000/tlsa?domain=" + domain,timeout=2)
return resp.json()
@ -235,6 +238,25 @@ def site_worker(domain):
sites_file.close()
return worker
def workerIP(worker):
# If file doesn't exist, create it
try:
workers_file = open('/data/workers.txt', 'r')
except FileNotFoundError:
workers_file = open('/data/workers.txt', 'w')
workers_file.close()
workers_file = open('/data/workers.txt', 'r')
ip = None
for line in workers_file.readlines():
if worker == line.split(':')[0]:
ip = line.split(':')[1].strip('\n')
break
workers_file.close()
return ip
# Start the server