<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Network Vulnerability Scanner</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    <style>
        body { font-family: Consolas, monospace; margin: 40px; }
        .form-section { margin-bottom: 20px; }
        .ports-list { display: flex; flex-wrap: wrap; gap: 10px; }
        .port-checkbox { margin-right: 10px; }
        .results { margin-top: 30px; }
    </style>
</head>
<body>
    <div class="top-row">
          <h1>Network Vulnerability Scanner</h1>

           <div class="menu">
                <ul>
                    <li><a href="{{ url_for('index') }}">HOME</a></li>
                    <li><a href="{{ url_for('ports') }}">PORTS INFORMATION</a></li>
                    <li><a href="{{ url_for('services') }}">SERVICE</a></li>
                    <li><a href="{{ url_for('about') }}">ABOUT</a></li>
                </ul>
        </div>
    </div>

    <form method="post">
       <!--<div class="center-container"></div>-->
        <div class="form-section">
            <label for="target">Target IP or Hostname:</label>
            <input type="text" id="target" name="target" required value="{{ target }}">
        </div>
        <div class="form-section">
            <label>Select Ports to Scan:</label>
        </div>

            <div class="ports-list">
                {% for port in common_ports %}
                    <label class="port-checkbox">
                        <input type="checkbox" name="ports" value="{{ port }}" {% if port|string in selected_ports %}checked{% endif %}>
                        {{ port }}
                    </label>
                {% endfor %}
            </div>
        <!-- Additional ports textbox -->
        <div class="form-section">
            <label for="additional_ports">Additional Ports:</label>
            <input type="text" id="additional_ports" name="additional_ports" value="{{ additional_ports|default('') }}" placeholder="e.g. 1234, 5678, 8081" pattern="[0-9,\s-]+" title="Enter port numbers separated by commas (e.g., 1234, 5678, 8081)">
            <div style="font-size: 14px; color: #888; margin-top: 4px;">
                Enter additional ports separated by commas. Supports ranges (e.g., 1000-2000) and individual ports (e.g., 1234, 5678, 8081).
            </div>
        </div>
        <button type="submit">Scan</button>
    </form>

    {% if target and all_ports %}
    <div class="results">
        <h2>Selected Target and Ports</h2>
        <p><strong>Target:</strong> {{ target }}</p>
        <p><strong>Ports:</strong> {{ all_ports|join(', ') }}</p>
    </div>
    {% endif %}

    {% if scan_results and scan_results.scan %}
    <div class="results">
        <h2>Scan Results</h2>
        <table border="1" cellpadding="5" cellspacing="0">
            <tr>
                <th>Port</th>
                <th>Protocol</th>
                <th>State</th>
                <th>Service</th>
                <th>Version</th>
                <th>Vulnerabilities (CVEs)</th>
            </tr>
            {% for port_info in scan_results.scan %}
            <tr>
                <td>{{ port_info.port }}</td>
                <td>{{ port_info.protocol }}</td>
                <td>{{ port_info.state }}</td>
                <td>{{ port_info.name }}</td>
                <td>{{ port_info.version }}</td>
                <td>
                    {% set cves = cve_results.get(port_info.port, []) %}
                    {% if cves %}
                        <ul>
                        {% for cve in cves %}
                            <li>
                                <strong>{{ cve.id }}</strong>: {{ cve.summary }}<br>
                                {% if cve.cvss %}CVSS: {{ cve.cvss }}<br>{% endif %}
                                {% if cve.published %}Published: {{ cve.published }}<br>{% endif %}
                                {% if cve.references %}
                                    <a href="{{ cve.references[0] }}" target="_blank">Reference</a>
                                {% endif %}
                            </li>
                        {% endfor %}
                        </ul>
                    {% else %}
                        No known CVEs found.
                    {% endif %}
                </td>
            </tr>
            {% endfor %}
        </table>
    </div>
    {% elif scan_results and scan_results.error %}
    <div class="results">
        <h2>Scan Error</h2>
        <p>{{ scan_results.error }}</p>
    </div>
    {% endif %}
</body>
</html>
