diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 48d0f4029da18c70d915dfdd2e64c3e2ca976190..04a4282d8c1ca61e7d8caf293db995d03fcf2330 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -254,3 +254,6 @@ class SystemUser(models.Model): except IntegrityError: print('Error continue') continue + + + diff --git a/apps/assets/templates/assets/asset_detail.html b/apps/assets/templates/assets/asset_detail.html index ee75e3e986e9304b6ac7b81a9e4baf4287356bd8..d78da68f46c3133a73dba26870fb8cea4ff96bac 100644 --- a/apps/assets/templates/assets/asset_detail.html +++ b/apps/assets/templates/assets/asset_detail.html @@ -225,6 +225,41 @@ +
+
+ {% trans 'System users' %} +
+
+ + + + + + + + + + + {% for system_user in system_users %} + + + + + {% endfor %} + +
+ +
+ +
{{ system_user.name }} + +
+
+
{% endif %} diff --git a/apps/assets/templates/assets/asset_tag_create.html b/apps/assets/templates/assets/asset_tag_create.html deleted file mode 100644 index f82a86dfedfcafde8d05527a5fb7bb2a2594e3e0..0000000000000000000000000000000000000000 --- a/apps/assets/templates/assets/asset_tag_create.html +++ /dev/null @@ -1,124 +0,0 @@ -{% extends 'base.html' %} -{% load i18n %} -{% load static %} -{% load bootstrap %} -{% block custom_head_css_js %} - - - -{% endblock %} -{% block content %} -
-
-
-
-
-
{{ action }}
- -
- -
-
-
-
-
-
- {% csrf_token %} -

基本信息

- {{ form.name|bootstrap_horizontal }} -
- -
-
-

- {% for asset in assets_on_list %} - - {% endfor %} -

-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
-
-
- - - - - -{% endblock %} - -{% block custom_foot_js %} - -{% endblock %} \ No newline at end of file diff --git a/apps/assets/templates/assets/asset_tag_detail.html b/apps/assets/templates/assets/asset_tag_detail.html deleted file mode 100644 index a479034fcb8471b2130975f7f01a429b4e644755..0000000000000000000000000000000000000000 --- a/apps/assets/templates/assets/asset_tag_detail.html +++ /dev/null @@ -1,277 +0,0 @@ -{% extends 'base.html' %} -{% load static %} -{% load i18n %} - -{% block custom_head_css_js %} - - -{% endblock %} -{% block content %} -
-
-
-
- -
-
-
-
- {{ asset_tag.name }} -
- - - - - - - - - - -
-
-
- - - - - - - - - - - - - - - - -
{% trans 'Tag Name' %}:{{ asset_tag.name }}
{% trans 'Created by' %}:{{ asset_tag.created_by }}
{% trans 'Date created' %}:{{ asset_tag.created_time|date:"Y-m-d H:i:s" }}
-
-
- -
-
- {% trans 'Asset list of ' %} {{ asset_tag.name }} -
- - - - - - - - - - -
-
-
- - - - - - - - - - - - - -
{% trans 'Hostname' %}{% trans 'IP' %}{% trans 'Port' %}{% trans 'Type' %}{% trans 'Valid' %}{% trans 'Action' %}
-
-
-
-
-
-
- {% trans 'Add asset to this tag' %} -
-
- - - - - - - - - - - -
- -
- -
-
-
- -
-
-
-
-
-
- - -{% endblock %} -{% block custom_foot_js %} - -{% endblock %} diff --git a/apps/assets/templates/assets/asset_tags_list.html b/apps/assets/templates/assets/asset_tags_list.html deleted file mode 100644 index 21df7e19bb6f0cf1cdeff0b11f875c0d7fb26715..0000000000000000000000000000000000000000 --- a/apps/assets/templates/assets/asset_tags_list.html +++ /dev/null @@ -1,125 +0,0 @@ -{% extends '_base_list.html' %} -{% load i18n static %} -{% block custom_head_css_js %} - - -{% endblock %} -{#{% block content_left_head %}#} -{# {% trans "Create tag" %}#} -{#{% endblock %}#} -{#{% block table_head %}#} -{# #} -{# #} -{# #} -{# {% trans 'Tag Name' %}#} -{# {% trans 'Asset num' %}#} -{# #} -{#{% endblock %}#} -{#{% block table_body %}#} -{# {% for asset_tag in asset_tags_list %}#} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# {{ asset_tag.name }}#} -{# #} -{# #} -{# {{ asset_tag.asset_set.count }}#} -{# #} -{# {% trans 'Update' %}#} -{# {% trans 'Delete' %}#} -{# #} -{# #} -{# {% endfor %}#} -{#{% endblock %}#} -{#{% block content_bottom_left %}#} -{# #} -{#{% endblock %}#} -{% block table_search %}{% endblock %} -{% block table_container %} -
- {% trans "Create Tag" %} -
- - - - - - - - - - - -
{% trans 'TagName' %}{% trans 'Asset num' %}{% trans 'Action' %}
-
-
- -
- -
-
-
- -{% endblock %} - -{% block custom_foot_js %} - - - -{% endblock %} diff --git a/apps/assets/templates/assets/asset_update.html b/apps/assets/templates/assets/asset_update.html index 0300315faef203a3b001a09622b22ae8c45f6544..c21e50e92f7ba47b23562bcd59d8ea5e50fa97c3 100644 --- a/apps/assets/templates/assets/asset_update.html +++ b/apps/assets/templates/assets/asset_update.html @@ -46,7 +46,6 @@

{% trans 'Other' %}

{{ form.status|bootstrap_horizontal }} {{ form.env|bootstrap_horizontal }} - {{ form.tags|bootstrap_horizontal }} {{ form.comment|bootstrap_horizontal }} {{ form.is_active|bootstrap_horizontal }} diff --git a/apps/jumpserver/urls.py b/apps/jumpserver/urls.py index e49bafb670b532b675304e987aa22987c8507911..b9a878fa8d40f945f662a5178358174a5dfc5a48 100644 --- a/apps/jumpserver/urls.py +++ b/apps/jumpserver/urls.py @@ -19,12 +19,13 @@ Including another URLconf from django.conf.urls import url, include from django.conf import settings from django.conf.urls.static import static -from django.views.generic.base import TemplateView + +from .views import IndexView urlpatterns = [ url(r'^captcha/', include('captcha.urls')), - url(r'^$', TemplateView.as_view(template_name='base.html'), name='index'), + url(r'^$', IndexView.as_view(), name='index'), url(r'^users/', include('users.urls.views_urls', namespace='users')), url(r'^assets/', include('assets.urls.views_urls', namespace='assets')), url(r'^perms/', include('perms.urls.views_urls', namespace='perms')), diff --git a/apps/jumpserver/views.py b/apps/jumpserver/views.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b6a510fff8bb6cbb4a6c2416e4238e66768c2ca5 100644 --- a/apps/jumpserver/views.py +++ b/apps/jumpserver/views.py @@ -0,0 +1,70 @@ +from django.views.generic import TemplateView +from django.utils import timezone +from django.db.models import Count + +from users.utils import AdminUserRequiredMixin +from users.models import User +from assets.models import Asset +from audits.models import ProxyLog + + +class IndexView(AdminUserRequiredMixin, TemplateView): + template_name = 'index.html' + + def get_context_data(self, **kwargs): + seven_days_ago = timezone.now() - timezone.timedelta(days=7) + month_ago = timezone.now() - timezone.timedelta(days=30) + proxy_log_seven_days = ProxyLog.objects.filter(date_start__gt=seven_days_ago, is_failed=False) + proxy_log_month = ProxyLog.objects.filter(date_start__gt=month_ago, is_failed=False) + month_dates = proxy_log_month.dates('date_start', 'day') + month_total_visit = [ProxyLog.objects.filter(date_start__date=d) for d in month_dates] + month_str = [d.strftime('%m-%d') for d in month_dates] + month_total_visit_count = [p.count() for p in month_total_visit] + month_user = [p.values('user').distinct().count() for p in month_total_visit] + month_asset = [p.values('asset').distinct().count() for p in month_total_visit] + month_user_active = User.objects.filter(last_login__gt=month_ago).count() + month_user_inactive = User.objects.filter(last_login__lt=month_ago).count() + month_user_disabled = User.objects.filter(is_active=False).count() + month_asset_active = proxy_log_month.values('asset').distinct().count() + month_asset_inactive = Asset.objects.all().count() - month_asset_active + month_asset_disabled = Asset.objects.filter(is_active=False).count() + week_asset_hot_ten = list(proxy_log_seven_days.values('asset').annotate(total=Count('asset')).order_by('-total')[:10]) + for p in week_asset_hot_ten: + last_login = ProxyLog.objects.filter(asset=p['asset']).order_by('date_start').last() + p['last'] = last_login + last_login_ten = ProxyLog.objects.all().order_by('-date_start')[:10] + for p in last_login_ten: + try: + p.avatar_url = User.objects.get(username=p.user).avatar_url() + except User.DoesNotExist: + p.avatar_url = User.objects.first().avatar_url() + week_user_hot_ten = list(proxy_log_seven_days.values('user').annotate(total=Count('user')).order_by('-total')[:10]) + for p in week_user_hot_ten: + last_login = ProxyLog.objects.filter(user=p['user']).order_by('date_start').last() + p['last'] = last_login + + context = { + 'assets_count': Asset.objects.count(), + 'users_count': User.objects.filter(role__in=('Admin', 'User')).count(), + 'online_user_count': ProxyLog.objects.filter(is_finished=False).values('user').distinct().count(), + 'online_asset_count': ProxyLog.objects.filter(is_finished=False).values('asset').distinct().count(), + 'user_visit_count_weekly': proxy_log_seven_days.values('user').distinct().count(), + 'asset_visit_count_weekly': proxy_log_seven_days.count(), + 'user_visit_count_top_five': proxy_log_seven_days.values('user').annotate(total=Count('user')).order_by('-total')[:5], + 'month_str': month_str, + 'month_total_visit_count': month_total_visit_count, + 'month_user': month_user, + 'mouth_asset': month_asset, + 'month_user_active': month_user_active, + 'month_user_inactive': month_user_inactive, + 'month_user_disabled': month_user_disabled, + 'month_asset_active': month_asset_active, + 'month_asset_inactive': month_asset_inactive, + 'month_asset_disabled': month_asset_disabled, + 'week_asset_hot_ten': week_asset_hot_ten, + 'last_login_ten': last_login_ten, + 'week_user_hot_ten': week_user_hot_ten, + } + + kwargs.update(context) + return super(IndexView, self).get_context_data(**kwargs) diff --git a/apps/ops/templates/ops/task_detail.html b/apps/ops/templates/ops/task_detail.html index bc8fbf68265f5468da1f0dc98e19ac3b350d4efb..612a1abc07bda46092eb889994bd5c3c46dc545d 100644 --- a/apps/ops/templates/ops/task_detail.html +++ b/apps/ops/templates/ops/task_detail.html @@ -73,7 +73,7 @@ {% else %}
-
+
40% Complete (success)
diff --git a/apps/perms/api.py b/apps/perms/api.py index db6f31774527c37e0ebe4dd6deba1212dcdee468..02d583ba18a817e84b41161cf0ec6ce896ef4e9e 100644 --- a/apps/perms/api.py +++ b/apps/perms/api.py @@ -197,7 +197,7 @@ class MyAssetGroupAssetsApi(ListAPIView): permission_classes = (IsValidUser,) def get(self, request, *args, **kwargs): - asset_groups = {} + asset_groups = dict() asset_groups[0] = { 'id': 0, 'name': 'ungrouped', 'assets': [] } @@ -216,7 +216,7 @@ class MyAssetGroupAssetsApi(ListAPIView): asset_json = asset.to_json() asset_json['system_users'] = [su.to_json() for su in system_users] if not asset.groups.all(): - asset_groups[0][assets].append(asset_json) + asset_groups[0]['assets'].append(asset_json) continue for asset_group in asset.groups.all(): if asset_group.id in asset_groups: diff --git a/apps/templates/_base_list.html b/apps/templates/_base_list.html index f88abd9ac56f275160da6755166c380e45cdd484..4448ecae985c8a901af6b2db7b3db8ed3141319e 100644 --- a/apps/templates/_base_list.html +++ b/apps/templates/_base_list.html @@ -1,7 +1,7 @@ {% extends 'base.html' %} {% load static %} {% block custom_head_css_js %} - + diff --git a/apps/templates/_nav.html b/apps/templates/_nav.html index d0a2b907321b34ba965b60bd554657c5b64ee08e..7e2ee4720a42dadab5c2432d81b82d2d50effc3e 100644 --- a/apps/templates/_nav.html +++ b/apps/templates/_nav.html @@ -1,6 +1,6 @@ {% load i18n %}
  • - + {% trans 'Home' %}
  • diff --git a/apps/templates/index.html b/apps/templates/index.html index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..581751f222c6763bc01e32ad50acb96f295edf47 100644 --- a/apps/templates/index.html +++ b/apps/templates/index.html @@ -0,0 +1,478 @@ +{% extends 'base.html' %} +{% load static %} +{% block content %} +
    +
    +
    +
    +
    + Users +
    用户总数
    +
    +
    +

    {{ users_count }}

    + All user +
    +
    +
    +
    +
    +
    + Hosts +
    主机总数
    +
    +
    +

    {{ assets_count }}

    + All host +
    +
    +
    + +
    +
    +
    + Online +
    在线用户
    +
    +
    +

    {{ online_user_count }}

    + Online user +
    +
    +
    + +
    +
    +
    + Connected +
    已连接服务器
    +
    +
    +

    {{ online_asset_count }}

    + Connected host +
    +
    +
    +
    +
    +
    +

    活跃用户TOP5

    + 过去一周共有{{ user_visit_count_weekly }}位用户登录{{ asset_visit_count_weekly }}次服务器. +
      + {% for data in user_visit_count_top_five %} +
    • + + {{ data.total }}次/周 + + {{ forloop.counter }} {{ data.user }} +
    • + {% endfor %} +
    +
    +
    +
    +
    +

    + 活跃用户资产占比 +

    +

    + 以下图形分别描述一个月活跃用户和资产占所有用户主机的百分比 +

    +
    +
    +
    + +
    +
    用户
    +
    +
    +
    +
    主机
    +
    +
    +
    + +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    一周Top10资产
    + +
    +
    +

    一周Top10资产

    + 登录次数及最近一次登录记录. +
    +
    + {% if week_asset_hot_ten %} + {% for data in week_asset_hot_ten %} +
    +
    +
    + + {{ data.asset }} +
    + {{ data.total }}次 +
    +
    +

    最近一次登录用户

    +

    {{ data.last.user }}

    +

    于{{ data.last.date_start |date:"Y-m-d H:i:s" }}

    +
    +
    +
    + {% endfor %} + {% else %} +

    (暂无)

    + {% endif %} +
    +
    +
    +
    +
    +
    +
    最近十次登录
    +
    + 10 Messages +
    +
    +
    +

    登录记录

    + 最近十次登录记录. +
    +
    +
    +
    + {% if last_login_ten %} + {% for login in last_login_ten %} +
    + + image + +
    + {% ifequal login.is_finished 0 %} + {{ login.date_start|timesince }} ago + {% else %} + {{ login.date_start|timesince }} ago + {% endifequal %} + {{ login.user }} 登录了{{ login.asset }}
    + {{ login.date_start }} + +
    +
    + {% endfor %} + {% else %} +

    (暂无)

    + {% endif %} +
    +
    +
    +
    +
    + +
    +
    +
    +
    一周Top10用户
    + +
    +
    +

    一周Top10用户

    + 用户登录次数及最近一次登录记录. +
    +
    + {% if week_user_hot_ten %} + {% for data in week_user_hot_ten %} +
    +
    +
    + + {{ data.user }} +
    + {{ data.total }}次 +
    +
    +

    最近一次登录主机

    +

    {{ data.last.asset }}

    +

    于{{ data.last.date_start |date:"Y-m-d H:i:s" }}

    +
    +
    +
    + {% endfor %} + {% else %} +

    (暂无)

    + {% endif %} +
    +
    +
    +
    +
    + +{% endblock %} + +{% block custom_foot_js %} + + + +{% endblock %} \ No newline at end of file diff --git a/apps/users/templates/users/user_group_detail.html b/apps/users/templates/users/user_group_detail.html index a27c4f91f7969d251284b716391222373f9c8a83..f317183c2e081ee27f80d53a32ed959cb6642981 100644 --- a/apps/users/templates/users/user_group_detail.html +++ b/apps/users/templates/users/user_group_detail.html @@ -5,7 +5,7 @@ {% block custom_head_css_js %} - + diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 64dfed303d967f207db1dba433ad2a8fdc639f3c..7353390d2f4d9c2f386377902e197b16c222ff8b 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -7,7 +7,7 @@ ForgeryPy==0.1 openpyxl==2.4.0 celery==3.1.23 paramiko==2.1.1 -ansible==2.1.2.0 +ansible==2.2.2.0 django-simple-captcha==0.5.2 django-formtools==1.0 sshpubkeys==2.2.0 @@ -20,4 +20,3 @@ tornado==4.4.2 eventlet==0.20.1 django-filter==1.0.0 passlib==1.7.1 -sshpass diff --git a/utils/clean_migrations.sh b/utils/clean_migrations.sh index c1c8e6e09668000b477d9ef004e6bdd0b958f62a..b5493dc0dfa3e33cd058c0fc39cb632331ec9eb7 100755 --- a/utils/clean_migrations.sh +++ b/utils/clean_migrations.sh @@ -2,5 +2,5 @@ # for app in users assets perms audits ops applications;do - rm -f ../apps/$app/migrations/000* + rm -f ../apps/$app/migrations/00* done