{% extends "base.html" %}
{% import "macros.html" as macros %}

{% block javascript %}
{{ super() }}
<script type="text/javascript">
    $(function () {
        $('#formtabs a:first').tab('show');
    });

    $(document).on('click', '#btnWizardPrev', function () {
        $('#HoneypotWizard').wizard('previous');
    });

    $(document).on('click', '#btnWizardNext', function () {
        $('#HoneypotWizard').wizard('next', 'foo');
    });

    function show_tab_with_errors() {
        var divCollection = document.getElementsByTagName("div");
        for (var i = 0; i < divCollection.length; i++) {

            if (divCollection[i].getAttribute("class") == "control-group error") {
                console.log(divCollection[i].parentNode.parentNode);
                var id = divCollection[i].parentNode.parentNode.id;
                $('[href=#' + id + ']').tab('show');
                break;
            }
        }
    }

    $(document).ready(function () {
        show_tab_with_errors();
    });
</script>
{% endblock %}

{% block content %}
<div>
    <h3>Honeypot Configuration</h3>

    <p>
        You can use the tabs below to customize your new honeypot configuration. When you're done,
        click on the generate button.
    </p>
</div>

<form action="" method="post" class="form form-horizontal">
    {{ form.hidden_tag() }}
    {{ macros.form_errors(form, 'only') }}
    <div class="tabbable tabs-left">
        <ul class="nav nav-tabs" id="formtabs">
            <li><a href="#general" data-toggle="tab">General</a></li>
            <li><a href="#http" data-toggle="tab">HTTP</a></li>
            <li><a href="#https" data-toggle="tab">HTTPs</a></li>
            <li><a href="#ftp" data-toggle="tab">FTP</a></li>
            <li><a href="#smtp" data-toggle="tab">SMTP</a></li>
            <li><a href="#vnc" data-toggle="tab">VNC</a></li>
            <li><a href="#telnet" data-toggle="tab">Telnet</a></li>
            <li><a href="#pop3" data-toggle="tab">POP3</a></li>
            <li><a href="#pop3s" data-toggle="tab">POP3s</a></li>
            <li><a href="#ssh" data-toggle="tab">SSH</a></li>
            <li><a href="#certificate" data-toggle="tab">Certificate</a></li>
        </ul>

        <div class="tab-content">

            <div id="general" class="tab-pane">
                <fieldset>
                    <legend>General Options</legend>
                    {% for field in [form.general__name] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="http" class="tab-pane">
                <fieldset>
                    <legend>HTTP Options</legend>
                    {% for field in [form.capabilities__http__enabled, form.capabilities__http__port,
                    form.capabilities__http__protocol_specific_data__banner] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="https" class="tab-pane">
                <fieldset>
                    <legend>HTTPs Options</legend>
                    {% for field in [form.capabilities__https__enabled, form.capabilities__https__port,
                    form.capabilities__https__protocol_specific_data__banner] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="ftp" class="tab-pane">
                <fieldset>
                    <legend>FTP Options</legend>
                    {% for field in [form.capabilities__ftp__enabled,
                    form.capabilities__ftp__protocol_specific_data__banner, form.capabilities__ftp__port,
                    form.capabilities__ftp__protocol_specific_data__max_attempts,
                    form.capabilities__ftp__protocol_specific_data__syst_type] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="smtp" class="tab-pane">
                <fieldset>
                    <legend>SMTP Options</legend>
                    {% for field in [form.capabilities__smtp__enabled,
                    form.capabilities__smtp__protocol_specific_data__banner, form.capabilities__smtp__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="vnc" class="tab-pane">
                <fieldset>
                    <legend>VNC Options</legend>
                    {% for field in [form.capabilities__vnc__enabled, form.capabilities__vnc__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="telnet" class="tab-pane">
                <fieldset>
                    <legend>Telnet Options</legend>
                    {% for field in [form.capabilities__telnet__enabled,
                    form.capabilities__telnet__protocol_specific_data__max_attempts, form.capabilities__telnet__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="pop3" class="tab-pane">
                <fieldset>
                    <legend>POP3 Options</legend>
                    {% for field in [form.capabilities__pop3__enabled,
                    form.capabilities__pop3__protocol_specific_data__max_attempts, form.capabilities__pop3__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="pop3s" class="tab-pane">
                <fieldset>
                    <legend>POP3s Options</legend>
                    {% for field in [form.capabilities__pop3s__enabled,
                    form.capabilities__pop3s__protocol_specific_data__max_attempts, form.capabilities__pop3s__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>

            <div id="ssh" class="tab-pane">
                <fieldset>
                    <legend>SSH Options</legend>
                    {% for field in [form.capabilities__ssh__enabled, form.capabilities__ssh__port] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>
            <div id="certificate" class="tab-pane">
                <fieldset>
                    <legend>Certificate information</legend>
                    This certificate information will be used for encrypted services (POP3s, HTTPs, etc).
                    {% for field in [form.certificate_info__common_name, form.certificate_info__country,
                    form.certificate_info__state, form.certificate_info__organization,
                    form.certificate_info__organization_unit, form.certificate_info__locality] %}
                    {% if not field|bootstrap_is_hidden_field %}
                    {{ macros.horizontal_field(field) }}
                    {%- endif %}
                    {% endfor %}
                </fieldset>
            </div>
        </div>
    </div>
    <hr>
    <div class="controls">
        <button name="submit" type="submit" class="btn btn-primary">Generate</button>
    </div>
</form>
{% endblock content %}
