mirror of https://github.com/jumpserver/jumpserver
perf: 修改 connect token, 获取 applet info
parent
e82eb8f3d1
commit
24da1e7d91
|
@ -20,7 +20,7 @@ from common.utils.django import get_request_os
|
||||||
from orgs.mixins.api import RootOrgViewMixin
|
from orgs.mixins.api import RootOrgViewMixin
|
||||||
from perms.models import ActionChoices
|
from perms.models import ActionChoices
|
||||||
from terminal.connect_methods import NativeClient, ConnectMethodUtil
|
from terminal.connect_methods import NativeClient, ConnectMethodUtil
|
||||||
from terminal.models import EndpointRule, Applet
|
from terminal.models import EndpointRule
|
||||||
from ..models import ConnectionToken
|
from ..models import ConnectionToken
|
||||||
from ..serializers import (
|
from ..serializers import (
|
||||||
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
||||||
|
@ -34,30 +34,6 @@ class RDPFileClientProtocolURLMixin:
|
||||||
request: Request
|
request: Request
|
||||||
get_serializer: callable
|
get_serializer: callable
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def set_applet_info(token, rdp_options):
|
|
||||||
# remote-app
|
|
||||||
applet = Applet.objects.filter(name=token.connect_method).first()
|
|
||||||
if not applet:
|
|
||||||
return rdp_options
|
|
||||||
|
|
||||||
cmdline = {
|
|
||||||
'app_name': applet.name,
|
|
||||||
'user_id': str(token.user.id),
|
|
||||||
'asset_id': str(token.asset.id),
|
|
||||||
'token_id': str(token.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
app = '||tinker'
|
|
||||||
rdp_options['remoteapplicationmode:i'] = '1'
|
|
||||||
rdp_options['alternate shell:s'] = app
|
|
||||||
rdp_options['remoteapplicationprogram:s'] = app
|
|
||||||
rdp_options['remoteapplicationname:s'] = app
|
|
||||||
|
|
||||||
cmdline_b64 = base64.b64encode(json.dumps(cmdline).encode()).decode()
|
|
||||||
rdp_options['remoteapplicationcmdline:s'] = cmdline_b64
|
|
||||||
return rdp_options
|
|
||||||
|
|
||||||
def get_rdp_file_info(self, token: ConnectionToken):
|
def get_rdp_file_info(self, token: ConnectionToken):
|
||||||
rdp_options = {
|
rdp_options = {
|
||||||
'full address:s': '',
|
'full address:s': '',
|
||||||
|
@ -114,9 +90,10 @@ class RDPFileClientProtocolURLMixin:
|
||||||
rdp_options['session bpp:i'] = os.getenv('JUMPSERVER_COLOR_DEPTH', '32')
|
rdp_options['session bpp:i'] = os.getenv('JUMPSERVER_COLOR_DEPTH', '32')
|
||||||
rdp_options['audiomode:i'] = self.parse_env_bool('JUMPSERVER_DISABLE_AUDIO', 'false', '2', '0')
|
rdp_options['audiomode:i'] = self.parse_env_bool('JUMPSERVER_DISABLE_AUDIO', 'false', '2', '0')
|
||||||
|
|
||||||
# 设置远程应用
|
# 设置远程应用, 不是 Mstsc
|
||||||
remote_app_options = token.get_remote_app_option()
|
if token.connect_method != NativeClient.mstsc:
|
||||||
rdp_options.update(remote_app_options)
|
remote_app_options = token.get_remote_app_option()
|
||||||
|
rdp_options.update(remote_app_options)
|
||||||
|
|
||||||
# 文件名
|
# 文件名
|
||||||
name = token.asset.name
|
name = token.asset.name
|
||||||
|
@ -160,15 +137,17 @@ class RDPFileClientProtocolURLMixin:
|
||||||
'file': {}
|
'file': {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if connect_method_name == NativeClient.mstsc:
|
if connect_method_name == NativeClient.mstsc or connect_method_dict['type'] == 'applet':
|
||||||
filename, content = self.get_rdp_file_info(token)
|
filename, content = self.get_rdp_file_info(token)
|
||||||
data.update({
|
data.update({
|
||||||
|
'protocol': 'rdp',
|
||||||
'file': {
|
'file': {
|
||||||
'name': filename,
|
'name': filename,
|
||||||
'content': content,
|
'content': content,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
|
print("Connect method: {}".format(connect_method_dict))
|
||||||
endpoint = self.get_smart_endpoint(
|
endpoint = self.get_smart_endpoint(
|
||||||
protocol=connect_method_dict['endpoint_protocol'],
|
protocol=connect_method_dict['endpoint_protocol'],
|
||||||
asset=token.asset
|
asset=token.asset
|
||||||
|
|
|
@ -220,11 +220,10 @@ class ConnectMethodUtil:
|
||||||
|
|
||||||
for component, component_protocol in cls.protocols().items():
|
for component, component_protocol in cls.protocols().items():
|
||||||
support = component_protocol['support']
|
support = component_protocol['support']
|
||||||
|
component_web_methods = component_protocol.get('web_methods', [])
|
||||||
|
|
||||||
for protocol in support:
|
for protocol in support:
|
||||||
# Web 方式
|
# Web 方式
|
||||||
protocol_web_methods = set(web_methods.get(protocol, [])) \
|
|
||||||
& set(component_protocol.get('web_methods', []))
|
|
||||||
methods[protocol.value].extend([
|
methods[protocol.value].extend([
|
||||||
{
|
{
|
||||||
'component': component.value,
|
'component': component.value,
|
||||||
|
@ -233,7 +232,8 @@ class ConnectMethodUtil:
|
||||||
'value': method.value,
|
'value': method.value,
|
||||||
'label': method.label,
|
'label': method.label,
|
||||||
}
|
}
|
||||||
for method in protocol_web_methods
|
for method in web_methods.get(protocol, [])
|
||||||
|
if method in component_web_methods
|
||||||
])
|
])
|
||||||
|
|
||||||
# 客户端方式
|
# 客户端方式
|
||||||
|
|
Loading…
Reference in New Issue