|
|
|
@ -36,6 +36,9 @@ api_token=os.getenv('API_TOKEN')
|
|
|
|
|
provider = 'hetzner'
|
|
|
|
|
TMPFILE = '/tmp/lastIP'
|
|
|
|
|
|
|
|
|
|
rid=None
|
|
|
|
|
zid=None
|
|
|
|
|
|
|
|
|
|
WEBRTCCONFIGFILE = '/etc/bigbluebutton/bbb-webrtc-sfu/production.yml'
|
|
|
|
|
# WEBRTCCONFIGFILE = 'test.yml'
|
|
|
|
|
|
|
|
|
@ -44,6 +47,8 @@ def get_ip():
|
|
|
|
|
return (r['ip'])
|
|
|
|
|
|
|
|
|
|
def get_zone_id(zone):
|
|
|
|
|
if zid != None: return zid
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
response = requests.get(
|
|
|
|
|
url="https://dns.hetzner.com/api/v1/zones",
|
|
|
|
@ -57,12 +62,16 @@ def get_zone_id(zone):
|
|
|
|
|
|
|
|
|
|
id = [z.get('id') for z in response.get('zones') if z.get('name')==zone]
|
|
|
|
|
|
|
|
|
|
return (id[0])
|
|
|
|
|
rid=id[0]
|
|
|
|
|
return rid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_record_id(zone,subdomain):
|
|
|
|
|
if rid != None: return rid
|
|
|
|
|
|
|
|
|
|
if provider == 'ovh':
|
|
|
|
|
id = client.get('/domain/zone/' + zone + '/record', fieldType='A', subDomain=subdomain )
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
response = requests.get(
|
|
|
|
@ -80,7 +89,9 @@ def get_record_id(zone,subdomain):
|
|
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
|
my_logger.critical('HTTP Request failed')
|
|
|
|
|
exit(1)
|
|
|
|
|
return id[0]
|
|
|
|
|
|
|
|
|
|
zid = id[0]
|
|
|
|
|
return zid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_record(zone, subdomain, ip):
|
|
|
|
@ -95,11 +106,9 @@ def set_record(zone, subdomain, ip):
|
|
|
|
|
result = client.post('/domain/zone/' + zone + '/refresh')
|
|
|
|
|
return result
|
|
|
|
|
else:
|
|
|
|
|
zid=get_zone_id(zone)
|
|
|
|
|
rid=get_record_id(zone,subdomain)
|
|
|
|
|
try:
|
|
|
|
|
response = requests.put(
|
|
|
|
|
url="https://dns.hetzner.com/api/v1/records/" + rid,
|
|
|
|
|
url="https://dns.hetzner.com/api/v1/records/" + get_record_id(zone,subdomain),
|
|
|
|
|
headers={
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
"Auth-API-Token": api_token,
|
|
|
|
@ -109,12 +118,13 @@ def set_record(zone, subdomain, ip):
|
|
|
|
|
"ttl": 60,
|
|
|
|
|
"type": "A",
|
|
|
|
|
"name": subdomain,
|
|
|
|
|
"zone_id": zid
|
|
|
|
|
"zone_id": get_zone_id(zone)
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
return (None if response.status_code == requests.codes.ok else False)
|
|
|
|
|
except requests.exceptions.RequestException:
|
|
|
|
|
print('HTTP Request failed')
|
|
|
|
|
my_logger.critical('HTTP Request failed')
|
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def read_config_file():
|
|
|
|
@ -136,7 +146,6 @@ if len(sys.argv) > 2:
|
|
|
|
|
webrtc_config = read_config_file()
|
|
|
|
|
|
|
|
|
|
lastIP = webrtc_config['freeswitch']['ip']
|
|
|
|
|
|
|
|
|
|
currentIP = get_ip()
|
|
|
|
|
|
|
|
|
|
if lastIP == currentIP:
|
|
|
|
@ -145,7 +154,7 @@ if len(sys.argv) > 2:
|
|
|
|
|
|
|
|
|
|
if (set_record (sys.argv[1], sys.argv[2], currentIP) == None ):
|
|
|
|
|
write_config_file(currentIP)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
subprocess.run(["ip","a","del",lastIP + '/32',"dev","lo"])
|
|
|
|
|
subprocess.run(["ip","a","add",currentIP,"dev","lo"])
|
|
|
|
|
|
|
|
|
|