From f0e87ef3f87fcaae329cd66f9e49c759d6b14396 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sun, 7 Apr 2024 12:11:44 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20rdp=20token=20=E5=A4=8D=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit perf: connection token --- apps/authentication/api/connection_token.py | 9 +++++++-- apps/authentication/models/connection_token.py | 5 ++++- apps/terminal/connect_methods.py | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/authentication/api/connection_token.py b/apps/authentication/api/connection_token.py index b8690ba28..fbeacb96b 100644 --- a/apps/authentication/api/connection_token.py +++ b/apps/authentication/api/connection_token.py @@ -223,12 +223,17 @@ class ExtraActionApiMixin(RDPFileClientProtocolURLMixin): validate_exchange_token: callable @action(methods=['POST', 'GET'], detail=True, url_path='rdp-file') - def get_rdp_file(self, *args, **kwargs): + def get_rdp_file(self, request, *args, **kwargs): token = self.get_object() token.is_valid() filename, content = self.get_rdp_file_info(token) - filename = '{}.rdp'.format(filename) response = HttpResponse(content, content_type='application/octet-stream') + + if is_true(request.query_params.get('reusable')): + token.set_reusable(True) + filename = '{}-{}'.format(filename, token.date_expired.strftime('%Y%m%d_%H%M%S')) + + filename += '.rdp' response['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' % filename return response diff --git a/apps/authentication/models/connection_token.py b/apps/authentication/models/connection_token.py index 2ef28eab1..f07874a2a 100644 --- a/apps/authentication/models/connection_token.py +++ b/apps/authentication/models/connection_token.py @@ -82,12 +82,15 @@ class ConnectionToken(JMSOrgBaseModel): self.save(update_fields=['date_expired']) def set_reusable(self, is_reusable): + if not settings.CONNECTION_TOKEN_REUSABLE: + return self.is_reusable = is_reusable if self.is_reusable: seconds = settings.CONNECTION_TOKEN_REUSABLE_EXPIRATION else: seconds = settings.CONNECTION_TOKEN_ONETIME_EXPIRATION - self.date_expired = timezone.now() + timedelta(seconds=seconds) + + self.date_expired = self.date_created + timedelta(seconds=seconds) self.save(update_fields=['is_reusable', 'date_expired']) def renewal(self): diff --git a/apps/terminal/connect_methods.py b/apps/terminal/connect_methods.py index 72007112d..0294ccab1 100644 --- a/apps/terminal/connect_methods.py +++ b/apps/terminal/connect_methods.py @@ -34,6 +34,7 @@ class NativeClient(TextChoices): db_client = 'db_client', _('DB Client') # Razor mstsc = 'mstsc', _('Remote Desktop') + rdp_guide = 'rdp_guide', _('RDP Guide') @classmethod def get_native_clients(cls):