{% include 'header.html' %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/servers.css') }}"> {% include 'wrapper.html' %}
<div class="server-page">
    <form action="{{ url_for('delete_server') }}" method="POST" id="delete-server-form"><input type="hidden" name="id" value="{{ server[0] }}"></form>
    <form action="{{ url_for('change_server') }}" method="POST" id="name-form">
        <input type="hidden" value="{{ server[0] }}" name="id">
        <input type="hidden" value="{{ attain }}" id="attain-hidden-input" name="attain">
        <h1 class="head inline"><input type="text" size="12" value="{{ server[2] }}" name="name" placeholder="Name" required> - <input type="text" size="12" value="{{ server[1] }}" name="ip" placeholder="IP" required>

        </h1>
        <select name="section" id="">
            {% for sec in sections %}
                <option value="{{ sec[0] }}" {% if section==sec[1] %}selected="selected"{% endif %}>{{ sec[1] }}</option>
            {% endfor %}
        </select>
        <div class="custom-control custom-checkbox mr-sm-2 inline">
            <input type="checkbox" name="access" class="custom-control-input " id="customControlAutosizing" {% if server[4] %}checked{% endif %}>
            <label class="custom-control-label" for="customControlAutosizing">Access</label>
        </div>

        <div class="edit head">
            <a href="javascript:editServerSubmit();" style="margin-right: 20px;">
                <i class="fas fa-save fa-2x"></i>
            </a>
            {% if server[0] %}
            <a href="javascript:deleteServer()" style="margin-right: 20px;">
                <i class="fas fa-trash fa-2x" style="color: rgb(212, 71, 71);"></i>
            </a>
            <a href="{{ url_for('server')}}?ip={{ server[1] }}"><i class="fas fa-arrow-right fa-2x"></i></a> {% endif %}
        </div>
    </form>
    <div class="container-fluid server-content">
        <div class="row">
            <div class="col col-sm-4 users">
                <form action="{{ url_for('create_user') }}" method="POST" id="user-form">
                    <table class="table table-dark">
                        <thead>
                            <tr class="cols">
                                <th scope="col">Username</th>
                                <th scope="col">Password</th>
                                <th scope="col">Permissions</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td>{{ user[2] }}</td>
                                <td>{{ user[3] }}</td>
                                <td>{{ user[4] }}</td>
                                <td><a href="{{ url_for('delete_user') }}?id={{ user[0] }}" onclick="this.parentElement.parentElement.remove()"><i class="fas fa-trash"
                                            style="margin-left: 15px; color: rgb(212, 71, 71);"></i></a></td>
                            </tr>
                            {% endfor %} {% if server[0] %}
                            <tr>
                                <input type="hidden" name="server_ip" value="{{ server[1] }}">
                                <input type="hidden" name="server_id" value="{{ server[0] }}">
                                <input type="hidden" name="type" value="1">
                                <td><input type="text" size="5" name="username"></td>
                                <td><input type="text" size="7" name="password"></td>
                                <td><input type="text" size="5" name="permissions"></td>
                                <td><a href="javascript:$('#user-form').submit();"><i class="fas fa-plus"
                                            style="margin-left: 15px; color: rgb(61, 122, 202);"></i></a></td>
                            </tr>
                            {% endif %}
                        </tbody>
                    </table>
            </div>
            </form>
            <div class="col col-sm-6 vulns">
                <form action="{{ url_for('create_vuln') }}" method="POST" id="vuln-form">
                    <table class="table table-dark">
                        <thead>
                            <tr class="cols">
                                <th scope="col">Vulnerability</th>
                                <th scope="col">Description</th>
                                <th scope="col">Fix</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for vuln in vulns %}
                            <tr>
                                <td>{{ vuln[1] }}</td>
                                <td>{{ vuln[2] }}</td>
                                <td>{{ vuln[3] }}</td>
                                <td><a href="{{ url_for('delete_vuln') }}?id={{ vuln[0] }}" onclick="this.parentElement.parentElement.remove()"><i class="fas fa-trash"
                                            style="margin-left: 15px; color: rgb(212, 71, 71);"></i></a></td>
                            </tr>
                            {% endfor %} {% if server[0] %}
                            <tr>
                                <input type="hidden" name="server_ip" value="{{ server[1] }}">
                                <input type="hidden" name="server_id" value="{{ server[0] }}">
                                <td><input type="text" size="8" name="name"></td>
                                <td><input type="text" size="40" name="description"></td>
                                <td><input type="text" size="5" name="fix"></td>
                                <td><a href="javascript:$('#vuln-form').submit();"><i class="fas fa-plus"
                                            style="margin-left: 15px; color: rgb(61, 122, 202);"></i></a></td>
                            </tr>
                            {% endif %}
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col col-sm-6 free-text">
                <form action="#" method="POST" id="attain-form">
                    <h1>Attain</h1>
                    <textarea class="form-control" id="attain-input" rows="5" name="attain" style="font-size: 28px;overflow: scroll;word-wrap:break-word;min-height: 200px;max-height: 500px;" placeholder="Attain..">{{ attain }}</textarea>
                </form>
            </div>
            <div class="col col-sm-2">
                <table class="table table-dark ports" style="margin-top: 50px;">
                    <thead>
                        <tr class="cols">
                            <th scope="col">Port</th>
                            <th scope="col">Service</th>
                            <th scope="col">State</th>
                            <th scope="col">Vulnerable</th>
                            <th scope="col">Action</th>
                        </tr>
                    </thead>
                    <form action="{{ url_for('create_server_port') }}" method="POST" id="port-form">
                        <tbody>
                            {% for port in ports %}
                            <tr>
                                <td>{{ port[1] }}</td>
                                <td>{{ port[2] }}</td>
                                <td>{{ port[3] }}</td>
                                <td>{{ port[4] }}</td>
                                <td><a href="{{ url_for('delete_port') }}?id={{ port[0] }}" onclick="this.parentElement.parentElement.remove()"><i class="fas fa-trash"
                                        style="margin-left: 15px; color: rgb(212, 71, 71);"></i></a></td>
                            </tr>
                            {% endfor %} {% if server[0] %}
                            <tr>
                                <input name="server_id" type="hidden" value="{{ server[0] }}">
                                <td><input id="input_port1" name="port" type="text" size="3"></td>
                                <td><input id="input_port2" name="service" type="text" size="3"></td>
                                <td><input id="input_port3" name="state" type="text" size="3"></td>
                                <td><input id="input_port4" name="vuln" type="text" size="5"></td>
                                <td><a href="javascript:$('#port-form').submit();"><i class="fas fa-plus"
                                        style="margin-left: 15px; color: rgb(61, 122, 202);"></i></a></td>
                            </tr>
                            {% endif %}
                        </tbody>
                    </form>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col col-sm-6">
                <table class="table table-dark files" style="width: 680px;">
                    <thead>
                        <tr class="cols">
                            <th scope="col">Filename</th>
                            <th scope="col">Path</th>
                            <th scope="col">Description</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for file in files %}
                        <tr>
                            <td><a>{{ file[1] }}</a></td>
                            <td>{{ file[2] }}</td>
                            <td><a href="{{ url_for('delete_file') }}?id={{ file[0] }}" onclick="this.parentElement.parentElement.remove()"><i class="fas fa-trash"
                                            style="margin-left: 15px; color: rgb(212, 71, 71);"></i></a></td>
                        </tr>
                        {% endfor %} {% if server[0] %}
                        <tr>
                            <td>
                                <form enctype="multipart/form-data" action="{{ url_for('upload_file') }}" method="POST">
                                    <input type="file" id="file_upload" onchange="form.submit()" name="upload_file" multiple>
                                </form>
                            </td>
                        </tr>
                        {% endif %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    // Get the input field
    var input1 = document.getElementById("input_port1");
    var input2 = document.getElementById("input_port2");
    var input3 = document.getElementById("input_port3");
    var input4 = document.getElementById("input_port4");
    input1.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            $('#port-form').submit();
        }
    });
    input2.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            $('#port-form').submit();
        }
    });
    input3.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            $('#port-form').submit();
        }
    });
    input4.addEventListener("keyup", function(event) {
        if (event.keyCode === 13) {
            $('#port-form').submit();
        }
    });
</script>
{% include 'wrapper_end.html' %} {% include 'footer.html' %}