{% extends "base.html" %}

{% block title %}Debug actions{% 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;
    }
}

function audit_specific_event(elem){
    let relative_url = elem.getAttribute("url");
    let audit_id = document.getElementById('audit').value;
    let absolute_url = new URL(relative_url + audit_id, document.baseURI).href;
    window.location.href = absolute_url;
}
</script>

    <ul>
        <li>Download templates from Pwndoc to Scan2Report
            <ul>
                <li><a href="{{ url_for('api_templates.export_as_scan2report_native') }}">and get it as zip archive</a></li>
                <li><a href="{{ url_for('api_templates.download_templates_from_pwndoc_to_scan2report', output_format='scan2report_native') }}">Without HTML tags (for DOCX generation) - one locale only</a> </li>
                <li><a href="{{ url_for('api_templates.download_templates_from_pwndoc_to_scan2report', output_format='scan2report_with_pwndoc_formatting') }}">With escaping for further processing - one locale only</a></li>
            </ul>
        </li>
        <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><a href="{{ url_for('api_templates.warnings') }}">Status page for problems with 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 (except Pwndoc)(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.show_newly_grouped_or_aliased_findings', audit_id="")}}" onclick="audit_specific_event(this);">List newly grouped or aliased findings</a> </li>
        <li><a href="#" url="{{ url_for('api_debug.debug_download_audit', audit_id="")}}" onclick="audit_specific_event(this);">Download to debug_tmp the audit and it's findings</a> </li>
        <li><a href="#" url="{{ url_for('api_process_findings.force_upload_services', audit_id="")}}" onclick="audit_specific_event(this);">Force upload of seen services for the table of services</a></li>
        <li><a href="#" url="{{ url_for('api_pwndoc_audit.report_download', audit_id="")}}" onclick="audit_specific_event(this);">Generate PwnDoc docx result with an extended timeout</a></li>
    </ul>


{% endblock %}
