<commit_before>{% extends "base.html" %}

{% block content %}
<div class="container">
    {% if message %}
    <div class="alert alert-{{ message.alert }} alert-dismissible clearfix" role="alert">
        <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
        <div class="pull-left">{{ message.msg }}</div>
    </div>
    {% endif %}

    <form method="post" id="rule_list_form">
        <div class="panel panel-default" style="margin-bottom: 10px">
            <div class="panel-heading"><h2 class="panel-title">Rules</h2></div>
            <div class="table-responsive">
                <table class="table table-striped table-hover table-condensed" id="rulestable">
                    <thead class="thead-inverse">
                        <tr>
                            <th><!-- checkbox --></th>
                            <th><!-- rule action --></th>
                            <th>Interface</th>
                            <th>Protocol</th>
                            <th>Source</th>
                            <th>Port</th>
                            <th>Destination</th>
                            <th>Port</th>
                            <th>NAT / RDR</th>
                            <th>Description</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for rule in rules %}
                        <tr id="rule_row_{{ rule.id }}">
                            <td><input type="checkbox" id="rule_{{ rule.id }}" name="rule_{{ rule.id }}" value="{{ rule.id }}" /></td>
                            <td width="70px">
                                <span title="Traffic is {{ rule.action }}ed" class="glyphicon glyphicon-{% if rule.action == 'pass' %}ok{% elif rule.action == 'match' %}flag{% else %}remove{% endif %} rule-{{ rule.action }}"></span>
                                
                                {% if rule.log %}
                                <span title="Traffic is logged" class="glyphicon glyphicon-tasks"></span>
                                {% endif %}

                                {% if rule.quick %}
                                <span title="Stop matching rules" class="glyphicon glyphicon-alert"></span>
                                {% endif %}
                            </td>
                            <td>{{ rule.iface }}</td>
                            <td>{{ "{} ".format(rule.af) if rule.af != "*" or rule.proto == '*' }}{{ rule.proto if rule.proto != '*' }}</td>
                            <td>{% if rule.src_addr_type == 'table' %}{{ "<{}>".format(rule.src_addr) }}{% else %}{{ rule.src_addr }}{% endif %}</td>
                            <td>{{ port_ops[rule.src_port_op][2].format(rule.src_port) }}</td>
                            <td>{% if rule.dst_addr_type == 'table' %}{{ "<{}>".format(rule.dst_addr) }}{% else %}{{ rule.dst_addr }}{% endif %}</td>
                            <td>{{ port_ops[rule.dst_port_op][2].format(rule.dst_port) }}</td>
                            <td>{% if rule.trans_type %}<span class="glyphicon glyphicon-{% if rule.trans_type == 'NAT' %}resize-horizontal{% elif rule.trans_type == 'RDR' %}circle-arrow-right{% endif %}" title="{{ rule.trans_type }}"></span> {{ "<{}>".format(rule.trans_addr) if rule.trans_addr_type == 'table' else rule.trans_addr }}{% if rule.trans_type == 'RDR' and rule.trans_port[0] %} {{ port_ops[rule.trans_port_op][2].format(rule.trans_port) }}{% endif %}{% endif %}</td>
                            <td>{{ rule.label }}</td>
                            <td align="right">
                                <span class="glyphicon glyphicon-bookmark glyph-link" title="Move checked rules above this one. Ctrl+Click to move selected rules below." id="moveR_{{ rule.id }}"></span>
                                <a href="/firewall/rules/edit/{{ rule.id}}"><span class="glyphicon glyphicon-edit glyph-link" id="action_rule_{{ rule.id }}"></span></a>
                                <span class="glyphicon glyphicon-trash glyph-link" id="action_rule_{{ rule.id }}" onclick="remove_rule({{ rule.id }});"></span>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
         <nav class="action-buttons">
            <button class="btn btn-primary" type="button" value="true" name="move_rules" id="button_save_order" onclick="save_rules_order();" disabled>
                <span class="glyphicon glyphicon-sort"></span> Save Order
            </button>

            <a class="btn btn-success" href="/firewall/rules/edit" role="button">
                <span class="glyphicon glyphicon-plus"></span> Add
            </a>
            <button class="btn btn-danger" type="submit" value="true" name="delete_rules">
                <span class="glyphicon glyphicon-trash"></span> Delete
            </a>
        </nav>
    </form>
</div>

{% endblock %}
{% block footer %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/jquery-ui.min.css') }}">
<script src="{{ url_for('static', filename='js/jquery-ui.min.js') }}"></script>

<script type="text/javascript">
// Select row on click
$('#rulestable > tbody > tr').on('click', function() {
    if($(this).hasClass('selected')) {
        $(this).removeClass('selected');
        $(this).find('input:checkbox:first').prop("checked", false);
    }
    else {
        $(this).addClass('selected');
        $(this).find('input:checkbox:first').prop("checked", true);
    }
});

$('[id^=action_rule_').click(function(event) {
    event.stopImmediatePropagation();
});

// Move rule action
$("[id^=moveR_").click(function(event) {
    // Prevent click from toggling row
    event.stopImmediatePropagation();
    
    // Save target rule position
    var anchor_row = $(this).parents("tr:first");

    if(event.ctrlKey) {
        $($('#rulestable > tbody > tr').get().reverse()).each(function() {
            // Get ID of the row
            ruleid = this.id.slice(9);
            if(ruleid) {
                if($('#rule_' + ruleid).prop('checked')) {
                    // Move selected row and unselect it. Add highlight class
                    $(this).insertAfter(anchor_row);
                    $('#rule_' + ruleid).prop('checked', false);
                    $(this).removeClass('selected');
                    $('#rule_row_' + ruleid).addClass("highlight");
                }
            }
        });
    }
    else {
        $('#rulestable > tbody > tr').each(function() {
            // Get ID of the row
            ruleid = this.id.slice(9);
            if(ruleid) {
                if($('#rule_' + ruleid).prop('checked')) {
                    // Move selected row and unselect it. Add highlight class
                    $(this).insertBefore(anchor_row);
                    $('#rule_' + ruleid).prop('checked', false);
                    $(this).removeClass('selected');
                    $('#rule_row_' + ruleid).addClass("highlight");
                }
            }
        });
    }

    // Fade out highlight color and remove the class
    $('.highlight').effect("highlight", {}, 5000);
    $('#rulestable tr').removeClass("highlight");

    // Enable the save button
    $("#button_save_order").prop("disabled", false);
}).mouseover(function(e) {
    var ruleselected = false;

    // Determine if any rules are selected
    $('[id^=rule_').each(function () {
        if($(this).prop("checked")) {
            ruleselected = true;
        }
    });

    // Modify the icon to show where the rules will go
    if(ruleselected) {
        $(this).removeClass().addClass("glyphicon glyphicon-arrow-up glyph-link text-danger");
    }
}).mouseout(function(e) {
    // Modify the icon back to the original
    $(this).removeClass().addClass("glyphicon glyphicon-bookmark glyph-link");
});

// Hide alerts automatically after time
$('.alert').fadeTo(10000, 500).slideUp(500, function(){
    $(".alert").slideUp(500);
});

// Submit form handler
$("#rule_list_form").submit(function(event) {
    resp = confirm("Are you sure you wish to delete the selected rules?");

    if(resp == false) {
        // Do not submit form
        return false<commit_msg>Fix enabling the save order button when nothing is selected<commit_after>{% extends "base.html" %}

{% block content %}
<div class="container">
    {% if message %}
    <div class="alert alert-{{ message.alert }} alert-dismissible clearfix" role="alert">
        <button type="button" class="close" data-dismiss="alert"><span>&times;</span></button>
        <div class="pull-left">{{ message.msg }}</div>
    </div>
    {% endif %}

    <form method="post" id="rule_list_form">
        <div class="panel panel-default" style="margin-bottom: 10px">
            <div class="panel-heading"><h2 class="panel-title">Rules</h2></div>
            <div class="table-responsive">
                <table class="table table-striped table-hover table-condensed" id="rulestable">
                    <thead class="thead-inverse">
                        <tr>
                            <th><!-- checkbox --></th>
                            <th><!-- rule action --></th>
                            <th>Interface</th>
                            <th>Protocol</th>
                            <th>Source</th>
                            <th>Port</th>
                            <th>Destination</th>
                            <th>Port</th>
                            <th>NAT / RDR</th>
                            <th>Description</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                    {% for rule in rules %}
                        <tr id="rule_row_{{ rule.id }}">
                            <td><input type="checkbox" id="rule_{{ rule.id }}" name="rule_{{ rule.id }}" value="{{ rule.id }}" /></td>
                            <td width="70px">
                                <span title="Traffic is {{ rule.action }}ed" class="glyphicon glyphicon-{% if rule.action == 'pass' %}ok{% elif rule.action == 'match' %}flag{% else %}remove{% endif %} rule-{{ rule.action }}"></span>
                                
                                {% if rule.log %}
                                <span title="Traffic is logged" class="glyphicon glyphicon-tasks"></span>
                                {% endif %}

                                {% if rule.quick %}
                                <span title="Stop matching rules" class="glyphicon glyphicon-alert"></span>
                                {% endif %}
                            </td>
                            <td>{{ rule.iface }}</td>
                            <td>{{ "{} ".format(rule.af) if rule.af != "*" or rule.proto == '*' }}{{ rule.proto if rule.proto != '*' }}</td>
                            <td>{% if rule.src_addr_type == 'table' %}{{ "<{}>".format(rule.src_addr) }}{% else %}{{ rule.src_addr }}{% endif %}</td>
                            <td>{{ port_ops[rule.src_port_op][2].format(rule.src_port) }}</td>
                            <td>{% if rule.dst_addr_type == 'table' %}{{ "<{}>".format(rule.dst_addr) }}{% else %}{{ rule.dst_addr }}{% endif %}</td>
                            <td>{{ port_ops[rule.dst_port_op][2].format(rule.dst_port) }}</td>
                            <td>{% if rule.trans_type %}<span class="glyphicon glyphicon-{% if rule.trans_type == 'NAT' %}resize-horizontal{% elif rule.trans_type == 'RDR' %}circle-arrow-right{% endif %}" title="{{ rule.trans_type }}"></span> {{ "<{}>".format(rule.trans_addr) if rule.trans_addr_type == 'table' else rule.trans_addr }}{% if rule.trans_type == 'RDR' and rule.trans_port[0] %} {{ port_ops[rule.trans_port_op][2].format(rule.trans_port) }}{% endif %}{% endif %}</td>
                            <td>{{ rule.label }}</td>
                            <td align="right">
                                <span class="glyphicon glyphicon-bookmark glyph-link" title="Move checked rules above this one. Ctrl+Click to move selected rules below." id="moveR_{{ rule.id }}"></span>
                                <a href="/firewall/rules/edit/{{ rule.id}}"><span class="glyphicon glyphicon-edit glyph-link" id="action_rule_{{ rule.id }}"></span></a>
                                <span class="glyphicon glyphicon-trash glyph-link" id="action_rule_{{ rule.id }}" onclick="remove_rule({{ rule.id }});"></span>
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
         <nav class="action-buttons">
            <button class="btn btn-primary" type="button" value="true" name="move_rules" id="button_save_order" onclick="save_rules_order();" disabled>
                <span class="glyphicon glyphicon-sort"></span> Save Order
            </button>

            <a class="btn btn-success" href="/firewall/rules/edit" role="button">
                <span class="glyphicon glyphicon-plus"></span> Add
            </a>
            <button class="btn btn-danger" type="submit" value="true" name="delete_rules">
                <span class="glyphicon glyphicon-trash"></span> Delete
            </a>
        </nav>
    </form>
</div>

{% endblock %}
{% block footer %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/jquery-ui.min.css') }}">
<script src="{{ url_for('static', filename='js/jquery-ui.min.js') }}"></script>

<script type="text/javascript">
// Select row on click
$('#rulestable > tbody > tr').on('click', function() {
    if($(this).hasClass('selected')) {
        $(this).removeClass('selected');
        $(this).find('input:checkbox:first').prop("checked", false);
    }
    else {
        $(this).addClass('selected');
        $(this).find('input:checkbox:first').prop("checked", true);
    }
});

$('[id^=action_rule_').click(function(event) {
    event.stopImmediatePropagation();
});

// Move rule action
$("[id^=moveR_").click(function(event) {
    // Prevent click from toggling row
    event.stopImmediatePropagation();
    
    // Save target rule position
    var anchor_row = $(this).parents("tr:first");

    // Store if any rows are selected
    var rows_selected = false

    if(event.ctrlKey) {
        $($('#rulestable > tbody > tr').get().reverse()).each(function() {
            // Get ID of the row
            ruleid = this.id.slice(9);
            if(ruleid) {
                if($('#rule_' + ruleid).prop('checked')) {
                    // Move selected row and unselect it. Add highlight class
                    $(this).insertAfter(anchor_row);
                    $('#rule_' + ruleid).prop('checked', false);
                    $(this).removeClass('selected');
                    $('#rule_row_' + ruleid).addClass("highlight");
                    rows_selected = true
                }
            }
        });
    }
    else {
        $('#rulestable > tbody > tr').each(function() {
            // Get ID of the row
            ruleid = this.id.slice(9);
            if(ruleid) {
                if($('#rule_' + ruleid).prop('checked')) {
                    // Move selected row and unselect it. Add highlight class
                    $(this).insertBefore(anchor_row);
                    $('#rule_' + ruleid).prop('checked', false);
                    $(this).removeClass('selected');
                    $('#rule_row_' + ruleid).addClass("highlight");
                    rows_selected = true
                }
            }
        });
    }

    // Fade out highlight color and remove the class
    $('.highlight').effect("highlight", {}, 5000);
    $('#rulestable tr').removeClass("highlight");

    // Enable the save button
    if(rows_selected) {
        $("#button_save_order").prop("disabled", false);
    }
}).mouseover(function(e) {
    var ruleselected = false;

    // Determine if any rules are selected
    $('[id^=rule_').each(function () {
        if($(this).prop("checked")) {
            ruleselected = true;
        }
    });

    // Modify the icon to show where the rules will go
    if(ruleselected) {
        $(this).removeClass().addClass("glyphicon glyphicon-arrow-up glyph-link text-danger");
    }
}).mouseout(function(e) {
    // Modify the icon back to the original
    $(this).removeClass().addClass("glyphicon glyphicon-bookmark glyph-link");
});

// Hide alerts automatically after time
$('.alert').fadeTo(10000, 500).slideUp(500, function(){
    $(".alert").slideUp(500);
});

// Submit form handler
$("#rule_list_form").submit(function(event) {
    resp = confirm("Are you sure you wish to delete the selected rules?");

    if(resp == false) {
        // Do not submit form
        return false
{'fraction_non_alphanumeric': 0.17422406148389002, 'fraction_numerical': 0.0035471475022169673, 'mean_word_length': 1.7735694376127233, 'pattern_counts': {'":': 0, '<': 231, '<?xml version=': 0, '>': 243, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5688207', 'n_tokens_mistral': 4944, 'n_tokens_neox': 4622, 'n_words': 996}