perf: 添加lion终端类型; 修改加入会话校验逻辑(vnc/rdp)

pull/6125/head
Bai 2021-05-17 14:46:40 +08:00 committed by Jiangjie.Bai
parent 5e9006d0c2
commit 189bc9d74a
5 changed files with 7 additions and 13 deletions

View File

@ -16,7 +16,7 @@ PROJECT_DIR = const.PROJECT_DIR
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = CONFIG.SECRET_KEY
# SECURITY WARNING: keep the token secret, remove it if all coco, guacamole ok
# SECURITY WARNING: keep the token secret, remove it if all koko, lion ok
BOOTSTRAP_TOKEN = CONFIG.BOOTSTRAP_TOKEN
# SECURITY WARNING: don't run with debug turned on in production!

View File

@ -90,7 +90,7 @@ class SessionViewSet(OrgBulkModelViewSet):
def filter_queryset(self, queryset):
queryset = super().filter_queryset(queryset)
# 解决guacamole更新session时并发导致幽灵会话的问题
# 解决guacamole更新session时并发导致幽灵会话的问题,暂不处理
if self.request.method in ('PATCH',):
queryset = queryset.select_for_update()
return queryset
@ -98,11 +98,6 @@ class SessionViewSet(OrgBulkModelViewSet):
def perform_create(self, serializer):
if hasattr(self.request.user, 'terminal'):
serializer.validated_data["terminal"] = self.request.user.terminal
sid = serializer.validated_data["system_user"]
# guacamole提交的是id
if is_uuid(sid):
_system_user = get_object_or_404(SystemUser, id=sid)
serializer.validated_data["system_user"] = _system_user.name
return super().perform_create(serializer)
def get_permissions(self):
@ -140,6 +135,7 @@ class SessionReplayViewSet(AsyncApiMixin, viewsets.ViewSet):
def get_replay_data(session, url):
tp = 'json'
if session.protocol in ('rdp', 'vnc'):
# 需要考虑录像播放和离线播放器的约定,暂时不处理
tp = 'guacamole'
download_url = reverse('api-terminal:session-replay-download', kwargs={'pk': session.id})

View File

@ -39,11 +39,6 @@ class StatusViewSet(viewsets.ModelViewSet):
def handle_sessions(self):
session_ids = self.request.data.get('sessions', [])
# guacamole 上报的 session 是字符串
# "[53cd3e47-210f-41d8-b3c6-a184f3, 53cd3e47-210f-41d8-b3c6-a184f4]"
if isinstance(session_ids, str):
session_ids = session_ids[1:-1].split(',')
session_ids = [sid.strip() for sid in session_ids if sid.strip()]
Session.set_sessions_active(session_ids)
def get_queryset(self):

View File

@ -43,6 +43,7 @@ class TerminalTypeChoices(TextChoices):
guacamole = 'guacamole', 'Guacamole'
omnidb = 'omnidb', 'OmniDB'
xrdp = 'xrdp', 'Xrdp'
lion = 'lion', 'Lion'
@classmethod
def types(cls):

View File

@ -109,7 +109,9 @@ class Session(OrgModelMixin):
_PROTOCOL = self.PROTOCOL
if self.is_finished:
return False
if self.protocol in [_PROTOCOL.SSH, _PROTOCOL.TELNET, _PROTOCOL.K8S]:
if self.protocol in [
_PROTOCOL.SSH, _PROTOCOL.VNC, _PROTOCOL.RDP, _PROTOCOL.TELNET, _PROTOCOL.K8S
]:
return True
else:
return False