Merge pull request #5269 from jumpserver/dev

chore: Merge master from dev
pull/5308/head
Orange 2020-12-15 20:35:51 +08:00 committed by GitHub
commit 6d5bec1ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 21 deletions

View File

@ -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):

View File

@ -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)
request.session[BACKEND_SESSION_KEY] = 'CASBackend'
post_auth_success.send(sender, user=user, request=request)

View File

@ -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

Binary file not shown.

View File

@ -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"

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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)