mirror of
https://github.com/Ysurac/openmptcprouter-vps-admin.git
synced 2025-03-09 15:40:05 +00:00
Add latest Shadowsocks-Go API
This commit is contained in:
parent
b31e764e7b
commit
371ce38ec2
2 changed files with 75 additions and 49 deletions
7
debian/changelog
vendored
7
debian/changelog
vendored
|
@ -1,3 +1,10 @@
|
||||||
|
omr-vps-admin (0.13+20241016) unstable; urgency=medium
|
||||||
|
|
||||||
|
* Add Shadowsocks-go new API support
|
||||||
|
* Add option to disable 6in4
|
||||||
|
|
||||||
|
-- OpenMPTCProuter <contact@openmptcprouter.com> Wed, 16 Oct 2024 15:49:13 +0200
|
||||||
|
|
||||||
omr-vps-admin (0.12+20240920) unstable; urgency=medium
|
omr-vps-admin (0.12+20240920) unstable; urgency=medium
|
||||||
|
|
||||||
* Fix Shadowsocks-go changes
|
* Fix Shadowsocks-go changes
|
||||||
|
|
117
omr-admin.py
117
omr-admin.py
|
@ -160,15 +160,32 @@ def get_bytes_ss(port):
|
||||||
|
|
||||||
def get_bytes_ss_go(user):
|
def get_bytes_ss_go(user):
|
||||||
try:
|
try:
|
||||||
r = requests.get(url="http://127.0.0.1:65279/v1/servers/ss-2022/stats")
|
#r = requests.get(url="http://127.0.0.1:65279/v1/servers/ss-2022/stats")
|
||||||
#r = requests.get(url="http://127.0.0.1:65279/api/ssm/v1/servers/ss-2022/stats")
|
r = requests.get(url="http://127.0.0.1:65279/api/ssm/v1/servers/ss-2022/stats")
|
||||||
except requests.exceptions.Timeout:
|
except requests.exceptions.Timeout:
|
||||||
LOG.debug("Shadowsocks go stats timeout")
|
LOG.debug("Shadowsocks go stats timeout")
|
||||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
except requests.exceptions.RequestException as err:
|
except requests.exceptions.RequestException as err:
|
||||||
LOG.debug("Shadowsocks go stats error (" + str(err) + ")")
|
LOG.debug("Shadowsocks go stats error (" + str(err) + ")")
|
||||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
if 'error' in r.json():
|
try:
|
||||||
|
if 'error' in r.json():
|
||||||
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
|
except requests.exceptions.JSONDecodeError:
|
||||||
|
try:
|
||||||
|
r = requests.get(url="http://127.0.0.1:65279/v1/servers/ss-2022/stats")
|
||||||
|
#r = requests.get(url="http://127.0.0.1:65279/api/ssm/v1/servers/ss-2022/stats")
|
||||||
|
except requests.exceptions.Timeout:
|
||||||
|
LOG.debug("Shadowsocks go stats timeout")
|
||||||
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
|
except requests.exceptions.RequestException as err:
|
||||||
|
LOG.debug("Shadowsocks go stats error (" + str(err) + ")")
|
||||||
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
|
try:
|
||||||
|
if 'error' in r.json():
|
||||||
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
|
except requests.exceptions.JSONDecodeError as err:
|
||||||
|
LOG.debug("Shadowsocks go stats error (" + str(err) + ")")
|
||||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||||
if 'users' in r.json():
|
if 'users' in r.json():
|
||||||
for userdata in r.json()['users']:
|
for userdata in r.json()['users']:
|
||||||
|
@ -1924,7 +1941,7 @@ async def config(userid: Optional[int] = Query(None), serial: Optional[str] = Qu
|
||||||
locaip6 = 'fd00::a00:1'
|
locaip6 = 'fd00::a00:1'
|
||||||
remoteip6 = 'fd00::a00:2'
|
remoteip6 = 'fd00::a00:2'
|
||||||
|
|
||||||
vpn = 'glorytun_tcp'
|
vpn = 'openvpn'
|
||||||
if 'vpn' in omr_config_data['users'][0][username]:
|
if 'vpn' in omr_config_data['users'][0][username]:
|
||||||
vpn = omr_config_data['users'][0][username]['vpn']
|
vpn = omr_config_data['users'][0][username]['vpn']
|
||||||
|
|
||||||
|
@ -3076,27 +3093,29 @@ def vpnips(*, vpnconfig: VPNips, current_user: User = Depends(get_current_user))
|
||||||
userid = current_user.userid
|
userid = current_user.userid
|
||||||
if userid is None:
|
if userid is None:
|
||||||
userid = 0
|
userid = 0
|
||||||
if os.path.isfile('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid)):
|
|
||||||
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'rb'))).hexdigest()
|
if not '6in4' in omr_config_data or omr_config_data['6in4']:
|
||||||
else:
|
if os.path.isfile('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid)):
|
||||||
initial_md5 = ''
|
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'rb'))).hexdigest()
|
||||||
with open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'w+') as n:
|
|
||||||
n.write('LOCALIP=' + localip + "\n")
|
|
||||||
n.write('REMOTEIP=' + remoteip + "\n")
|
|
||||||
if localip6:
|
|
||||||
n.write('LOCALIP6=' + localip6 + "\n")
|
|
||||||
else:
|
else:
|
||||||
n.write('LOCALIP6=fd00::a0' + hex(userid)[2:] + ':1/126' + "\n")
|
initial_md5 = ''
|
||||||
if remoteip6:
|
with open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'w+') as n:
|
||||||
n.write('REMOTEIP6=' + remoteip6 + "\n")
|
n.write('LOCALIP=' + localip + "\n")
|
||||||
else:
|
n.write('REMOTEIP=' + remoteip + "\n")
|
||||||
n.write('REMOTEIP6=fd00::a0' + hex(userid)[2:] + ':2/126' + "\n")
|
if localip6:
|
||||||
if ula:
|
n.write('LOCALIP6=' + localip6 + "\n")
|
||||||
n.write('ULA=' + ula + "\n")
|
else:
|
||||||
final_md5 = hashlib.md5(file_as_bytes(open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'rb'))).hexdigest()
|
n.write('LOCALIP6=fd00::a0' + hex(userid)[2:] + ':1/126' + "\n")
|
||||||
if initial_md5 != final_md5:
|
if remoteip6:
|
||||||
os.system("systemctl -q restart omr6in4@user" + str(userid))
|
n.write('REMOTEIP6=' + remoteip6 + "\n")
|
||||||
#set_lastchange()
|
else:
|
||||||
|
n.write('REMOTEIP6=fd00::a0' + hex(userid)[2:] + ':2/126' + "\n")
|
||||||
|
if ula:
|
||||||
|
n.write('ULA=' + ula + "\n")
|
||||||
|
final_md5 = hashlib.md5(file_as_bytes(open('/etc/openmptcprouter-vps-admin/omr-6in4/user' + str(userid), 'rb'))).hexdigest()
|
||||||
|
if initial_md5 != final_md5:
|
||||||
|
os.system("systemctl -q restart omr6in4@user" + str(userid))
|
||||||
|
#set_lastchange()
|
||||||
|
|
||||||
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall/params.vpn', 'rb'))).hexdigest()
|
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall/params.vpn', 'rb'))).hexdigest()
|
||||||
fd, tmpfile = mkstemp()
|
fd, tmpfile = mkstemp()
|
||||||
|
@ -3123,31 +3142,31 @@ def vpnips(*, vpnconfig: VPNips, current_user: User = Depends(get_current_user))
|
||||||
os.system("systemctl -q reload shorewall")
|
os.system("systemctl -q reload shorewall")
|
||||||
#set_lastchange()
|
#set_lastchange()
|
||||||
|
|
||||||
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall6/params.vpn', 'rb'))).hexdigest()
|
if not '6in4' in omr_config_data or omr_config_data['6in4']:
|
||||||
fd, tmpfile = mkstemp()
|
initial_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall6/params.vpn', 'rb'))).hexdigest()
|
||||||
dataexist = False
|
fd, tmpfile = mkstemp()
|
||||||
with open('/etc/shorewall6/params.vpn', 'r') as f, open(tmpfile, 'a+') as n:
|
dataexist = False
|
||||||
for line in f:
|
with open('/etc/shorewall6/params.vpn', 'r') as f, open(tmpfile, 'a+') as n:
|
||||||
if not ('OMR_ADDR_USER' + str(userid) +'=' in line and not userid == 0) and not ('OMR_ADDR=' in line and userid == 0):
|
for line in f:
|
||||||
n.write(line)
|
if not ('OMR_ADDR_USER' + str(userid) +'=' in line and not userid == 0) and not ('OMR_ADDR=' in line and userid == 0):
|
||||||
elif not userid == 0:
|
n.write(line)
|
||||||
n.write('OMR_ADDR_USER' + str(userid) + '=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
elif not userid == 0:
|
||||||
dataexist = True
|
n.write('OMR_ADDR_USER' + str(userid) + '=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
||||||
elif userid == 0:
|
dataexist = True
|
||||||
n.write('OMR_ADDR=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
elif userid == 0:
|
||||||
dataexist = True
|
n.write('OMR_ADDR=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
||||||
if not dataexist:
|
dataexist = True
|
||||||
if not userid == 0:
|
if not dataexist:
|
||||||
n.write('OMR_ADDR_USER' + str(userid) + '=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
if not userid == 0:
|
||||||
elif userid == 0:
|
n.write('OMR_ADDR_USER' + str(userid) + '=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
||||||
n.write('OMR_ADDR=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
elif userid == 0:
|
||||||
|
n.write('OMR_ADDR=fd00::a0' + hex(userid)[2:] + ':2/126' + '\n')
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
move(tmpfile, '/etc/shorewall6/params.vpn')
|
move(tmpfile, '/etc/shorewall6/params.vpn')
|
||||||
final_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall6/params.vpn', 'rb'))).hexdigest()
|
final_md5 = hashlib.md5(file_as_bytes(open('/etc/shorewall6/params.vpn', 'rb'))).hexdigest()
|
||||||
if initial_md5 != final_md5:
|
if initial_md5 != final_md5:
|
||||||
os.system("systemctl -q reload shorewall6")
|
os.system("systemctl -q reload shorewall6")
|
||||||
#set_lastchange()
|
#set_lastchange()
|
||||||
|
|
||||||
return {'result': 'done', 'reason': 'changes applied', 'route': 'vpnips'}
|
return {'result': 'done', 'reason': 'changes applied', 'route': 'vpnips'}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue