{% extends "base.html" %}
{% load staticfiles %}
{% block content %}
<style>
.btn-file {
    position: relative;
    overflow: hidden;
}
.btn-file input[type=file] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 999px;
    text-align: right;
    filter: alpha(opacity=0);
    opacity: 0;
    background: red;
    cursor: inherit;
    display: block;
}
input[readonly] {
    background-color: white !important;
    cursor: text !important;
}
</style>
<script type='text/javascript'>
$(document)
    .on('change', '.btn-file :file', function() {
        var input = $(this),
        numFiles = input.get(0).files ? input.get(0).files.length : 1,
        label = input.val().replace(/\\/g, '/').replace(/.*\//, '');
        input.trigger('fileselect', [numFiles, label]);
});

$(document).ready( function() {
    $('.btn-file :file').on('fileselect', function(event, numFiles, label) {

        var input = $(this).parents('.input-group').find(':text'),
            log = numFiles > 1 ? numFiles + ' files selected' : label;

        if( input.length ) {
            input.val(log);
        } else {
            if( log ) alert(log);
        }

    });
});
</script>
<div class="row">
    <div class="col-md-6 col-md-offset-3 center">

        <form role="form" action="" method="post" enctype="multipart/form-data">{% csrf_token %}
            <div class="tabbable">
                {% if not resubmit %}
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#file" data-toggle="tab"><span class="glyphicon glyphicon-file"></span> File</a></li>
                    <li><a href="#url" data-toggle="tab"><span class="glyphicon glyphicon-globe"></span> URL</a></li>
                </ul>
                {% endif %}
                <div class="tab-content">
                    <div class="tab-pane fade {% if not resubmit or resubmit == "file" %}in active{% endif %}" id="file">
                        {% if resubmit == "file" %}
                        <label style="display: flex; color: #337ab7;">Chosen file to resubmit</label>
                        <input name="category" type="text" class="form-control hidden" value="file">
                        {% if dropped_file %}
                        <input name="category" type="text" class="form-control hidden" value="dropped_file">
                        {% endif %}
                        {% endif %}
                        <div class="input-group col-md-6">
                            <span class="input-group-btn">
                            {% if resubmit %}
                                <input type="text" class="form-control" disabled value="{{file_name}}">
                                <input name="sample_id" type="text" class="form-control hidden" value="{{sample_id}}">
                            {% else %}
                                <input type="text" class="form-control" readonly>
                                <span class="btn btn-primary btn-file">
                                    Select <input type="file" name="sample" multiple="multiple">
                                </span>
                            {% endif %}
                            </span>
                        </div>
                    </div>
                    <div class="tab-pane fade {% if resubmit == "URL" %}in active{% endif %}" id="url">
                        {% if resubmit == "URL" %}
                        <label style="display: flex; color: #337ab7;">Chosen URL to resubmit</label>
                        <input name="category" type="text" class="form-control hidden" value="URL">
                        {% endif %}
                        <div style="width: 100%;" class="input-group">
                            <label class="sr-only" form="form_url">URL</label>
                            <input type="text" class="form-control" id="form_url" name="url" placeholder="URL" {% if url %} value="{{url}}" {% endif %} />
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel" id="accordion" style="margin-top: 20px;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <strong>Network routing through <i>dirty line</i> or VPN</strong>
                    </div>
                    <div class="panel-body">
                        <select class="form-control" id="form_route" name="route">
                            <option value="none">None (no internet access)</option>
                            {% if internet != "none" %}
                                <option value="internet"{% if route == "internet" %} selected{% endif %}>Internet (dirty line, {{ internet }})</option>
                            {% endif %}
                            {% for vpn in vpns %}
                                <option value="{{ vpn.name }}"{% if route == vpn.name %} selected{% endif %}>{{ vpn.description }} (VPN, {{ vpn.interface }})</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
            </div>
            <div class="panel" id="accordion" style="margin-top: 20px;">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#options"><i class="icon icon-cog"></i> Advanced Options</a>
                    </div>
                    <div id="options" class="panel-collapse collapse {% if resubmit %}in{% endif %}" style="text-align: left;">
                        <div class="panel-body">
                            <div class="form-group">
                                <label for="form_package">Analysis Package</label>
                                <select class="form-control" id="form_package" name="package">
                                    <option value="" active>Detect Automatically</option>
                                    {% for package in packages %}
                                    <option value="{{package}}">{{package}}</option>
                                    {% endfor %}
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="form_timeout">Timeout</label>
                                <input type="text" class="form-control" id="form_timeout" name="timeout" />
                            </div>
                            <div class="form-group">
                                <label for="form_options">Options</label>
                                <input type="text" class="form-control" id="form_options" name="options" value="{{ options }}" />
                            </div>
                            <div class="form-group">
                                <label for="form_priority">Priority</label>
                                <select class="form-control" id="form_priority" name="priority">
                                    <option value="1">Low</option>
                                    <option value="2" selected>Medium</option>
                                    <option value="3">High</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="form_machine">Machine</label>
                                <select class="form-control" id="form_machine" name="machine">
                                {% for id,label in machines %}
                                    <option value="{{id}}">{{label}}</option>
                                {% endfor %}
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="form_custom">Custom</label>
                                <input type="text" class="form-control" id="form_custom" name="custom" />
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="free" /> No Injection <span class="text-muted"><small>(disable behavioral analysis)</small></span>
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="process_memory" checked /> Process Memory Dump
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="memory" /> Full Memory Dump <span class="text-muted"><small>(if the "memory" processing module is enabled, will launch a Volatility analysis)</small></span>
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="enforce_timeout" /> Enforce Timeout
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="human" checked />Enable Simulated Human Interaction</input>
                                </label>
                            </div>
                            <div class="checkbox">
                                <label>
                                    <input type="checkbox" name="services" />Enable Services <span class="text-muted"><small>(enable simulated environment specified in the auxiliary configuration)</small></span>
                                </label>
                            </div>
                            <div class="form-group">
                                <label for="form_tags">Tags</label>
                                <input type="text" class="form-control" id="form_tags" name="tags" />
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="margin-top: 20px;"><button type="submit" class="btn btn-primary btn-lg">Analyze</button></div>
        </form>
    </div>
</div>
{% endblock %}
