{% extends "pages/main.html" %}
{% load staticfiles %}
{% block title %} Sysmon Configuration {% endblock %}

{% block container %}

<h2>Configuration</h2>


<div>
    <div class="panel-group" id="accordion">
        <div class="panel panel-red panel-danger">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="accordion" href="#collapseOne"> Blackbox configuration </a>
                </h4>
            </div>
            <div id="collapseOne" class="panel-collapse collapse in">
                <div class="panel-body">
                    <p> <b style="color:red;">Warning :</b>
                    Enabling security controls doesn't prevent your application from being vulnerable,
                        some violations may be false positives and somme attacks may be not detected.
                    </p>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                          <tr>
                            <th>Control type</th>
                            <th>Status</th>
                            <th>Description</th>
                            <th>Severity</th>
                            <th>Entries</th>
                          </tr>
                        </thead>
                        <tbody>
                         {% for control in blackbox_controls %}
                          <tr>
                            <td> <a href="{% url 'control_details' control.name %}"> {{ control.name }} </a></td>
                            <td>
                               {% if control.enabled %}
                                <span class="label label-success" style="font-size: 100%;">
                                    <input type="checkbox" checked onchange="update_control('{{ control.name }}', 'OFF')"> ON
                                </span>
                                {% else %}
                                <span class="label label-danger" style="font-size: 100%;">
                                    <input type="checkbox" onchange="update_control('{{ control.name }}', 'ON')"> OFF
                                </span>
                                {% endif %}
                            </td>
                            <td> {{ control.description }} </td>
                            <td>
                            <span style="display: block; width: 60px;" class=
                            {% if control.severity.name == "HIGH" %} "label label-danger">
                            {% elif control.severity.name == "MEDIUM" %} "label label-warning">
                            {% elif control.severity.name == "LOW" %} "label label-info severity">
                            {% else %} "label label-default severity">
                            {% endif %}
                            {{ control.severity.name }}</span>
                            </td>
                            <td>{{ control.entries|length }}</td>
                          </tr>
                         {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="accordion" href="#collapseTwo"> Incoming HTTP requests logging attributes </a>
                </h4>
            </div>
            <div id="collapseTwo" class="panel-collapse collapse">
                <div class="panel-body">
                    <p> Events to log when an http request is received by the server.</p>
                </div>
                 <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                          <tr>
                            <th>Log rule</th>
                            <th>Status</th>
                            <th>Description</th>
                          </tr>
                        </thead>
                        <tbody>
                         {% for rule in log_http_attributes %}
                          <tr>
                            <td> {{ rule.name }} </td>
                            <td>
                                {% if rule.enabled %}
                                <span class="label label-success" style="font-size: 100%;">
                                    <input type="checkbox" checked onchange="update_rule('{{ rule.name }}', 'HTTP', 'OFF')"> ON
                                </span>
                                {% else %}
                                <span class="label label-danger" style="font-size: 100%;">
                                    <input type="checkbox" onchange="update_rule('{{ rule.name }}', 'HTTP', 'ON')"> OFF
                                </span>
                                {% endif %}
                            </td>
                              <td> {{ rule.description }} </td>
                          </tr>
                         {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="accordion" href="#collapseThree"> View logging attributes </a>
                </h4>
            </div>
            <div id="collapseThree" class="panel-collapse collapse">
                <div class="panel-body">
                    <p> Events to log when a view is being processed by the server.</p>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                          <tr>
                            <th>Log rule</th>
                            <th>Status</th>
                            <th>Description</th>
                          </tr>
                        </thead>
                        <tbody>
                         {% for rule in log_view_attributes %}
                          <tr>
                            <td> {{ rule.name }} </td>
                            <td>
                                {% if rule.enabled %}
                                <span class="label label-success" style="font-size: 100%;">
                                    <input type="checkbox" checked onchange="update_rule('{{ rule.name }}', 'VIEW', 'OFF')"> ON
                                </span>
                                {% else %}
                                <span class="label label-danger" style="font-size: 100%;">
                                    <input type="checkbox" onchange="update_rule('{{ rule.name }}', 'VIEW', 'ON')"> OFF
                                </span>
                                {% endif %}
                            </td>
                              <td> {{ rule.description }} </td>
                          </tr>
                         {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="accordion" href="#collapseFour"> Response logging attributes </a>
                </h4>
            </div>
            <div id="collapseFour" class="panel-collapse collapse">
                <div class="panel-body">
                    <p> Events to log when a response is emitted from the server.</p>
                </div>
                <div class="table-responsive">
                    <table class="table table-striped">
                        <thead>
                          <tr>
                            <th>Log rule</th>
                            <th>Status</th>
                            <th>Description</th>
                          </tr>
                        </thead>
                        <tbody>
                         {% for rule in log_response_attributes %}
                          <tr>
                            <td> {{ rule.name }} </td>
                            <td>
                                {% if rule.enabled %}
                                <span class="label label-success" style="font-size: 100%;">
                                    <input type="checkbox" checked onchange="update_rule('{{ rule.name }}', 'RESPONSE', 'OFF')"> ON
                                </span>
                                {% else %}
                                <span class="label label-danger" style="font-size: 100%;">
                                    <input type="checkbox" onchange="update_rule('{{ rule.name }}', 'RESPONSE', 'ON')"> OFF
                                </span>
                                {% endif %}
                            </td>
                              <td> {{ rule.description }} </td>
                          </tr>
                         {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
	<p><strong>Note:</strong> Click on the linked heading text to expand or collapse panels.</p>
</div>


<script type="application/javascript">
    function update_rule(name, kind, status) {
        $.ajax({
            dataType: 'text',
            type:'POST',
            url: '{% url 'update_log_rule' %}',
            data: {
                rule_name: name,
                kind: kind,
                status: status
            },
            success: function(response){
                location.reload();
            }
        });
    }

    function update_control(name, status) {
        $.ajax({
            dataType: 'text',
            type:'POST',
            url: '{% url 'update_control_status' %}',
            data: {
                control_name: name,
                status: status
            },
            success: function(response){
                location.reload();
            }
        });
    }
</script>
{% endblock %}

