From 29656b16302734a14e9678a9cf0e334db2d5cd99 Mon Sep 17 00:00:00 2001 From: "Jiangjie.Bai" Date: Tue, 19 Jul 2022 18:59:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E8=8E=B7=E5=8F=96=20r?= =?UTF-8?q?dp-file=20/=20client-url=20/=20smart-endpoint=20=E6=97=B6endpoi?= =?UTF-8?q?nt=20host=E5=90=8E=E5=8F=B0=E5=A4=84=E7=90=86=E4=B8=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=AF=B7=E6=B1=82=E7=9A=84host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/api/connection_token.py | 13 ++----------- apps/terminal/models/endpoint.py | 5 +++-- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index c0f85757d..873129b20 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -91,11 +91,6 @@ 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': '', @@ -145,9 +140,7 @@ class ConnectionTokenMixin: endpoint = self.get_smart_endpoint( protocol='rdp', asset=token.asset, application=token.application ) - # TODO 暂时获取一下host,后续优化 - host = self.get_host(endpoint) - rdp_options['full address:s'] = f'{host}:{endpoint.rdp_port}' + rdp_options['full address:s'] = f'{endpoint.host}:{endpoint.rdp_port}' # 设置用户名 rdp_options['username:s'] = '{}|{}'.format(token.user.username, str(token.id)) @@ -199,10 +192,8 @@ class ConnectionTokenMixin: endpoint = self.get_smart_endpoint( protocol='ssh', asset=token.asset, application=token.application ) - # TODO 暂时获取一下host,后续优化 - host = self.get_host(endpoint) data = { - 'ip': host, + 'ip': endpoint.host, 'port': str(endpoint.ssh_port), 'username': 'JMS-{}'.format(str(token.id)), 'password': token.secret diff --git a/apps/terminal/models/endpoint.py b/apps/terminal/models/endpoint.py index 083b9c0a1..beefdeb69 100644 --- a/apps/terminal/models/endpoint.py +++ b/apps/terminal/models/endpoint.py @@ -63,8 +63,6 @@ class Endpoint(JMSModel): 'http_port': 0, } endpoint, created = cls.objects.get_or_create(id=cls.default_id, defaults=data) - if not endpoint.host and request: - endpoint.host = request.get_host().split(':')[0] return endpoint @classmethod @@ -122,4 +120,7 @@ class EndpointRule(JMSModel): endpoint = endpoint_rule.endpoint else: endpoint = Endpoint.get_or_create_default(request) + if not endpoint.host and request: + # 动态添加 current request host + endpoint.host = request.get_host().split(':')[0] return endpoint