改进:[API] 获取会话ID时发生错误,能给出错误描述。
parent
5322b88053
commit
32ba720ad1
|
@ -111,14 +111,14 @@ class RequestSessionHandler(TPBaseJsonHandler):
|
||||||
|
|
||||||
operator = '[{}] {}'.format(args['_srv_name_'], operator)
|
operator = '[{}] {}'.format(args['_srv_name_'], operator)
|
||||||
|
|
||||||
err, info = yield api_request_session_id(
|
ret = yield api_request_session_id(
|
||||||
acc_id,
|
acc_id,
|
||||||
protocol_sub_type,
|
protocol_sub_type,
|
||||||
self.request.remote_ip,
|
self.request.remote_ip,
|
||||||
operator
|
operator
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != TPE_OK:
|
if ret['code'] != TPE_OK:
|
||||||
return self.write_json(err)
|
return self.write_json(ret['code'], ret['message'])
|
||||||
|
|
||||||
return self.write_json(TPE_OK, data=info)
|
return self.write_json(TPE_OK, data=ret['data'])
|
||||||
|
|
|
@ -92,54 +92,36 @@ class SessionListsHandler(TPBaseHandler):
|
||||||
|
|
||||||
@tornado.gen.coroutine
|
@tornado.gen.coroutine
|
||||||
def api_request_session_id(acc_id, protocol_sub_type, client_ip, operator):
|
def api_request_session_id(acc_id, protocol_sub_type, client_ip, operator):
|
||||||
# 根据给定的account_id,查询对应的主机ID和账号ID
|
ret = {
|
||||||
|
'code': TPE_OK,
|
||||||
# 有三种方式获取会话ID:
|
'message': '',
|
||||||
# 1. 给定一个远程连接授权ID(普通用户进行远程连接)
|
'data': {}
|
||||||
# 2. 给定要连接的主机ID和账号ID(管理员进行远程连接)
|
}
|
||||||
# 3. 给定要连接的主机ID和账号信息(管理员测试远程连接是否可用)
|
|
||||||
#
|
|
||||||
# WEB服务根据上述信息产生临时的远程连接ID,核心服务通过此远程连接ID来获取远程连接所需数据,生成会话ID。
|
|
||||||
|
|
||||||
# try:
|
|
||||||
# _mode = int(args['mode'])
|
|
||||||
# _protocol_type = int(args['protocol_type'])
|
|
||||||
# _protocol_sub_type = int(args['protocol_sub_type'])
|
|
||||||
# except:
|
|
||||||
# return self.write_json(TPE_PARAM)
|
|
||||||
|
|
||||||
_mode = 2
|
|
||||||
|
|
||||||
conn_info = dict()
|
conn_info = dict()
|
||||||
conn_info['_enc'] = 1
|
conn_info['_enc'] = 1
|
||||||
conn_info['host_id'] = 0
|
conn_info['host_id'] = 0
|
||||||
conn_info['client_ip'] = client_ip # self.request.remote_ip
|
conn_info['client_ip'] = client_ip
|
||||||
conn_info['user_id'] = 1 # self.get_current_user()['id']
|
conn_info['user_id'] = 1
|
||||||
conn_info['user_username'] = operator # self.get_current_user()['username']
|
conn_info['user_username'] = operator
|
||||||
|
|
||||||
# mode = 0: test connect
|
# 直接连接(无需授权,第三方服务操作,已经经过授权检查了)
|
||||||
# mode = 1: user connect
|
err, acc_info = account.get_account_info(acc_id)
|
||||||
# mode = 2: admin connect
|
if err != TPE_OK:
|
||||||
if _mode == 2:
|
ret['code'] = err
|
||||||
# 直接连接(无需授权),必须具有运维授权管理的权限方可进行
|
ret['message'] = '无此远程账号'
|
||||||
# ret = self.check_privilege(TP_PRIVILEGE_OPS_AUZ)
|
return ret
|
||||||
# if ret != TPE_OK:
|
|
||||||
# return
|
|
||||||
#
|
|
||||||
# acc_id = args['acc_id']
|
|
||||||
|
|
||||||
err, acc_info = account.get_account_info(acc_id)
|
host_id = acc_info['host_id']
|
||||||
if err != TPE_OK:
|
acc_info['protocol_flag'] = TP_FLAG_ALL
|
||||||
return err, None
|
acc_info['record_flag'] = TP_FLAG_ALL
|
||||||
|
|
||||||
host_id = acc_info['host_id']
|
|
||||||
acc_info['protocol_flag'] = TP_FLAG_ALL
|
|
||||||
acc_info['record_flag'] = TP_FLAG_ALL
|
|
||||||
|
|
||||||
# 获取要远程连接的主机信息(要访问的IP地址,如果是路由模式,则是路由主机的IP+端口)
|
# 获取要远程连接的主机信息(要访问的IP地址,如果是路由模式,则是路由主机的IP+端口)
|
||||||
err, host_info = host.get_host_info(host_id)
|
err, host_info = host.get_host_info(host_id)
|
||||||
if err != TPE_OK:
|
if err != TPE_OK:
|
||||||
return err, None
|
ret['code'] = err
|
||||||
|
ret['message'] = '未找到对应远程主机'
|
||||||
|
return ret
|
||||||
|
|
||||||
conn_info['host_id'] = host_id
|
conn_info['host_id'] = host_id
|
||||||
conn_info['host_ip'] = host_info['ip']
|
conn_info['host_ip'] = host_info['ip']
|
||||||
|
@ -180,14 +162,18 @@ def api_request_session_id(acc_id, protocol_sub_type, client_ip, operator):
|
||||||
_yr = core_service_async_post_http(req)
|
_yr = core_service_async_post_http(req)
|
||||||
_code, ret_data = yield _yr
|
_code, ret_data = yield _yr
|
||||||
if _code != TPE_OK:
|
if _code != TPE_OK:
|
||||||
return _code, None
|
ret['code'] = _code
|
||||||
|
ret['message'] = '无法连接到核心服务'
|
||||||
|
return ret
|
||||||
if ret_data is None:
|
if ret_data is None:
|
||||||
# return self.write_json(TPE_FAILED, '调用核心服务获取会话ID失败')
|
ret['code'] = TPE_FAILED
|
||||||
return TPE_FAILED, None
|
ret['message'] = '调用核心服务获取会话ID失败'
|
||||||
|
return ret
|
||||||
|
|
||||||
if 'sid' not in ret_data:
|
if 'sid' not in ret_data:
|
||||||
# return self.write_json(TPE_FAILED, '核心服务获取会话ID时返回错误数据')
|
ret['code'] = TPE_FAILED
|
||||||
return TPE_FAILED, None
|
ret['message'] = '核心服务获取会话ID时返回错误数据'
|
||||||
|
return ret
|
||||||
|
|
||||||
data = dict()
|
data = dict()
|
||||||
data['session_id'] = ret_data['sid']
|
data['session_id'] = ret_data['sid']
|
||||||
|
@ -202,8 +188,10 @@ def api_request_session_id(acc_id, protocol_sub_type, client_ip, operator):
|
||||||
elif conn_info['protocol_type'] == TP_PROTOCOL_TYPE_TELNET:
|
elif conn_info['protocol_type'] == TP_PROTOCOL_TYPE_TELNET:
|
||||||
data['teleport_port'] = tp_cfg().core.telnet.port
|
data['teleport_port'] = tp_cfg().core.telnet.port
|
||||||
|
|
||||||
# return self.write_json(0, data=data)
|
ret['code'] = TPE_OK
|
||||||
return TPE_OK, data
|
ret['message'] = ''
|
||||||
|
ret['data'] = data
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
class DoGetSessionIDHandler(TPBaseJsonHandler):
|
class DoGetSessionIDHandler(TPBaseJsonHandler):
|
||||||
|
|
Loading…
Reference in New Issue