博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
主机管理+堡垒机系统开发:前端显示审计日志(九)
阅读量:5044 次
发布时间:2019-06-12

本文共 17393 字,大约阅读时间需要 57 分钟。

一、目录结构

 

二、实现代码

1、views

from django.shortcuts import render,redirect,HttpResponsefrom django.contrib.auth.decorators import login_requiredfrom django.contrib.auth import authenticate,logout,loginfrom  django.conf import settingsimport os,re,jsonfrom backend import audit# Create your views here.def json_date_handler(obj):    if hasattr(obj, 'isoformat'):        return obj.strftime("%Y-%m-%d %T")@login_requireddef dashboard(request):    return render(request,'index.html')def acc_login(request):    error_msg = ''    if request.method == "POST":        username = request.POST.get('username')        password = request.POST.get('password')        user = authenticate(username=username,password=password)        if user:            login(request,user)            return redirect("/")        else:            error_msg = "Wrong username or password!"    return render(request,"login.html",{'error_msg':error_msg})def acc_logout(request):    logout(request)    return redirect("/login/")@login_requireddef webssh(request):    return render(request,'web_ssh.html')@login_requireddef user_audit(request):    log_dirs = os.listdir(settings.AUDIT_LOG_DIR)    return render(request,'user_audit.html',locals())@login_requireddef audit_log_date(request,log_date):    log_date_path = "%s/%s" %(settings.AUDIT_LOG_DIR,log_date)    log_file_dirs = os.listdir(log_date_path)    session_ids = [re.search("\d+",i).group() for i in log_file_dirs ]    session_objs = models.Session.objects.filter(id__in=session_ids)    return render(request, 'user_audit_file_list.html', locals())

 2、url

from django.conf.urls import urlfrom django.contrib import adminfrom web import viewsurlpatterns = [    url(r'^admin/', admin.site.urls),    url(r'^$', views.dashboard),    url(r'^user_audit/$', views.user_audit,name="user_audit"),    url(r'^audit_log/(\w+-\w+-\w+)/$', views.audit_log_date,name="audit_log_date"),    url(r'^audit_log/(\w+-\w+-\w+)/(\d+)/$', views.audit_log_detail,name="audit_log_detail"),    url(r'^login/$', views.acc_login),    url(r'^logout/$', views.acc_logout,name="logout"),]

3、settings

STATICFILES_DIRS = (    os.path.join(BASE_DIR,'statics'),)

4、base.html

1   2   3   4     
5
6 CrazyEye | 智能堡垒机 7 8 9
10
11 12 13
14
15 16 17
18
19 20 21
22
23 24 25 26 27
28
29 30
31
32 33 34 35 36
51 52 53 54 55
56
57 58 59 {% block body %}body content{% endblock %} 60 61 62 63 64
65
66 67
68 69 70 71
72 73 74 75
76 77 78 79
80 81 82 83
98 99 100 101
base

5、index.html

1 {% extends 'base.html' %}  2   3 {% block body %}  4     
805
806
807 {% endblock %}
index

6、login.html

1 {% extends 'base.html' %} 2  3 
4
5 6 {% block body %} 7
8 9
10
11
19
20 21 22
23
24
25
26
27

Sign In to your account

28
{% csrf_token %}29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
46
47
48
49
50
51
52
{ { error_msg }}53
54 55
56
57
58
62
63
64 65 66 67
68
69
70 71 {% endblock %}
login

7、user_audit.html

{% extends 'index.html' %}{% block page-title %}用户审计{% endblock %}{% block page-content %}

审计目录

{% endblock %}

8、user_audit_detail.html

{% extends 'index.html' %}{% block page-title %}用户审计{% endblock %}{% block page-content %}

审计详情 主机:

{% for cmd in cmd_list %}
{% endfor %}
id 日期 命令
{ { forloop.counter }} { { cmd.0 }} { { cmd.1 }}
{% endblock %}

9、user_audit_file_list.html

{% extends 'index.html' %}{% block page-title %}用户审计{% endblock %}{% block page-content %}

审计日志列表

{% for session_obj in session_objs %}
{% endfor %}
Session ID 堡垒机用户 登录时间 登录主机 登录用户名 停留时间 执行命令数
{ { session_obj.id }} { { session_obj.user.name }} { { session_obj.date }} { { session_obj.bind_host.host.hostname }}({ { session_obj.bind_host.host.ip_addr }}) { { session_obj.bind_host.remote_user.username }} ... ...
{% endblock %}

三、测试截图

1、审计列表

2、审计目录

 3、审计详情主机

 

转载于:https://www.cnblogs.com/luoahong/p/9499656.html

你可能感兴趣的文章