Skip to content

Commit

Permalink
Fix global settings and hostname retrieve
Browse files Browse the repository at this point in the history
  • Loading branch information
Ysurac committed Nov 28, 2023
1 parent 4223eb0 commit e4fe9b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
omr-vps-admin (0.7+20231128) unstable; urgency=medium

* Fix global settings in json
* Fix when hostname website doesn't answer

-- OpenMPTCProuter <[email protected]> Tue, 28 Nov 2023 11:35:32 +0200

omr-vps-admin (0.7+20231116) unstable; urgency=medium

* Fix ss_go stats when ss_go return a json with an error message
Expand Down
35 changes: 15 additions & 20 deletions omr-admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#from starlette.requests import Request
import netifaces

#logging.basicConfig(filename='/tmp/omr-admin.log', encoding='utf-8', level=logging.DEBUG)
LOG = logging.getLogger('api')
LOG.setLevel(logging.ERROR)
#LOG.setLevel(logging.DEBUG)
Expand Down Expand Up @@ -258,12 +259,9 @@ def check_username_serial(username, serial):
data['users'][0][username]['serial_error'] = 1
else:
data['users'][0][username]['serial_error'] = int(data['users'][0][username]['serial_error']) + 1
if data and data != configdata:
backup_config()
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
else:
LOG.debug("Empty data for check_username_serial")
backup_config()
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
return False

def set_global_param(key, value):
Expand All @@ -274,26 +272,23 @@ def set_global_param(key, value):
configdata = json.loads(content)
data = configdata
except ValueError as e:
LOG.debug("Can't read file for set_global_param")
return {'error': 'Config file not readable', 'route': 'global_param'}
data[key] = value
if data and data != configdata:
if not key in data or data[key] != value:
data[key] = value
backup_config()
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as outfile:
json.dump(data, outfile, indent=4)
else:
LOG.debug("Empty data for set_global_param")
LOG.debug("Already exist data for set_global_param key:" + key)

def modif_config_user(user, changes):
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json') as f:
content = json.load(f)
content['users'][0][user].update(changes)
if content:
backup_config()
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as f:
json.dump(content, f, indent=4)
else:
LOG.debug("Empty data for modif_config_user")

backup_config()
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json', 'w') as f:
json.dump(content, f, indent=4)

def add_ss_user(port, key, userid=0, ip=''):
with open('/etc/shadowsocks-libev/manager.json') as f:
Expand Down Expand Up @@ -1793,9 +1788,9 @@ async def config(userid: Optional[int] = Query(None), serial: Optional[str] = Qu
else:
#ipv4_addr = os.popen("dig -4 TXT +timeout=2 +tries=1 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'\"' '{ print $2}'").read().rstrip()
if ipv4_addr == '':
ipv4_addr = os.popen('wget -4 -qO- -T 1 http://ip.openmptcprouter.com').read().rstrip()
ipv4_addr = os.popen('wget -4 -qO- -t 1 -T 1 http://ip.openmptcprouter.com').read().rstrip()
if ipv4_addr == '':
ipv4_addr = os.popen('wget -4 -qO- -T 1 http://ifconfig.me').read().rstrip()
ipv4_addr = os.popen('wget -4 -qO- -t 1 -T 1 http://ifconfig.me').read().rstrip()
if ipv4_addr != '':
set_global_param('ipv4', ipv4_addr)

Expand All @@ -1815,7 +1810,7 @@ async def config(userid: Optional[int] = Query(None), serial: Optional[str] = Qu
elif 'internet' in omr_config_data and not omr_config_data['internet']:
vps_domain = ''
else:
vps_domain = os.popen('wget -4 -qO- -T 1 http://hostname.openmptcprouter.com').read().rstrip()
vps_domain = os.popen('wget -4 -qO- -t 1 -T 1 http://hostname.openmptcprouter.com').read().rstrip()
if vps_domain != '':
set_global_param('hostname', vps_domain)
#vps_domain = os.popen('dig -4 +short +times=3 +tries=1 -x ' + ipv4_addr + " | sed 's/\.$//'").read().rstrip()
Expand Down Expand Up @@ -1969,7 +1964,7 @@ def shadowsocks(*, params: ShadowsocksConfigparams, current_user: User = Depends
if 'hostname' in omr_config_data:
vps_domain = omr_config_data['hostname']
else:
vps_domain = os.popen('wget -4 -qO- -T 1 http://hostname.openmptcprouter.com').read().rstrip()
vps_domain = os.popen('wget -4 -qO- -t 1 -T 1 http://hostname.openmptcprouter.com').read().rstrip()
if vps_domain != '':
set_global_param('hostname', vps_domain)

Expand Down

0 comments on commit e4fe9b8

Please sign in to comment.