|
|
|
@ -2,11 +2,13 @@
|
|
|
|
|
|
|
|
|
|
## imports
|
|
|
|
|
import json
|
|
|
|
|
import ovh
|
|
|
|
|
import requests
|
|
|
|
|
import os, sys
|
|
|
|
|
import logging
|
|
|
|
|
import logging.handlers
|
|
|
|
|
import os, sys
|
|
|
|
|
import ovh
|
|
|
|
|
import requests
|
|
|
|
|
import subprocess
|
|
|
|
|
import yaml
|
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
|
|
my_logger = logging.getLogger('MyLogger')
|
|
|
|
@ -32,6 +34,9 @@ client = ovh.Client(
|
|
|
|
|
|
|
|
|
|
TMPFILE = '/tmp/lastIP'
|
|
|
|
|
|
|
|
|
|
WEBRTCCONFIGFILE = `/etc/bigbluebutton/bbb-webrtc-sfu/production.yml`
|
|
|
|
|
# WEBRTCCONFIGFILE = 'test.yml'
|
|
|
|
|
|
|
|
|
|
def get_ip():
|
|
|
|
|
r = requests.get('http://ipinfo.io')
|
|
|
|
|
return (r.json()['ip'])
|
|
|
|
@ -52,18 +57,26 @@ def set_record(zone, subdomain, ip):
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
result = client.post('/domain/zone/' + zone + '/refresh')
|
|
|
|
|
return result
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
def read_config_file():
|
|
|
|
|
with open(WEBRTCCONFIGFILE,'r') as file:
|
|
|
|
|
webrtc_config = yaml.safe_load(file)
|
|
|
|
|
return webrtc_config
|
|
|
|
|
|
|
|
|
|
def write_config_file(ip):
|
|
|
|
|
webrtc_config['mediasoup']['webrtc']['listenIps'][0]['announcedIp']=ip
|
|
|
|
|
webrtc_config['mediasoup']['plainRtp']['listenIp']['announcedIp']=ip
|
|
|
|
|
webrtc_config['freeswitch']['ip']=ip
|
|
|
|
|
|
|
|
|
|
with open(WEBRTCCONFIGFILE, 'w') as file:
|
|
|
|
|
yaml.dump(webrtc_config, file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
|
if os.path.exists(TMPFILE):
|
|
|
|
|
with open(TMPFILE) as file:
|
|
|
|
|
try:
|
|
|
|
|
lastIP=file.read()
|
|
|
|
|
except:
|
|
|
|
|
my_logger.critical('error reading ' + TMPFILE)
|
|
|
|
|
else:
|
|
|
|
|
lastIP = ''
|
|
|
|
|
webrtc_config = read_config_file()
|
|
|
|
|
|
|
|
|
|
lastIP = webrtc_config['freeswitch']['ip']
|
|
|
|
|
|
|
|
|
|
currentIP = get_ip()
|
|
|
|
|
|
|
|
|
@ -71,8 +84,12 @@ if len(sys.argv) > 2:
|
|
|
|
|
my_logger.debug ('IP has not changed since last call')
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"])
|
|
|
|
|
|
|
|
|
|
my_logger.debug('IP of ' + sys.argv[2] + '.' + sys.argv[1] + ' successfully changed to ' + currentIP)
|
|
|
|
|
else:
|
|
|
|
|
my_logger.critical('Couldn\'t change IP')
|
|
|
|
|