mirror of https://github.com/jumpserver/jumpserver
pref: 修改添加 connect methods
parent
2a8d63e9cd
commit
fb653f93db
|
@ -1,17 +1,18 @@
|
|||
from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.request import Request
|
||||
|
||||
from common.drf.api import JMSBulkModelViewSet
|
||||
from common.permissions import IsValidUserOrConnectionToken
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.shortcuts import get_object_or_404
|
||||
from assets.models import Asset
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from terminal.models import Session, Endpoint, EndpointRule
|
||||
from terminal import serializers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.generics import ListAPIView
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
|
||||
from assets.models import Asset
|
||||
from common.drf.api import JMSBulkModelViewSet
|
||||
from common.permissions import IsValidUser
|
||||
from common.permissions import IsValidUserOrConnectionToken
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from terminal import serializers
|
||||
from terminal.models import Session, Endpoint, EndpointRule
|
||||
|
||||
__all__ = ['EndpointViewSet', 'EndpointRuleViewSet']
|
||||
|
||||
|
@ -97,3 +98,14 @@ class EndpointRuleViewSet(JMSBulkModelViewSet):
|
|||
search_fields = filterset_fields
|
||||
serializer_class = serializers.EndpointRuleSerializer
|
||||
queryset = EndpointRule.objects.all()
|
||||
|
||||
|
||||
class ConnectMethodListApi(ListAPIView):
|
||||
permission_classes = (IsValidUser,)
|
||||
serializer_class = serializers.ProtocolConnectMethodsSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
protocol = self.request.query_params.get('protocol')
|
||||
if not protocol:
|
||||
return []
|
||||
return Protocol.objects.filter(name=protocol)
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
from django.db.models import TextChoices
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from assets.const import Protocol
|
||||
|
||||
|
||||
# Replay & Command Storage Choices
|
||||
# --------------------------------
|
||||
|
||||
|
@ -48,11 +51,59 @@ class TerminalType(TextChoices):
|
|||
lion = 'lion', 'Lion'
|
||||
core = 'core', 'Core'
|
||||
celery = 'celery', 'Celery'
|
||||
magnus = 'magnus', 'Magnus'
|
||||
razor = 'razor', 'Razor'
|
||||
magnus = 'magnus', 'Magnus'
|
||||
razor = 'razor', 'Razor'
|
||||
tinker = 'tinker', 'Tinker'
|
||||
|
||||
@classmethod
|
||||
def types(cls):
|
||||
return set(dict(cls.choices).keys())
|
||||
|
||||
|
||||
class NativeClient:
|
||||
# Koko
|
||||
ssh = 'ssh', 'ssh'
|
||||
putty = 'putty', 'PuTTY'
|
||||
xshell = 'xshell', 'Xshell'
|
||||
|
||||
# Magnus
|
||||
mysql = 'mysql', 'MySQL Client'
|
||||
psql = 'psql', 'psql'
|
||||
sqlplus = 'sqlplus', 'sqlplus'
|
||||
redis = 'redis-cli', 'redis-cli'
|
||||
|
||||
# Razor
|
||||
mstsc = 'mstsc', 'Remote Desktop'
|
||||
|
||||
@classmethod
|
||||
def commands(cls, name, os):
|
||||
return {
|
||||
'ssh': 'ssh {username}@{hostname} -p {port}',
|
||||
'putty': 'putty -ssh {username}@{hostname} -P {port}',
|
||||
'xshell': '-url ssh://root:passwd@192.168.10.100',
|
||||
'mysql': 'mysql -h {hostname} -P {port} -u {username} -p',
|
||||
'psql': {
|
||||
'default': 'psql -h {hostname} -p {port} -U {username} -W',
|
||||
'windows': 'psql /h {hostname} /p {port} /U {username} -W',
|
||||
},
|
||||
'sqlplus': 'sqlplus {username}/{password}@{hostname}:{port}',
|
||||
'redis': 'redis-cli -h {hostname} -p {port} -a {password}',
|
||||
'mstsc': 'mstsc /v:{hostname}:{port}',
|
||||
}
|
||||
|
||||
|
||||
class ConnectMethod(TextChoices):
|
||||
web_cli = 'web_cli', _('Web CLI')
|
||||
web_gui = 'web_gui', _('Web GUI')
|
||||
native_client = 'native_client', _('Native Client')
|
||||
|
||||
@classmethod
|
||||
def methods(cls):
|
||||
return {
|
||||
Protocol.ssh: [cls.web_cli, cls.native_client],
|
||||
Protocol.rdp: ([cls.web_gui], [cls.native_client]),
|
||||
Protocol.vnc: [cls.web_gui],
|
||||
Protocol.telnet: [cls.web_cli, cls.native_client],
|
||||
Protocol.mysql: [cls.web_cli, cls.web_gui, cls.native_client],
|
||||
Protocol.sqlserver: [cls.web_cli, cls.web_gui],
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
from rest_framework import serializers
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers
|
||||
|
||||
from common.drf.serializers import BulkModelSerializer
|
||||
from common.drf.fields import LabeledChoiceField
|
||||
from common.drf.serializers import BulkModelSerializer
|
||||
from common.utils import get_request_ip, pretty_string, is_uuid
|
||||
from users.serializers import ServiceAccountSerializer
|
||||
from .. import const
|
||||
|
@ -133,3 +133,7 @@ class TerminalRegistrationSerializer(serializers.ModelSerializer):
|
|||
instance.replay_storage = ReplayStorage.default().name
|
||||
instance.save()
|
||||
return instance
|
||||
|
||||
|
||||
class ConnectMethodSerializer(serializers.Serializer):
|
||||
name = serializers.CharField(max_length=128)
|
||||
|
|
Loading…
Reference in New Issue