{% extends 'base.html' %}
{% block content %}
{% include 'nav_cat_bar.html' %}
<style>
    .modal-dialog {
        width: 800px;
    }
    .modal-body {
        background-color: #000000;
    }
</style>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="panel-heading">
                <div class="panel-title m-b-md"><h4> 用户日志详细信息列表 </h4></div>
                <div class="panel-options">

                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1"><i class="fa fa-laptop"></i> 在线 </a></li>
                        <li class=""><a data-toggle="tab" href="#tab-2"><i class="fa fa-bar-chart-o"></i> 历史记录 </a></li>
                    </ul>
                </div>
            </div>
            <div class="panel-body">
                <div class="tab-content">
                    <div id="tab-1" class="ibox float-e-margins tab-pane active">
                        <div class="ibox-content">
                            <table class="table table-striped table-bordered table-hover " id="editable" >
                                <thead>
                                    <tr>
                                        <th class="text-center"> 用户名 </th>
                                        <th class="text-center"> 登录主机 </th>
                                        <th class="text-center"> 实时监控 </th>
                                        <th class="text-center"> 阻断 </th>
                                        <th class="text-center"> 登录时间 </th>
                                        <th class="text-center"> 结束时间 </th>

                                    </tr>
                                </thead>
                                <tbody>
                                {% for post in online %}
                                    <tr class="gradeX">
                                        <td class="text-center"> {{ post.user.name }} </td>
                                        <td class="text-center"> {{ post.asset.ip }} </td>
                                        <td class="text-center"><a class="monitor" href="{{ post.log_path }}" filename="{{ post.log_path }}" onclick="return false"> 监控 </a></td>
                                        <td class="text-center"><a href="/jlog/log_kill/{{ post.pid }}"> 阻断 </a></td>
                                        <td class="text-center"> {{ post.start_time|date:"Y-m-d H:i:s" }} </td>
                                        <td class="text-center"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="tab-2" class="ibox float-e-margins tab-pane">
                        <div class="ibox-content">
                            <table class="table table-striped table-bordered table-hover " id="editable" >
                                <thead>
                                    <tr>
                                        <th class="text-center"> 用户名 </th>
                                        <th class="text-center"> 登录主机 </th>
                                        <th class="text-center"> 命令统计 </th>
                                        <th class="text-center"> 登录时间 </th>
                                        <th class="text-center"> 结束时间 </th>

                                    </tr>
                                </thead>
                                <tbody>
                                {% for post in offline %}
                                    <tr class="gradeX">
                                        <td class="text-center"> {{ post.user.name }} </td>
                                        <td class="text-center"> {{ post.asset.ip }} </td>
                                        <td class="text-center"> 命令统计 </td>
                                        <td class="text-center"> {{ post.start_time|date:"Y-m-d H:i:s"}} </td>
                                        <td class="text-center"> {{ post.end_time|date:"Y-m-d H:i:s" }} </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="tab-2" class="tab-pane">
                        <p>This is tab-2</p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="http://{{ web_socket_host }}/socket.io/socket.io.js"></script>
<script>
   $.fn.webSocket = function(opt){
    var url=$(this).attr("href");
    var st = {};
    st = $.extend(st,opt);
    var message = {};
    var $this = $(this);
    var ws = new WebSocket('ws://127.0.0.1:8888/tail' + "/?file_path=" + url);
    BootstrapDialog.show(function(ev){
        message: ev.data;
    });
}

   $(".monitor").webSocket()
</script>
{% endblock %}