一、目录结构

主机管理+堡垒机系统开发:前端显示审计日志(九)

 

二、实现代码

1、views

from django.shortcuts import render,redirect,HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate,logout,login
from  django.conf import settings
import os,re,json

from backend import audit
# Create your views here.

def json_date_handler(obj):
    if hasattr(obj, 'isoformat'):
        return obj.strftime("%Y-%m-%d %T")



@login_required
def 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_required
def webssh(request):
    return render(request,'web_ssh.html')

@login_required
def user_audit(request):

    log_dirs = os.listdir(settings.AUDIT_LOG_DIR)


    return render(request,'user_audit.html',locals())


@login_required
def 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 url
from django.contrib import admin
from web import views

urlpatterns = [
    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 <!DOCTYPE html>
  2 <html lang="en">
  3 <head>
  4     <meta charset="utf-8">
  5     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6     <title>CrazyEye | 智能堡垒机</title>
  7 
  8 
  9     <!--STYLESHEET-->
 10     <!--=================================================-->
 11 
 12 
 13     <!--Bootstrap Stylesheet [ REQUIRED ]-->
 14     <link href="/static/css/bootstrap.min.css" rel="stylesheet">
 15 
 16 
 17     <!--Nifty Stylesheet [ REQUIRED ]-->
 18     <link href="/static/css/nifty.min.css" rel="stylesheet">
 19 
 20 
 21     <!--Font Awesome [ OPTIONAL ]-->
 22     <link href="/static/css/font-awesome.min.css" rel="stylesheet">
 23 
 24 
 25     
 26 
 27     <!--SCRIPT-->
 28     <!--=================================================-->
 29 
 30     <!--Page Load Progress Bar [ OPTIONAL ]-->
 31     <link href="/static/css/pace.min.css" rel="stylesheet">
 32     <script src="/static/js/pace.min.js"></script>
 33 
 34 
 35     
 36     <!--
 37 
 38     REQUIRED
 39     You must include this in your project.
 40 
 41     RECOMMENDED
 42     This category must be included but you may modify which plugins or components which should be included in your project.
 43 
 44     OPTIONAL
 45     Optional plugins. You may choose whether to include it in your project or not.
 46 
 47 
 48     Detailed information and more samples can be found in the document.
 49 
 50     -->
 51         
 52 
 53 </head>
 54 
 55 <!--TIPS-->
 56 <!--You may remove all ID or Class names which contain "demo-", they are only used for demonstration. -->
 57 
 58 <body>
 59     {% block body %}body content{% endblock %}
 60 
 61 
 62     
 63     
 64     <!--JAVASCRIPT-->
 65     <!--=================================================-->
 66 
 67     <!--jQuery [ REQUIRED ]-->
 68     <script src="/static/js/jquery-2.1.1.min.js"></script>
 69 
 70 
 71     <!--BootstrapJS [ RECOMMENDED ]-->
 72     <script src="/static/js/bootstrap.min.js"></script>
 73 
 74 
 75     <!--Fast Click [ OPTIONAL ]-->
 76     <script src="/static/js/fastclick.min.js"></script>
 77 
 78     
 79     <!--Nifty Admin [ RECOMMENDED ]-->
 80     <script src="/static/js/nifty.min.js"></script>
 81 
 82     
 83     <!--
 84 
 85     REQUIRED
 86     You must include this in your project.
 87 
 88     RECOMMENDED
 89     This category must be included but you may modify which plugins or components which should be included in your project.
 90 
 91     OPTIONAL
 92     Optional plugins. You may choose whether to include it in your project or not.
 93 
 94 
 95     Detailed information and more samples can be found in the document.
 96 
 97     -->
 98         
 99 
100 </body>
101 </html>
base

相关文章:

  • 2021-11-18
  • 2021-08-02
  • 2021-11-19
  • 2021-07-16
  • 2021-11-23
  • 2021-10-15
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-10-30
  • 2021-11-19
  • 2021-06-20
  • 2021-05-19
  • 2021-12-09
  • 2021-09-15
  • 2021-08-26
相关资源
相似解决方案