mirror of
https://github.com/Ysurac/openmptcprouter-vps-admin.git
synced 2025-02-12 10:31:52 +00:00
Fix OpenVPN and Shadowsocks-Rust stats, add notes to users
This commit is contained in:
parent
7adb6dd108
commit
f6e6f218d1
2 changed files with 41 additions and 4 deletions
8
debian/changelog
vendored
8
debian/changelog
vendored
|
@ -1,3 +1,11 @@
|
|||
omr-vps-admin (0.9+20240322) unstable; urgency=medium
|
||||
|
||||
* Fix OpenVPN stats
|
||||
* Fix Shadowsocks Rust stats
|
||||
* You can add notes in json to an existing user
|
||||
|
||||
-- OpenMPTCProuter <contact@openmptcprouter.com> Fri, 22 Mar 2024 16:00:25 +0200
|
||||
|
||||
omr-vps-admin (0.9+20240301) unstable; urgency=medium
|
||||
|
||||
* Add/Remove users via API without script restart
|
||||
|
|
37
omr-admin.py
37
omr-admin.py
|
@ -138,7 +138,7 @@ def get_bytes_openvpn(user):
|
|||
for data in ovpn_stats:
|
||||
if user in data:
|
||||
stats = data.split(',')
|
||||
return { 'downlinkBytes': stats[2], 'uplinkBytes': stats[3] }
|
||||
return { 'downlinkBytes': int(stats[2]), 'uplinkBytes': int(stats[3]) }
|
||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||
|
||||
|
||||
|
@ -162,7 +162,7 @@ def get_bytes_ss(port):
|
|||
|
||||
def get_bytes_ss_go(user):
|
||||
try:
|
||||
r = requests.get(url="http://127.0.0.1:65279/v1/servers/ss-2022/users/" + user)
|
||||
r = requests.get(url="http://127.0.0.1:65279/v1/servers/ss-2022/stats")
|
||||
except requests.exceptions.Timeout:
|
||||
LOG.debug("Shadowsocks go stats timeout")
|
||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||
|
@ -171,7 +171,10 @@ def get_bytes_ss_go(user):
|
|||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||
if 'error' in r.json():
|
||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||
return r.json()
|
||||
for userdata in r.json()['users']:
|
||||
if userdata['username'] == user:
|
||||
return { 'downlinkBytes': userdata['downlinkBytes'], 'uplinkBytes': userdata['uplinkBytes'] }
|
||||
return { 'downlinkBytes': 0, 'uplinkBytes': 0 }
|
||||
|
||||
def get_bytes_v2ray(t,user):
|
||||
if t == "tx":
|
||||
|
@ -236,6 +239,18 @@ def get_username_from_userid(userid):
|
|||
return user
|
||||
return ''
|
||||
|
||||
def get_userid_from_username(username):
|
||||
if username == 'openmptcprouter':
|
||||
return 0
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json') as f:
|
||||
content = f.read()
|
||||
content = re.sub(",\s*}", "}", content) # pylint: disable=W1401
|
||||
try:
|
||||
data = json.loads(content)
|
||||
except ValueError as e:
|
||||
return {'error': 'Config file not readable', 'route': 'get_username'}
|
||||
return int(data['users'][0][username]['userid'])
|
||||
|
||||
def check_username_serial(username, serial):
|
||||
with open('/etc/openmptcprouter-vps-admin/omr-admin-config.json') as f:
|
||||
content = f.read()
|
||||
|
@ -1324,10 +1339,12 @@ async def mptcpsupport(request: Request):
|
|||
|
||||
# Get VPS status
|
||||
@app.get('/status', summary="Get current server load average, uptime and release")
|
||||
async def status(userid: Optional[int] = Query(None), serial: Optional[str] = Query(None), current_user: User = Depends(get_current_user)):
|
||||
async def status(userid: Optional[int] = Query(None), username: Optional[str] = Query(None), serial: Optional[str] = Query(None), current_user: User = Depends(get_current_user)):
|
||||
LOG.debug('Get status...')
|
||||
if not current_user.permissions == "admin":
|
||||
userid = current_user.userid
|
||||
elif username is not None:
|
||||
userid = get_userid_from_username(username)
|
||||
if userid is None:
|
||||
userid = 0
|
||||
username = get_username_from_userid(userid)
|
||||
|
@ -3155,6 +3172,18 @@ def add_user(*, params: NewUser, current_user: User = Depends(get_current_user))
|
|||
omr_config_data = json.load(f)
|
||||
fake_users_db = omr_config_data['users'][0]
|
||||
|
||||
class ExistingUser(BaseModel):
|
||||
username: str = Query(..., title="Username")
|
||||
note: list = []
|
||||
|
||||
@app.post('/add_user_note', summary="Add a note to an user")
|
||||
def add_user_note(*, params: ExistingUser, current_user: User = Depends(get_current_user)):
|
||||
if not current_user.permissions == "admin":
|
||||
return {'result': 'permission', 'reason': 'Need admin user', 'route': 'add_user'}
|
||||
modif_config_user(params.username,{"note": params.note})
|
||||
set_lastchange(30)
|
||||
|
||||
|
||||
class RemoveUser(BaseModel):
|
||||
username: str
|
||||
|
||||
|
|
Loading…
Reference in a new issue