mirror of https://github.com/jumpserver/jumpserver
pref: 修改 endpoint api
parent
b1bd57cd76
commit
fc1b6c9db2
|
@ -23,8 +23,7 @@ class SmartEndpointViewMixin:
|
||||||
target_instance: None
|
target_instance: None
|
||||||
target_protocol: None
|
target_protocol: None
|
||||||
|
|
||||||
@action(methods=['get'], detail=False, permission_classes=[IsValidUserOrConnectionToken],
|
@action(methods=['get'], detail=False, permission_classes=[IsValidUserOrConnectionToken])
|
||||||
url_path='smart')
|
|
||||||
def smart(self, request, *args, **kwargs):
|
def smart(self, request, *args, **kwargs):
|
||||||
self.target_instance = self.get_target_instance()
|
self.target_instance = self.get_target_instance()
|
||||||
self.target_protocol = self.get_target_protocol()
|
self.target_protocol = self.get_target_protocol()
|
||||||
|
@ -57,12 +56,12 @@ class SmartEndpointViewMixin:
|
||||||
asset_id = request.GET.get('asset_id')
|
asset_id = request.GET.get('asset_id')
|
||||||
session_id = request.GET.get('session_id')
|
session_id = request.GET.get('session_id')
|
||||||
token_id = request.GET.get('token')
|
token_id = request.GET.get('token')
|
||||||
|
|
||||||
if token_id:
|
if token_id:
|
||||||
from authentication.models import ConnectionToken
|
from authentication.models import ConnectionToken
|
||||||
token = ConnectionToken.objects.filter(id=token_id).first()
|
token = ConnectionToken.objects.filter(id=token_id).first()
|
||||||
if token and token.asset:
|
if token and token.asset:
|
||||||
asset_id = token.asset.id
|
asset_id = token.asset.id
|
||||||
|
|
||||||
if asset_id:
|
if asset_id:
|
||||||
pk, model = asset_id, Asset
|
pk, model = asset_id, Asset
|
||||||
elif session_id:
|
elif session_id:
|
||||||
|
@ -77,8 +76,6 @@ class SmartEndpointViewMixin:
|
||||||
|
|
||||||
def get_target_protocol(self):
|
def get_target_protocol(self):
|
||||||
protocol = None
|
protocol = None
|
||||||
if isinstance(self.target_instance, Application) and self.target_instance.is_type(Application.APP_TYPE.oracle):
|
|
||||||
protocol = self.target_instance.get_target_protocol_for_oracle()
|
|
||||||
if not protocol:
|
if not protocol:
|
||||||
protocol = self.request.GET.get('protocol')
|
protocol = self.request.GET.get('protocol')
|
||||||
return protocol
|
return protocol
|
||||||
|
|
|
@ -51,12 +51,12 @@ class HttpMethod(TextChoices):
|
||||||
|
|
||||||
class NativeClient(TextChoices):
|
class NativeClient(TextChoices):
|
||||||
# Koko
|
# Koko
|
||||||
ssh = 'ssh', 'ssh'
|
ssh = 'ssh', 'SSH'
|
||||||
putty = 'putty', 'PuTTY'
|
putty = 'putty', 'PuTTY'
|
||||||
xshell = 'xshell', 'Xshell'
|
xshell = 'xshell', 'Xshell'
|
||||||
|
|
||||||
# Magnus
|
# Magnus
|
||||||
mysql = 'mysql', 'MySQL Client'
|
mysql = 'mysql', 'mysql'
|
||||||
psql = 'psql', 'psql'
|
psql = 'psql', 'psql'
|
||||||
sqlplus = 'sqlplus', 'sqlplus'
|
sqlplus = 'sqlplus', 'sqlplus'
|
||||||
redis = 'redis-cli', 'redis-cli'
|
redis = 'redis-cli', 'redis-cli'
|
||||||
|
@ -82,7 +82,7 @@ class NativeClient(TextChoices):
|
||||||
return clients
|
return clients
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_native_methods(cls, os='windows'):
|
def get_methods(cls, os='windows'):
|
||||||
clients_map = cls.get_native_clients()
|
clients_map = cls.get_native_clients()
|
||||||
methods = defaultdict(list)
|
methods = defaultdict(list)
|
||||||
|
|
||||||
|
@ -118,9 +118,9 @@ class NativeClient(TextChoices):
|
||||||
return command
|
return command
|
||||||
|
|
||||||
|
|
||||||
class RemoteAppMethod:
|
class AppletMethod:
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_remote_app_methods(cls):
|
def get_methods(cls):
|
||||||
from .models import Applet
|
from .models import Applet
|
||||||
applets = Applet.objects.all()
|
applets = Applet.objects.all()
|
||||||
methods = defaultdict(list)
|
methods = defaultdict(list)
|
||||||
|
@ -130,7 +130,6 @@ class RemoteAppMethod:
|
||||||
'value': applet.name,
|
'value': applet.name,
|
||||||
'label': applet.display_name,
|
'label': applet.display_name,
|
||||||
'icon': applet.icon,
|
'icon': applet.icon,
|
||||||
'type': 'remote_app',
|
|
||||||
})
|
})
|
||||||
return methods
|
return methods
|
||||||
|
|
||||||
|
@ -153,21 +152,21 @@ class TerminalType(TextChoices):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def protocols(cls):
|
def protocols(cls):
|
||||||
return {
|
protocols = {
|
||||||
cls.koko: {
|
cls.koko: {
|
||||||
'http_method': HttpMethod.web_cli,
|
'web_method': HttpMethod.web_cli,
|
||||||
'listen': [Protocol.ssh, Protocol.http],
|
'listen': [Protocol.ssh, Protocol.http],
|
||||||
'support': [
|
'support': [
|
||||||
Protocol.ssh, Protocol.telnet,
|
Protocol.ssh, Protocol.telnet,
|
||||||
Protocol.mysql, Protocol.postgresql,
|
Protocol.mysql, Protocol.postgresql,
|
||||||
Protocol.oracle, Protocol.sqlserver,
|
Protocol.oracle, Protocol.sqlserver,
|
||||||
Protocol.mariadb, Protocol.redis,
|
Protocol.mariadb, Protocol.redis,
|
||||||
Protocol.mongodb,
|
Protocol.mongodb, Protocol.k8s,
|
||||||
],
|
],
|
||||||
'match': 'm2m'
|
'match': 'm2m'
|
||||||
},
|
},
|
||||||
cls.omnidb: {
|
cls.omnidb: {
|
||||||
'http_method': HttpMethod.web_gui,
|
'web_method': HttpMethod.web_gui,
|
||||||
'listen': [Protocol.http],
|
'listen': [Protocol.http],
|
||||||
'support': [
|
'support': [
|
||||||
Protocol.mysql, Protocol.postgresql, Protocol.oracle,
|
Protocol.mysql, Protocol.postgresql, Protocol.oracle,
|
||||||
|
@ -176,7 +175,7 @@ class TerminalType(TextChoices):
|
||||||
'match': 'm2m'
|
'match': 'm2m'
|
||||||
},
|
},
|
||||||
cls.lion: {
|
cls.lion: {
|
||||||
'http_method': HttpMethod.web_gui,
|
'web_method': HttpMethod.web_gui,
|
||||||
'listen': [Protocol.http],
|
'listen': [Protocol.http],
|
||||||
'support': [Protocol.rdp, Protocol.vnc],
|
'support': [Protocol.rdp, Protocol.vnc],
|
||||||
'match': 'm2m'
|
'match': 'm2m'
|
||||||
|
@ -193,17 +192,17 @@ class TerminalType(TextChoices):
|
||||||
'listen': [Protocol.rdp],
|
'listen': [Protocol.rdp],
|
||||||
'support': [Protocol.rdp],
|
'support': [Protocol.rdp],
|
||||||
'match': 'map'
|
'match': 'map'
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
return protocols
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_protocols_connect_methods(cls, os):
|
def get_protocols_connect_methods(cls, os):
|
||||||
methods = defaultdict(list)
|
methods = defaultdict(list)
|
||||||
native_methods = NativeClient.get_native_methods(os)
|
native_methods = NativeClient.get_methods(os)
|
||||||
remote_app_methods = RemoteAppMethod.get_remote_app_methods()
|
applet_methods = AppletMethod.get_methods()
|
||||||
|
|
||||||
for component, component_protocol in cls.protocols().items():
|
for component, component_protocol in cls.protocols().items():
|
||||||
component_methods = defaultdict(list)
|
|
||||||
support = component_protocol['support']
|
support = component_protocol['support']
|
||||||
|
|
||||||
for protocol in support:
|
for protocol in support:
|
||||||
|
@ -214,19 +213,23 @@ class TerminalType(TextChoices):
|
||||||
|
|
||||||
for listen_protocol in listen:
|
for listen_protocol in listen:
|
||||||
if listen_protocol == Protocol.http:
|
if listen_protocol == Protocol.http:
|
||||||
web_protocol = component_protocol['http_method']
|
web_protocol = component_protocol['web_method']
|
||||||
component_methods[protocol.value].append({
|
methods[protocol.value].append({
|
||||||
'value': web_protocol.value,
|
'value': web_protocol.value,
|
||||||
'label': web_protocol.label,
|
'label': web_protocol.label,
|
||||||
'type': 'web',
|
'type': 'web',
|
||||||
|
'component': component.value,
|
||||||
})
|
})
|
||||||
|
|
||||||
# Native method
|
# Native method
|
||||||
component_methods[protocol.value].extend(native_methods[listen_protocol])
|
methods[protocol.value].extend([
|
||||||
component_methods[protocol.value].extend(remote_app_methods[listen_protocol])
|
{'component': component.value, 'type': 'native', **method}
|
||||||
|
for method in native_methods[listen_protocol]
|
||||||
|
])
|
||||||
|
|
||||||
for protocol, _methods in component_methods.items():
|
for protocol, applet_methods in applet_methods.items():
|
||||||
for method in _methods:
|
for method in applet_methods:
|
||||||
method['component'] = component.value
|
method['type'] = 'applet'
|
||||||
methods[protocol].extend(_methods)
|
method['component'] = cls.tinker.value
|
||||||
|
methods[protocol].extend(applet_methods)
|
||||||
return methods
|
return methods
|
||||||
|
|
Loading…
Reference in New Issue