From 5055d140fd34a04b68aff41e581097d6af14f8c4 Mon Sep 17 00:00:00 2001 From: feng626 <1304903146@qq.com> Date: Mon, 18 Jul 2022 11:29:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dhost=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/connection_token.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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