#975: REST route `GET /status` with `detail=true` shows detailed status
Note: `GET /status?detail=true` requires the authentication token.remotes/github/python3
parent
a850bd1236
commit
3a3b642556
|
|
@ -53,8 +53,11 @@ def check_secret(fnc):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
try:
|
try:
|
||||||
this, path, get_params, post_params, server = args # @UnusedVariable
|
this, path, get_params, post_params, server = args # @UnusedVariable
|
||||||
if this.random == server.headers['Authorization']:
|
# Accept "status" operation with no arguments or any function with Authorization header
|
||||||
fnc(*args, **kwargs)
|
if fnc.__name__ == 'process_status' and not get_params:
|
||||||
|
return fnc(*args, **kwargs)
|
||||||
|
elif this.random == server.headers['Authorization']:
|
||||||
|
return fnc(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
raise Exception('Unauthorized operation')
|
raise Exception('Unauthorized operation')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -207,19 +210,25 @@ class OpenGnSysWorker(ServerWorker):
|
||||||
raise Exception('Message processor for "{}" not found'.format(path[0]))
|
raise Exception('Message processor for "{}" not found'.format(path[0]))
|
||||||
return operation(path[1:], get_params, post_params)
|
return operation(path[1:], get_params, post_params)
|
||||||
|
|
||||||
|
@check_secret
|
||||||
def process_status(self, path, get_params, post_params, server):
|
def process_status(self, path, get_params, post_params, server):
|
||||||
"""
|
"""
|
||||||
Returns client status (OS type or execution status) and login status
|
Returns client status (OS type or execution status) and login status
|
||||||
:param path:
|
:param path:
|
||||||
:param get_params:
|
:param get_params: optional parameter "detail" to show extended status
|
||||||
:param post_params:
|
:param post_params:
|
||||||
:param server:
|
:param server:
|
||||||
:return: JSON object {"status": "status_code", "loggedin": boolean}
|
:return: JSON object {"status": "status_code", "loggedin": boolean, ...}
|
||||||
"""
|
"""
|
||||||
st = {'linux': 'LNX', 'macos': 'OSX', 'windows': 'WIN'}
|
st = {'linux': 'LNX', 'macos': 'OSX', 'windows': 'WIN'}
|
||||||
try:
|
try:
|
||||||
res['status'] = st[operations.os_type.lower()]
|
# Standard status
|
||||||
res = {'status': st[operations.os_type.lower()], 'loggedin': len(self.user) > 0}
|
res = {'status': st[operations.os_type.lower()], 'loggedin': len(self.user) > 0}
|
||||||
|
# Detailed status
|
||||||
|
if get_params.get('detail', 'false') == 'true':
|
||||||
|
res.update({'agent_version': VERSION, 'os_version': operations.os_version, 'sys_load': os.getloadavg()})
|
||||||
|
if res['loggedin']:
|
||||||
|
res.update({'sessions': len(self.user), 'current_user': self.user[-1]})
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Unknown operating system
|
# Unknown operating system
|
||||||
res = {'status': 'UNK'}
|
res = {'status': 'UNK'}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue