diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index f0a7e0a63..60b91e4db 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -91,6 +91,11 @@ class ConnectionTokenMixin: "config": rdp_config } + def get_host(self, endpoint): + if not endpoint.host: + return self.request.get_host() + return endpoint.host + def get_rdp_file_info(self, token: ConnectionToken): rdp_options = { 'full address:s': '', @@ -140,7 +145,9 @@ class ConnectionTokenMixin: endpoint = self.get_smart_endpoint( protocol='rdp', asset=token.asset, application=token.application ) - rdp_options['full address:s'] = f'{endpoint.host}:{endpoint.rdp_port}' + # TODO 暂时获取一下host,后续优化 + host = self.get_host(endpoint) + rdp_options['full address:s'] = f'{host}:{endpoint.rdp_port}' # 设置用户名 rdp_options['username:s'] = '{}|{}'.format(token.user.username, str(token.id)) @@ -192,8 +199,10 @@ class ConnectionTokenMixin: endpoint = self.get_smart_endpoint( protocol='ssh', asset=token.asset, application=token.application ) + # TODO 暂时获取一下host,后续优化 + host = self.get_host(endpoint) data = { - 'ip': endpoint.host, + 'ip': host, 'port': str(endpoint.ssh_port), 'username': 'JMS-{}'.format(str(token.id)), 'password': token.secret