{% extends "base.html" %}

{% block title %}Debug actions{% endblock %}

{% block headerEnd %}
<script src="{{ url_for('static', filename='audit_selector.js') }}" type="text/javascript" charset="utf-8"></script>
{% endblock %}


{% block content %}

<script type="text/javascript">
function dangerous_button_confirmation(elem){
    if (confirm("Are you sure you want to perform a dangerous function? \n" + elem.text) == true) {
        let relative_url = elem.getAttribute("url");
        let absolute_url = new URL(relative_url, document.baseURI).href;
        /* fetch(absolute_url).then((response) => console.debug(response)); */
        window.location.href = absolute_url;
    }
}

</script>

    <ul>
{#        <li><a href="{{ url_for('api_templates.import_scan2report_templates_to_pwndoc') }}">Upload templates from Scan2Report to Pwndoc</a></li>#}

        <li><a href="{{ url_for('api_debug.download_api_examples') }}">Download generic information from Pwndoc (excluding audits)</a></li>
        <li><a href="#" url="{{ url_for('api_debug.force_upload_init_data') }}" onclick="dangerous_button_confirmation(this);">Empty out Pwndoc DB by force (DANGEROUS)</a></li>
        <li><a href="#" url="{{ url_for('api_debug.delete_vulnerability_templates') }}" onclick="dangerous_button_confirmation(this);">Delete all vulnerability templates (DANGEROUS)</a></li>
        <li><a href="{{ url_for('api_debug.reinit_importer_pwndoc_id_mapping') }}">Re-synchronize FID to PwnDoc ID mappings</a></li>

        <li><a href="{{ url_for('api_debug.force_unescape_old_templates') }}">Force un-escape old templates</a></li>

        <li>View or download logs
            <ul>
                <li><a href="{{ url_for('api_debug.debug_download_logs', log_name='main') }}">Main (from Flask)</a></li>
                <li><a href="{{ url_for('api_debug.debug_download_logs', log_name='gunicorn_access') }}">Access (from gunicorn)</a></li>
                <li><a href="{{ url_for('api_debug.debug_download_logs', log_name='gunicorn_error') }}">Error (from gunicorn)</a></li>
                <li><a href="{{ url_for('api_debug.debug_download_logs', log_name='pwndoc') }}">Pwndoc Backend Logs - Raw</a></li>
                <li><a href="{{ url_for('api_debug.make_pwndoc_human_readable_log') }}">Pwndoc Backend Logs - Beautified</a></li>
                <li><a href="{{ url_for('api_debug.debug_download_logs', log_name='everything') }}">Everything (as zip archive)</a></li>
            </ul>
        </li>
    </ul>

    <hr>

    Actions specific to an audit: <br>
    <label for="audit">Pwndoc audit:</label>
    <select name="audit" id="audit">
        {% for audit_id, audit_name in audits_dict %}
            <option value="{{audit_id}}">{{audit_name}} - {{audit_id}}</option>
        {% endfor %}
    </select>
    <br>
    <ul>
        <li><a href="#" url="{{ url_for('api_debug.debug_download_audit', audit_id="AUDIT_ID_PLACEHOLDER")}}" onclick="audit_specific_event(this);">Download to debug_tmp the audit and it's findings</a> </li>
    </ul>


{% endblock %}
