def view_endpoint(request, eid):
    endpoint = get_object_or_404(Endpoint, id=eid)
    host = endpoint.host_no_port
    endpoints = Endpoint.objects.filter(host__regex=(('^' + host) + ':?'), product=endpoint.product).distinct()
    if ((request.user in endpoint.product.authorized_users.all()) or request.user.is_staff):
        pass
    else:
        raise PermissionDenied
    endpoint_cf = endpoint.endpoint_meta
    endpoint_metadata = {}
    for cf in endpoint_cf.all():
        cfv = cf.value
        if len(cfv):
            endpoint_metadata[cf.name] = cfv
    all_findings = Finding.objects.filter(endpoints__in=endpoints).distinct()
    active_findings = Finding.objects.filter(endpoints__in=endpoints, active=True, verified=True).distinct()
    closed_findings = Finding.objects.filter(endpoints__in=endpoints, mitigated__isnull=False).distinct()
    if all_findings:
        start_date = timezone.make_aware(datetime.combine(all_findings.last().date, datetime.min.time()))
    else:
        start_date = timezone.now()
    end_date = timezone.now()
    r = relativedelta(end_date, start_date)
    months_between = ((r.years * 12) + r.months)
    months_between += 1
    monthly_counts = get_period_counts(active_findings, all_findings, closed_findings, None, months_between, start_date, relative_delta='months')
    paged_findings = get_page_items(request, active_findings, 25)
    vulnerable = False
    if (active_findings.count() != 0):
        vulnerable = True
    product_tab = Product_Tab(endpoint.product.id, 'Endpoint', tab='endpoints')
    return render(request, 'dojo/view_endpoint.html', {'endpoint': endpoint, 'product_tab': product_tab, 'endpoints': endpoints, 'findings': paged_findings, 'all_findings': all_findings, 'opened_per_month': monthly_counts['opened_per_period'], 'endpoint_metadata': endpoint_metadata, 'vulnerable': vulnerable})
def view_endpoint(request, eid):
    endpoint = get_object_or_404(Endpoint, id=eid)
    host = endpoint.host_no_port
    endpoints = Endpoint.objects.filter(host__regex=(('^' + host) + ':?'), product=endpoint.product).distinct()
    if ((request.user in endpoint.product.authorized_users.all()) or request.user.is_staff):
        pass
    else:
        raise PermissionDenied
    endpoint_cf = endpoint.endpoint_meta
    endpoint_metadata = {}
    for cf in endpoint_cf.all():
        cfv = cf.value
        if len(cfv):
            endpoint_metadata[cf.name] = cfv
    all_findings = Finding.objects.filter(endpoints__in=endpoints).distinct()
    active_findings = Finding.objects.filter(endpoints__in=endpoints, active=True, verified=True).distinct()
    closed_findings = Finding.objects.filter(endpoints__in=endpoints, mitigated__isnull=False).distinct()
    if all_findings:
        start_date = timezone.make_aware(datetime.combine(all_findings.last().date, datetime.min.time()))
    else:
        start_date = timezone.now()
    end_date = timezone.now()
    r = relativedelta(end_date, start_date)
    months_between = ((r.years * 12) + r.months)
    months_between += 1
    monthly_counts = get_period_counts(active_findings, all_findings, closed_findings, None, months_between, start_date, relative_delta='months')
    paged_findings = get_page_items(request, active_findings, 25)
    vulnerable = False
    if (active_findings.count() != 0):
        vulnerable = True
    product_tab = Product_Tab(endpoint.product.id, 'Endpoint', tab='endpoints')
    return render(request, 'dojo/view_endpoint.html', {'endpoint': endpoint, 'product_tab': product_tab, 'endpoints': endpoints, 'findings': paged_findings, 'all_findings': all_findings, 'opened_per_month': monthly_counts['opened_per_period'], 'endpoint_metadata': endpoint_metadata, 'vulnerable': vulnerable})