diff --git a/apps/audits/signals_handler.py b/apps/audits/signals_handler.py index e25bd9be9..5543cca3b 100644 --- a/apps/audits/signals_handler.py +++ b/apps/audits/signals_handler.py @@ -127,7 +127,11 @@ def on_audits_log_create(sender, instance=None, **kwargs): def get_login_backend(request): backend = request.session.get(BACKEND_SESSION_KEY, '') backend = backend.rsplit('.', maxsplit=1)[-1] - return LOGIN_BACKEND.get(backend, '') + if backend in LOGIN_BACKEND: + return LOGIN_BACKEND[backend] + else: + logger.warn(f'LOGIN_BACKEND_NOT_FOUND: {backend}') + return '' def generate_data(username, request): diff --git a/apps/authentication/signals_handlers.py b/apps/authentication/signals_handlers.py index 4c49f5d55..8174f0db7 100644 --- a/apps/authentication/signals_handlers.py +++ b/apps/authentication/signals_handlers.py @@ -1,5 +1,6 @@ from importlib import import_module +from django.contrib.auth import BACKEND_SESSION_KEY from django.conf import settings from django.contrib.auth import user_logged_in from django.core.cache import cache @@ -24,14 +25,17 @@ def on_user_auth_login_success(sender, user, request, **kwargs): @receiver(openid_user_login_success) def on_oidc_user_login_success(sender, request, user, **kwargs): + request.session[BACKEND_SESSION_KEY] = 'OIDCAuthCodeBackend' post_auth_success.send(sender, user=user, request=request) @receiver(openid_user_login_failed) def on_oidc_user_login_failed(sender, username, request, reason, **kwargs): + request.session[BACKEND_SESSION_KEY] = 'OIDCAuthCodeBackend' post_auth_failed.send(sender, username=username, request=request, reason=reason) @receiver(cas_user_authenticated) def on_cas_user_login_success(sender, request, user, **kwargs): - post_auth_success.send(sender, user=user, request=request) \ No newline at end of file + request.session[BACKEND_SESSION_KEY] = 'CASBackend' + post_auth_success.send(sender, user=user, request=request) diff --git a/apps/common/drf/renders/base.py b/apps/common/drf/renders/base.py index deac735cc..57f035f26 100644 --- a/apps/common/drf/renders/base.py +++ b/apps/common/drf/renders/base.py @@ -27,11 +27,13 @@ class BaseFileRenderer(BaseRenderer): def set_response_disposition(self, response): serializer = self.serializer if response and hasattr(serializer, 'Meta') and hasattr(serializer.Meta, "model"): - model_name = serializer.Meta.model.__name__.lower() - now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") - filename = "{}_{}.{}".format(model_name, now, self.format) - disposition = 'attachment; filename="{}"'.format(filename) - response['Content-Disposition'] = disposition + filename_prefix = serializer.Meta.model.__name__.lower() + else: + filename_prefix = 'download' + now = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + filename = "{}_{}.{}".format(filename_prefix, now, self.format) + disposition = 'attachment; filename="{}"'.format(filename) + response['Content-Disposition'] = disposition def get_rendered_fields(self): fields = self.serializer.fields diff --git a/apps/locale/zh/LC_MESSAGES/django.mo b/apps/locale/zh/LC_MESSAGES/django.mo index 614aa0eec..b4b073c4e 100644 Binary files a/apps/locale/zh/LC_MESSAGES/django.mo and b/apps/locale/zh/LC_MESSAGES/django.mo differ diff --git a/apps/locale/zh/LC_MESSAGES/django.po b/apps/locale/zh/LC_MESSAGES/django.po index 816fdf726..ab3e7cc2a 100644 --- a/apps/locale/zh/LC_MESSAGES/django.po +++ b/apps/locale/zh/LC_MESSAGES/django.po @@ -1015,7 +1015,7 @@ msgstr "没有匹配到资产,结束任务" #: users/templates/users/user_list.html:98 #: users/templates/users/user_remote_app_permission.html:111 msgid "Delete" -msgstr "删除文件" +msgstr "删除" #: audits/models.py:27 msgid "Upload" diff --git a/apps/terminal/api/command.py b/apps/terminal/api/command.py index fdafb1baf..0d5cb1553 100644 --- a/apps/terminal/api/command.py +++ b/apps/terminal/api/command.py @@ -60,7 +60,7 @@ class CommandQueryMixin: queryset = multi_command_storage.filter( date_from=date_from, date_to=date_to, user=q.get("user"), asset=q.get("asset"), system_user=q.get("system_user"), - input=q.get("input"), session=q.get("session_id"), + input=q.get("input"), session=q.get("session_id", q.get('session')), risk_level=self.get_query_risk_level(), org_id=self.get_org_id(), ) return queryset diff --git a/apps/terminal/models/session.py b/apps/terminal/models/session.py index 4e2a1b99a..b35a618bc 100644 --- a/apps/terminal/models/session.py +++ b/apps/terminal/models/session.py @@ -132,7 +132,7 @@ class Session(OrgModelMixin): return None, e if settings.SERVER_REPLAY_STORAGE: - from .tasks import upload_session_replay_to_external_storage + from ..tasks import upload_session_replay_to_external_storage upload_session_replay_to_external_storage.delay(str(self.id)) return name, None @@ -146,10 +146,8 @@ class Session(OrgModelMixin): return cls.objects.filter(is_finished=False) def is_active(self): - if self.protocol in ['ssh', 'telnet', 'rdp', 'mysql']: - key = self.ACTIVE_CACHE_KEY_PREFIX.format(self.id) - return bool(cache.get(key)) - return True + key = self.ACTIVE_CACHE_KEY_PREFIX.format(self.id) + return bool(cache.get(key)) @property def command_amount(self): diff --git a/apps/terminal/serializers/components.py b/apps/terminal/serializers/components.py index e557d8f4f..d6e6d7f56 100644 --- a/apps/terminal/serializers/components.py +++ b/apps/terminal/serializers/components.py @@ -6,17 +6,17 @@ from django.utils.translation import ugettext_lazy as _ class ComponentsStateSerializer(serializers.Serializer): # system system_cpu_load_1 = serializers.FloatField( - required=False, default=0, label=_("System cpu load (1 minutes)") + required=False, label=_("System cpu load (1 minutes)") ) system_memory_used_percent = serializers.FloatField( - required=False, default=0, label=_('System memory used percent') + required=False, label=_('System memory used percent') ) system_disk_used_percent = serializers.FloatField( - required=False, default=0, label=_('System disk used percent') + required=False, label=_('System disk used percent') ) # sessions session_active_count = serializers.IntegerField( - required=False, default=0, label=_("Session active count") + required=False, label=_("Session active count") ) def save(self, **kwargs): diff --git a/apps/terminal/utils.py b/apps/terminal/utils.py index d85e21deb..b480503d5 100644 --- a/apps/terminal/utils.py +++ b/apps/terminal/utils.py @@ -116,7 +116,8 @@ class ComponentsMetricsUtil(object): def get_metrics(self, tp=None): components = self.get_components(tp) - total_count = normal_count = high_count = critical_count = session_active_total = 0 + total_count = normal_count = high_count = critical_count = offline_count = \ + session_active_total = 0 for component in components: total_count += 1 if component.is_alive: @@ -129,12 +130,13 @@ class ComponentsMetricsUtil(object): critical_count += 1 session_active_total += component.state.get('session_active_count', 0) else: - critical_count += 1 + offline_count += 1 return { 'total': total_count, 'normal': normal_count, 'high': high_count, 'critical': critical_count, + 'offline': offline_count, 'session_active': session_active_total } @@ -147,7 +149,8 @@ class ComponentsPrometheusMetricsUtil(ComponentsMetricsUtil): 'any': metrics['total'], 'normal': metrics['normal'], 'high': metrics['high'], - 'critical': metrics['critical'] + 'critical': metrics['critical'], + 'offline': metrics['offline'] } def get_prometheus_metrics_text(self): diff --git a/apps/users/api/relation.py b/apps/users/api/relation.py index 218d52142..bbcb5932b 100644 --- a/apps/users/api/relation.py +++ b/apps/users/api/relation.py @@ -28,3 +28,12 @@ class UserUserGroupRelationViewSet(JMSBulkRelationModelViewSet): return False else: return True + + def perform_create(self, serializer): + validated_data = [] + for item in serializer.validated_data: + if item['user'].role == User.ROLE.AUDITOR: + continue + validated_data.append(item) + serializer._validated_data = validated_data + return super().perform_create(serializer)