{% extends "base.html" %}

{% block title %}Dashboard - {{ super() }}{% endblock %}

{% block content %}

<section class="content-header">
    <h1>Dashboard</h1>
    <ol class="breadcrumb">
        <li><a href="{{ url_for('main.home') }}">OpenCVE</a></li>
        <li class="active">Dashboard</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <div class="col-md-9">
            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">Filter</h3>
                </div>
                <div class="box-body">
                    <div class="row">
                        <div class="col-sm-4 col-md-4 col-lg-4">
                            <form method="GET">
                                <div class="input-group pull-left">
                                    <span class="input-group-btn">
                                    <button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button>
                                    </span>
                                        <input type="text" placeholder="Search" class="form-control" name="search"
                                            value="{% if request.args.get('search') %}{{ request.args.get('search') }}{% endif %}">
                                </div>
                            </form>
                        </div>
                        <div class="col-sm-8 col-md-8 col-lg-8">
                            <div class="pull-right">
                                <a class="btn {% if request.args.get('cvss') %}btn-default{% else %}btn-primary{% endif %}"
                                    href="{{ url_for('main.home', search=request.args.get('search')) }}">ALL</a>
                                <div class="btn-group">
                                    <a class="btn {% if request.args.get('cvss') == 'none' %}btn-primary{% else %}btn-default{% endif %}"
                                    href="{{ url_for('main.home', cvss='none', search=request.args.get('search')) }}"
                                    type="button">NONE (0.0)</a>
                                    <a class="btn {% if request.args.get('cvss') == 'low' %}btn-primary{% else %}btn-default{% endif %}"
                                    href="{{ url_for('main.home', cvss='low', search=request.args.get('search')) }}"
                                    type="button">LOW (0.1 - 3.9)</a>
                                    <a class="btn {% if request.args.get('cvss') == 'medium' %}btn-primary{% else %}btn-default{% endif %}"
                                    href="{{ url_for('main.home', cvss='medium', search=request.args.get('search')) }}"
                                    type="button">MEDIUM (4.0 - 6.9)</a>
                                    <a class="btn {% if request.args.get('cvss') == 'high' %}btn-primary{% else %}btn-default{% endif %}"
                                    href="{{ url_for('main.home', cvss='high', search=request.args.get('search')) }}"
                                    type="button">HIGH (7.0 - 8.9)</a>
                                    <a class="btn {% if request.args.get('cvss') == 'critical' %}btn-primary{% else %}btn-default{% endif %}"
                                    href="{{ url_for('main.home', cvss='critical', search=request.args.get('search')) }}"
                                    type="button">CRITICAL (9.0 - 10.0)</a>
                                </div>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class='col-md-12'>
                    {% if cves.items %}
                    <div class="box box-primary">
                        <div class="box-body table-responsive no-padding">
                            <table class="table">
                                <thead>
                                <th>CVE</th>
                                <th>Vendors</th>
                                <th>Products</th>
                                <th class="text-center">Updated</th>
                                <th class="text-center">CVSS v2</th>
                                <th class="text-center">CVSS v3</th>
                                </thead>
                                {% for cve in cves.items %}
                                <tr>
                                    <td class="col-md-2"><a href="{{ url_for('.cve', cve_id=cve.cve_id) }}"><strong>{{
                                        cve.cve_id }}</strong></a></td>
                                    <td class="col-md-3">{{ cve.vendors|vendors_excerpt|safe }}</td>
                                    <td class="col-md-3">{{ cve.vendors|products_excerpt|safe }}</td>
                                    <td class="col-md-2 text-center">{{ cve.updated_at.strftime('%Y-%m-%d') }}</td>
                                    {% if cve.json.impact.baseMetricV2 %}
                                    <td class="col-md-1 text-center"><span
                                            class="label {{ cvss_bg(cve.json.impact.baseMetricV2.cvssV2.baseScore)[1] }}">{{ cve.json.impact.baseMetricV2.cvssV2.baseScore }} {{ cve.json.impact.baseMetricV2.severity }}</span>
                                    </td>
                                    {% else %}
                                    <td class="col-md-1 text-center"><span class="label label-default">N/A</span></td>
                                    {% endif %}
                                    {% if cve.json.impact.baseMetricV3 %}
                                    <td class="col-md-1 text-center"><span
                                            class="label {{ cvss_bg(cve.json.impact.baseMetricV3.cvssV3.baseScore)[1] }}">{{ cve.json.impact.baseMetricV3.cvssV3.baseScore }} {{ cve.json.impact.baseMetricV3.cvssV3.baseSeverity }}</span>
                                    </td>
                                    {% else %}
                                    <td class="col-md-1 text-center"><span class="label label-default">N/A</span></td>
                                    {% endif %}
                                </tr>
                                <tr>
                                    <td class="col-md-12 no-bordered" colspan="5">{{ cve.summary }}</td>
                                </tr>
                                {% endfor %}
                            </table>

                            {% if pagination %}
                            <div class="center">
                                {{ pagination.links }}
                            </div>
                            {% endif %}
                        </div>
                    </div>
                    {% else %}
                    <p class="alert alert-info">No CVE found, subscribe to <a href="{{ url_for('main.vendors') }}">vendors
                        and products</a> to display their CVE in your dashboard.</p>
                    {% endif %}
                </div>
            </div>
        </div>

        <div class="col-md-3">

            {% if current_user.vendors or current_user.products %}
            <div class="box box-primary">
                <div class="box-header">
                    <div class="box-title">Subscriptions</div>
                </div>
                <div class="box-body box-subscriptions">
                    {% if current_user.vendors %}
                    <h5><strong>Vendors <span>({{ current_user.vendors|length }})</span></strong></h5>
                    {% for vendor in current_user.vendors %}
                    <a class="label label-primary" href="{{ url_for('main.cves', vendor=vendor.name) }}">{{ vendor.name
                        | humanize }}</a>
                    {% endfor %}

                    {% if current_user.products %}
                    <hr/>
                    {% endif %}
                    {% endif %}
                    {% if current_user.products %}
                    <h5><strong>Products <span>({{ current_user.products|length }})</span></strong></h5>
                    {% for product in current_user.products %}
                    <a class="label label-primary"
                       href="{{ url_for('main.cves', vendor=product.vendor.name, product=product.name) }}">{{
                        product.name | humanize }}</a>
                    {% endfor %}
                    {% endif %}
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</section>

{% endblock %}