mirror of https://github.com/jumpserver/jumpserver
fix:绑定的端点Default下载RDP文件中的地址是空的
parent
cd0348cca1
commit
3853d0bcc6
|
@ -205,7 +205,7 @@ class RDPFileClientProtocolURLMixin:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_smart_endpoint(self, protocol, asset=None):
|
def get_smart_endpoint(self, protocol, asset=None):
|
||||||
endpoint = Endpoint.match_by_instance_label(asset, protocol)
|
endpoint = Endpoint.match_by_instance_label(asset, protocol, self.request)
|
||||||
if not endpoint:
|
if not endpoint:
|
||||||
target_ip = asset.get_target_ip() if asset else ''
|
target_ip = asset.get_target_ip() if asset else ''
|
||||||
endpoint = EndpointRule.match_endpoint(
|
endpoint = EndpointRule.match_endpoint(
|
||||||
|
|
|
@ -42,7 +42,7 @@ class SmartEndpointViewMixin:
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
||||||
def match_endpoint_by_label(self):
|
def match_endpoint_by_label(self):
|
||||||
return Endpoint.match_by_instance_label(self.target_instance, self.target_protocol)
|
return Endpoint.match_by_instance_label(self.target_instance, self.target_protocol, self.request)
|
||||||
|
|
||||||
def match_endpoint_by_target_ip(self):
|
def match_endpoint_by_target_ip(self):
|
||||||
target_ip = self.request.GET.get('target_ip', '') # 支持target_ip参数,用来方便测试
|
target_ip = self.request.GET.get('target_ip', '') # 支持target_ip参数,用来方便测试
|
||||||
|
|
|
@ -75,7 +75,20 @@ class Endpoint(JMSBaseModel):
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def match_by_instance_label(cls, instance, protocol):
|
def handle_endpoint_host(cls, endpoint, request=None):
|
||||||
|
if not endpoint.host and request:
|
||||||
|
# 动态添加 current request host
|
||||||
|
host_port = request.get_host()
|
||||||
|
# IPv6
|
||||||
|
if host_port.startswith('['):
|
||||||
|
host = host_port.split(']:')[0].rstrip(']') + ']'
|
||||||
|
else:
|
||||||
|
host = host_port.split(':')[0]
|
||||||
|
endpoint.host = host
|
||||||
|
return endpoint
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def match_by_instance_label(cls, instance, protocol, request=None):
|
||||||
from assets.models import Asset
|
from assets.models import Asset
|
||||||
from terminal.models import Session
|
from terminal.models import Session
|
||||||
if isinstance(instance, Session):
|
if isinstance(instance, Session):
|
||||||
|
@ -88,6 +101,7 @@ class Endpoint(JMSBaseModel):
|
||||||
endpoints = cls.objects.filter(name__in=list(values)).order_by('-date_updated')
|
endpoints = cls.objects.filter(name__in=list(values)).order_by('-date_updated')
|
||||||
for endpoint in endpoints:
|
for endpoint in endpoints:
|
||||||
if endpoint.is_valid_for(instance, protocol):
|
if endpoint.is_valid_for(instance, protocol):
|
||||||
|
endpoint = cls.handle_endpoint_host(endpoint, request)
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,13 +144,5 @@ class EndpointRule(JMSBaseModel):
|
||||||
endpoint = endpoint_rule.endpoint
|
endpoint = endpoint_rule.endpoint
|
||||||
else:
|
else:
|
||||||
endpoint = Endpoint.get_or_create_default(request)
|
endpoint = Endpoint.get_or_create_default(request)
|
||||||
if not endpoint.host and request:
|
endpoint = Endpoint.handle_endpoint_host(endpoint, request)
|
||||||
# 动态添加 current request host
|
|
||||||
host_port = request.get_host()
|
|
||||||
# IPv6
|
|
||||||
if host_port.startswith('['):
|
|
||||||
host = host_port.split(']:')[0].rstrip(']') + ']'
|
|
||||||
else:
|
|
||||||
host = host_port.split(':')[0]
|
|
||||||
endpoint.host = host
|
|
||||||
return endpoint
|
return endpoint
|
||||||
|
|
Loading…
Reference in New Issue