{% include 'header.html' %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/servers.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/users.css') }}"> {% include 'wrapper.html' %}
<div class="server-page main-page">
    <div class="hidden-box-darken">
    <h1 class="head" style="border-bottom-color: {{ color }};">
        <span class="editable">{{ server[2] }}</span>
        <input class="editable-inp" style="display:none;" type="text" size="10" value="{{ server[2] }}" name="name" placeholder="Name">
        <input class="editable-type" type="hidden" value="name">
        <input class="editable-obj" type="hidden" value="servers">
        <input class="editable-id" type="hidden" value="{{ server[0] }}"> - <span class="editable-2 ip" title="{% if vendor %} {{ vendor }} {% else %} {% endif %}">{{ server[1] }}</span>
        <input class="editable-inp-2" style="display:none;" type="text" size="10" value="{{ server[1] }}" name="ip" placeholder="IP">
        <input class="editable-type-2" type="hidden" value="ip">
        <input class="editable-obj-2" type="hidden" value="servers">
        <input class="editable-id-2" type="hidden" value="{{ server[0] }}">
    </h1>
    <select name="section" id="{{ server[0] }}">
        {% for sec in sections %}
            <option value="{{ sec[0] }}" {% if section==sec[1] %}selected="selected"{% endif %}>{{ sec[1] }}</option>
        {% endfor %}
    </select>
    <select class="color-picker" name="colors" id="{{ server[0] }}">
        {% for data in colors %}
            {% if data[2] == color %}
                <option id="{{ data[0] }}" value="{{ data[2] }}" selected="selected">{{ data[1] }}</option>
            {% else %}
                <option id="{{ data[0] }}" value="{{ data[2] }}">{{ data[1] }}</option>
            {% endif %}
        {% endfor %}
    </select>
    
    <div class="head-right">
        <div class="tags">
            {% for tag in tags %}
                <div class="tag normal-tag {{ tag['color'] }}" id="{{ tag['id'] }}">{{ tag['name'] }}<input type="hidden" class="tag-color" value="{{ tag['color'] }}"></div>
            {% endfor %}
            <a href="#" class="tag grey add-tag">+</a>
        </div>
    </div>
    <div class="container-fluid hidden-box-darken 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">Type</th>
                                <th scope="col">Permisions</th>
                                <th scope="col">Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td><a class="hover-user-details editable" style="padding: 5px 10px;" id="user-{{ user[0] }}" href="#" onmouseover="showUser('{{ user[2] }}', '{{ user[3] }}', '{{ user[1] }}', '{{ user[4] }}', '{{ user[5] }}', '{{ user[0] }}')">{{ user[2] }}</a>
                                    <input class="editable-inp" size="5" maxlength="15" type="text" value="{{ user[2] }}">
                                    <input class="editable-type" type="hidden" value="username">
                                    <input class="editable-obj" type="hidden" value="user">
                                    <input class="editable-id" type="hidden" value="{{ user[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ user[3] }}</span>
                                    <input class="editable-inp" size="5" maxlength="30" type="text" value="{{ user[3] }}">
                                    <input class="editable-type" type="hidden" value="password">
                                    <input class="editable-obj" type="hidden" value="user">
                                    <input class="editable-id" type="hidden" value="{{ user[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ user[1] }}</span>
                                    <input class="editable-inp" size="5" maxlength="15" type="text" value="{{ user[1] }}">
                                    <input class="editable-type" type="hidden" value="type">
                                    <input class="editable-obj" type="hidden" value="user">
                                    <input class="editable-id" type="hidden" value="{{ user[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ user[4] }}</span>
                                    <input class="editable-inp" size="8" maxlength="15" type="text" value="{{ user[4] }}">
                                    <input class="editable-type" type="hidden" value="permissions">
                                    <input class="editable-obj" type="hidden" value="user">
                                    <input class="editable-id" type="hidden" value="{{ user[0] }}">
                                </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 %}
                            <tr class="item-add">
                                <input type="hidden" name="server_ip" value="{{ server[1] }}">
                                <input type="hidden" name="server_id" value="{{ server[0] }}">
                                <!--input type="hidden" id="user-type-input" name="user_type" value="Unknown"-->
                                <td><input type="text" size="5" maxlength="15" name="username" placeholder="User"></td>
                                <td><input type="text" size="5" maxlength="30" name="password" placeholder="Pass"></td>
                                <td><input type="text" size="5" maxlength="15" name="user_type" placeholder="Type"></td>
                                <td><input type="text" size="8" maxlength="15" name="permissions" placeholder="Perm"></td>
                                <td><a onclick="getElementById('user-form').submit()" href="#"><i class="fas fa-plus"
                            style="margin: 5px 15px; font-size: 18px;"></i></a></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
            <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>
                                    <span class="editable">{{ vuln[1] }}</span>
                                    <input class="editable-inp" maxlength="40" type="text" value="{{ vuln[1] }}">
                                    <input class="editable-type" type="hidden" value="name">
                                    <input class="editable-obj" type="hidden" value="vuln">
                                    <input class="editable-id" type="hidden" value="{{ vuln[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ vuln[2] }}</span>
                                    <input class="editable-inp" maxlength="60" type="text" value="{{ vuln[2] }}">
                                    <input class="editable-type" type="hidden" value="data">
                                    <input class="editable-obj" type="hidden" value="vuln">
                                    <input class="editable-id" type="hidden" value="{{ vuln[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ vuln[3] }}</span>
                                    <input class="editable-inp" maxlength="10" type="text" value="{{ vuln[3] }}">
                                    <input class="editable-type" type="hidden" value="fix">
                                    <input class="editable-obj" type="hidden" value="vuln">
                                    <input class="editable-id" type="hidden" value="{{ vuln[0] }}">
                                </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 %}
                            <tr class="item-add">
                                <input type="hidden" name="server_ip" value="{{ server[1] }}">
                                <input type="hidden" name="server_id" value="{{ server[0] }}">
                                <td><input type="text" name="name" maxlength="40" placeholder="Name"></td>
                                <td><input type="text" name="description" maxlength="60" placeholder="Description"></td>
                                <td><input type="text" name="fix" maxlength="10" placeholder="Recommendation"></td>
                                <td><a href="javascript:$('#vuln-form').submit();"><i class="fas fa-plus"
                            style="margin-left: 15px;"></i></a></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col col-sm-6 free-text">
                <h1>Description</h1>
                <!-- This was previously called Attain -->
                <p class="editable" style="white-space: pre-wrap;font-size: 28px;overflow: scroll;word-wrap:break-word;white-space:pre-wrap;max-height: 200px;">{{ attain }}</p>
                <textarea class="desc-add form-control editable-inp" id="attain-input" rows="5" name="Description" placeholder="Description..">{{ attain }}</textarea>
                <input class="editable-obj" type="hidden" value="description">
                <input class="editable-id" type="hidden" value="{{ server[0] }}">
                <input class="editable-type" type="hidden" value="attain">
            </div>

            <div class="col col-sm-auto">
                <select value="None" style="height: 40px;width: 150px; margin: 8px;" onchange="sort_ports()" class="select-ports" id="state" name="sort_ports">
                    <option value="All" selected disabled hidden>All</option>
                    <option value="All">All</option>
                    <option value="Open">Open</option>
                    <option value="Filtered">Filtered</option>
                    <option value="Closed">Closed</option>
                </select>
                <form action="{{ url_for('create_server_port') }}" method="POST" id="port-form">
                    <table id="ports_table" class="table table-dark ports">
                        <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>
                        <tbody>
                            {% for port in ports %}
                            <tr>
                                <td>
                                    <span class="editable">{{ port[1] }}</span>
                                    <input class="editable-inp" maxlength="10" size="3" type="text" value="{{ port[1] }}">
                                    <input class="editable-type" type="hidden" value="port">
                                    <input class="editable-obj" type="hidden" value="port">
                                    <input class="editable-id" type="hidden" value="{{ port[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ port[2] }}</span>
                                    <input class="editable-inp" maxlength="10" size="3" type="text" value="{{ port[2] }}">
                                    <input class="editable-type" type="hidden" value="service">
                                    <input class="editable-obj" type="hidden" value="port">
                                    <input class="editable-id" type="hidden" value="{{ port[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ port[3] }}</span>
                                    <select value="None" style="display: none;" class="editable-inp" name="state">
                                        <option>Open</option>
                                        <option>Filtered</option>
                                        <option>Closed</option>
                                    </select>
                                    <input class="editable-type" type="hidden" value="state">
                                    <input class="editable-obj" type="hidden" value="port">
                                    <input class="editable-id" type="hidden" value="{{ port[0] }}">
                                </td>
                                <td>
                                    <span class="editable">{{ port[4] }}</span>
                                    <input class="editable-inp" maxlength="10" size="10" type="text" value="{{ port[4] }}">
                                    <input class="editable-type" type="hidden" value="vuln">
                                    <input class="editable-obj" type="hidden" value="port">
                                    <input class="editable-id" type="hidden" value="{{ port[0] }}">
                                </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 %}
                            <tr class="item-add">
                                <input name="server_id" type="hidden" value="{{ server[0] }}">
                                <td><input id="input_port1" name="port" maxlength="5" type="text" size="3" placeholder="Port"></td>
                                <td><input id="input_port2" name="service" maxlength="12" type="text" size="6" placeholder="Service"></td>
                                <td>
                                    <select value="None" class="editable-inp" name="state">
                                        <option value="Open">Open</option>
                                        <option value="Filtered">Filtered</option>
                                        <option value="Closed">Closed</option>
                                    </select>
                                </td>
                                <td><input id="input_port4" name="vuln" maxlength="10" type="text" size="10" placeholder="Vuln"></td>
                                <td><a href="javascript:$('#port-form').submit();"><i class="fas fa-plus"
                      style="margin-left: 15px"></i></a></td>
                            </tr>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
        <div class="row">
            <div class="col col-sm-6">
                <table style="overflow: scroll;max-height: 300px;" class="table table-dark files">
                    <thead>
                        <tr class="cols">
                            <th scope="col">Filename</th>
                            <th scope="col">Path</th>
                            <th scope="col">Description</th>
                            <th scope="col">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for file in files %}
                        <tr>
                            <td><a id="{{ file[2] }}" name="{{ file[1] }}" href="{{ url_for('files',file_name=file[2]) }}" download="{{ file[1] }}">{{ file[1] }}</a></td>
                            <td>{{ file[2] }}</td>
                            <td>{{ file[3] }}</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 %}
                        <tr class="item-add">
                            <td>
                                <form enctype="multipart/form-data" action="{{ url_for('upload_file') }}" method="POST">
                                    <label class="file-upload-label">
                                        <input type="file" id="file_upload" onchange="form.submit()" name="upload_file" multiple>
                                        <i class="fas fa-file-upload" style="margin-right: 10px;"></i>Upload file
                                    </label>
                                </form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <a class="delete-server floating-btn delete-server-btn " href="#" onclick="deleteServer('{{ server[0] }}')" title="Delete Server">
        <i class="fas fa-trash"></i>
    </a> 
    </div>
    <div class="hidden-floating-box" id="tag-box">
        <form action="{{ url_for('save_tag') }}" method="POST" id="tag-form">
            <div class="page-head">Server Tag</div>
            <input type="hidden" value="" class="server-id-input" name="server-id">
            <input type="hidden" value="" class="tag-id-input" name="tag-id">
            <input type="text" value="" name="tag-name" placeholder="Tag name" class="tag-name-input">
            <div class="">
                <label class="checkbox-container ">
                    <input type="checkbox" value="red" name="color">
                    <span class="checkbox-indicator red" id="tag-red"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="blue" name="color">
                    <span class="checkbox-indicator blue" id="tag-blue"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="green" name="color">
                    <span class="checkbox-indicator green" id="tag-green"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="yellow" name="color">
                    <span class="checkbox-indicator yellow" id="tag-yellow"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="white" name="color">
                    <span class="checkbox-indicator white" id="tag-white"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="grey" name="color">
                    <span class="checkbox-indicator grey" id="tag-grey"></span>
                </label>
                <label class="checkbox-container ">
                    <input type="checkbox" value="purple" name="color">
                    <span class="checkbox-indicator purple" id="tag-purple"></span>
                </label>
            </div>
            <div class="buttons">
                <a class="save-tag floating-btn" href="#" onclick="document.getElementById('tag-form').submit();">
                    <i class="fas fa-edit"></i><span> Save </span>
                </a>
                <a class="delete-tag floating-btn" href="#">
                    <i class="fas fa-trash"></i><span> Delete </span>
                </a>
            </div>

        </form>
    </div>
{% include 'user.html' %}
</div>
</div>
{% include 'wrapper_end.html' %}
<script>
    key_sc($(".delete-server-btn"), 'd');
</script>
<script src="{{ url_for('static', filename='js/server.js') }}"></script>
<script src="{{ url_for('static', filename='js/users.js') }}"></script>
{% include 'footer.html' %}