1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-vps-admin.git synced 2025-02-12 10:31:52 +00:00

Fix v2ray key change

This commit is contained in:
Ycarus 2020-11-10 15:02:02 +01:00
parent 774aceb357
commit 4501378b9e

View file

@ -1655,13 +1655,21 @@ def v2ray(*, params: V2rayconfig, current_user: User = Depends(get_current_user)
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/v2ray/v2ray-server.json', 'rb'))).hexdigest()
with open('/etc/v2ray/v2ray-server.json') as f:
v2ray_config = json.load(f)
userid = params.userid
v2ruserid = params.userid
for inbounds in v2ray_config['inbounds']:
if inbounds['tag'] == 'omrin-tunnel':
inbounds['settings']['clients'][0]['id'] = userid
inbounds['settings']['clients'][0]['id'] = v2ruserid
with open('/etc/v2ray/v2ray-server.json', 'w') as outfile:
json.dump(v2ray_config, outfile, indent=4)
userid = current_user.userid
if userid is None:
userid = 0
username = get_username_from_userid(userid)
final_md5 = hashlib.md5(file_as_bytes(open('/etc/v2ray/v2ray-server.json', 'rb'))).hexdigest()
v2ray_key = os.popen('jq -r .inbounds[0].settings.clients[0].id /etc/v2ray/v2ray-server.json').read().rstrip()
v2ray_port = os.popen('jq -r .inbounds[0].port /etc/v2ray/v2ray-server.json').read().rstrip()
v2ray_conf = { 'key': v2ray_key, 'port': v2ray_port}
modif_config_user(username, {'v2ray': v2ray_conf})
if initial_md5 != final_md5:
os.system("systemctl restart v2ray")
set_lastchange()