Skip to content

Commit

Permalink
Add the status page
Browse files Browse the repository at this point in the history
  • Loading branch information
U039b committed Sep 21, 2024
1 parent 6e631dd commit e186005
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 22 deletions.
4 changes: 4 additions & 0 deletions colander/core/templatetags/colander_tags.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from base64 import urlsafe_b64encode
from datetime import timedelta

from django import template

Expand Down Expand Up @@ -35,6 +36,9 @@ def to_b64(instance):
encoded = instance.encode('utf-8')
return urlsafe_b64encode(encoded).decode().replace('=', '')

@register.filter(name="humanize_duration")
def to_humanized_duration(instance):
return "{:0>8}".format(str(timedelta(seconds=int(instance))))

@register.filter(name="to_cyberchef_input")
def to_cyberchef_input(instance):
Expand Down
16 changes: 16 additions & 0 deletions colander/core/threatr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ def __load_credentials(self):
credentials = credentials.first()
self.api_key = credentials.credentials.get('api_key', '')

def get_status(self):
"""
Get the status of Threatr server.
:return: the status of Threatr
"""
status = {
'configured': True
}
if not self.__correctly_configured:
status['configured'] = False
return status
response = requests.get(f'{self.url}/api/status/', headers=self.__get_headers())
if response.status_code < 300:
status.update(response.json())
return status

def get_types(self):
"""
Get all the types defined in Threatr models.
Expand Down
22 changes: 22 additions & 0 deletions colander/core/views/status_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from django.conf import settings
from django.shortcuts import render

from colander.core.threatr import ThreatrClient


def colander_status_view(request):
client = ThreatrClient()
colander_git_commit_hash = ''
try:
colander_git_commit_hash = settings.GIT_COMMIT_HASH
except: pass
return render(
request,
'pages/status/base.html',
context={
'threatr': client.get_status(),
'colander': {
'git_commit_hash': colander_git_commit_hash
}
}
)
45 changes: 27 additions & 18 deletions colander/static/css/project.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
.text-success-light {
color: #5ace88; }

.text-danger-light {
color: #fd7474; }

.text-dark-light {
color: #696868; }

.bg-secondary-light {
background-color: rgba(169, 145, 212, 0.1) !important; }

Expand Down Expand Up @@ -38,7 +47,7 @@
--bs-gray-400: #cbc8d0;
--bs-gray-500: #adb5bd;
--bs-gray-600: #868e96;
--bs-gray-700: #444;
--bs-gray-700: #696868;
--bs-gray-800: #343a40;
--bs-gray-900: #17141F;
--bs-primary: #7122da;
Expand All @@ -59,7 +68,7 @@
--bs-dark-rgb: 23, 20, 31;
--bs-white-rgb: 255, 255, 255;
--bs-black-rgb: 0, 0, 0;
--bs-body-color-rgb: 68, 68, 68;
--bs-body-color-rgb: 105, 104, 104;
--bs-body-bg-rgb: 255, 255, 255;
--bs-font-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
--bs-font-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
Expand All @@ -68,7 +77,7 @@
--bs-body-font-size: 0.8rem;
--bs-body-font-weight: 400;
--bs-body-line-height: 1.5;
--bs-body-color: #444;
--bs-body-color: #696868;
--bs-body-bg: #fff;
--bs-border-width: 1px;
--bs-border-style: solid;
Expand Down Expand Up @@ -1567,7 +1576,7 @@ progress {
font-size: 0.8rem;
font-weight: 400;
line-height: 1.5;
color: #444;
color: #696868;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #cbc8d0;
Expand All @@ -1582,7 +1591,7 @@ progress {
.form-control[type="file"]:not(:disabled):not([readonly]) {
cursor: pointer; }
.form-control:focus {
color: #444;
color: #696868;
background-color: #fff;
border-color: #b891ed;
outline: 0;
Expand All @@ -1599,7 +1608,7 @@ progress {
padding: 0.375rem 0.75rem;
margin: -0.375rem -0.75rem;
margin-inline-end: 0.75rem;
color: #444;
color: #696868;
background-color: #F9F8FC;
pointer-events: none;
border-color: inherit;
Expand All @@ -1620,7 +1629,7 @@ progress {
padding: 0.375rem 0;
margin-bottom: 0;
line-height: 1.5;
color: #444;
color: #696868;
background-color: transparent;
border: solid transparent;
border-width: 1px 0; }
Expand Down Expand Up @@ -1683,7 +1692,7 @@ textarea.form-control-lg {
font-size: 0.8rem;
font-weight: 400;
line-height: 1.5;
color: #444;
color: #696868;
background-color: #fff;
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
background-repeat: no-repeat;
Expand All @@ -1707,7 +1716,7 @@ textarea.form-control-lg {
background-color: #F9F8FC; }
.form-select:-moz-focusring {
color: transparent;
text-shadow: 0 0 0 #444; }
text-shadow: 0 0 0 #696868; }

.form-select-sm {
padding-top: 0.25rem;
Expand Down Expand Up @@ -1968,7 +1977,7 @@ textarea.form-control-lg {
font-size: 0.8rem;
font-weight: 400;
line-height: 1.5;
color: #444;
color: #696868;
text-align: center;
white-space: nowrap;
background-color: #F9F8FC;
Expand Down Expand Up @@ -2170,7 +2179,7 @@ textarea.form-control-lg {
--bs-btn-font-size: 0.8rem;
--bs-btn-font-weight: 400;
--bs-btn-line-height: 1.5;
--bs-btn-color: #444;
--bs-btn-color: #696868;
--bs-btn-bg: transparent;
--bs-btn-border-width: 1px;
--bs-btn-border-color: transparent;
Expand Down Expand Up @@ -2568,7 +2577,7 @@ textarea.form-control-lg {
--bs-dropdown-padding-y: 0.5rem;
--bs-dropdown-spacer: 0.125rem;
--bs-dropdown-font-size: 0.8rem;
--bs-dropdown-color: #444;
--bs-dropdown-color: #696868;
--bs-dropdown-bg: #fff;
--bs-dropdown-border-color: var(--bs-border-color-translucent);
--bs-dropdown-border-radius: 0.375rem;
Expand All @@ -2577,7 +2586,7 @@ textarea.form-control-lg {
--bs-dropdown-divider-bg: var(--bs-border-color-translucent);
--bs-dropdown-divider-margin-y: 0.6rem;
--bs-dropdown-box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
--bs-dropdown-link-color: #444;
--bs-dropdown-link-color: #696868;
--bs-dropdown-link-hover-color: #fff;
--bs-dropdown-link-hover-bg: #7122da;
--bs-dropdown-link-active-color: #fff;
Expand Down Expand Up @@ -2930,7 +2939,7 @@ textarea.form-control-lg {
--bs-nav-tabs-border-color: #EDEDED;
--bs-nav-tabs-border-radius: 0.375rem;
--bs-nav-tabs-link-hover-border-color: #F9F8FC #F9F8FC #EDEDED;
--bs-nav-tabs-link-active-color: #444;
--bs-nav-tabs-link-active-color: #696868;
--bs-nav-tabs-link-active-bg: #fff;
--bs-nav-tabs-link-active-border-color: #EDEDED #EDEDED #fff;
border-bottom: var(--bs-nav-tabs-border-width) solid var(--bs-nav-tabs-border-color); }
Expand Down Expand Up @@ -3879,10 +3888,10 @@ textarea.form-control-lg {
--bs-list-group-border-radius: 0.375rem;
--bs-list-group-item-padding-x: 1.2rem;
--bs-list-group-item-padding-y: 0.6rem;
--bs-list-group-action-color: #444;
--bs-list-group-action-hover-color: #444;
--bs-list-group-action-color: #696868;
--bs-list-group-action-hover-color: #696868;
--bs-list-group-action-hover-bg: #fafafa;
--bs-list-group-action-active-color: #444;
--bs-list-group-action-active-color: #696868;
--bs-list-group-action-active-bg: #F9F8FC;
--bs-list-group-disabled-color: #868e96;
--bs-list-group-disabled-bg: #fff;
Expand Down Expand Up @@ -4578,7 +4587,7 @@ textarea.form-control-lg {
--bs-popover-header-bg: #e7e5ec;
--bs-popover-body-padding-x: 0.6rem;
--bs-popover-body-padding-y: 0.6rem;
--bs-popover-body-color: #444;
--bs-popover-body-color: #696868;
--bs-popover-arrow-width: 1rem;
--bs-popover-arrow-height: 0.5rem;
--bs-popover-arrow-border: var(--bs-popover-border-color);
Expand Down
14 changes: 13 additions & 1 deletion colander/static/scss/_custom_bootstrap_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $gray-300: #EDEDED;
$gray-400: #cbc8d0;
$gray-500: #adb5bd;
$gray-600: #868e96;
$gray-700: #444;
$gray-700: #696868;
$gray-800: #343a40;
$gray-900: #17141F;
$black: #000;
Expand Down Expand Up @@ -51,6 +51,18 @@ $popover-max-width: 512px;
$popover-body-padding-x: 0.5*$spacer;
$popover-body-padding-y: 0.5*$spacer;

.text-success-light {
color: mix(white, $success, 30%);
}

.text-danger-light {
color: mix(white, $danger, 30%);
}

.text-dark-light {
color: $gray-700;
}

.bg-secondary-light {
background-color: rgba($secondary, 0.1) !important;
}
Expand Down
9 changes: 7 additions & 2 deletions colander/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@

{% block top_bar %}
<header class="navbar navbar-dark sticky-top bg-primary flex-nowrap p-0 shadow">
<div class="navbar-brand col-lg-auto col-md-3">
<a class="me-0 px-3" href="/">
<div class="navbar-brand col-lg-auto col-md-3 d-flex">
<a class="me-0 px-3 flex-grow-1" href="/">
<i class="icon-pts-project" aria-hidden="true"></i>
<span>Colander</span>
</a>
{% if request.user.is_authenticated %}
<a class="text-end text-secondary px-2" title="Status" href="{% url 'colander_status_view' %}">
<i class="nf nf-md-list_status"></i>
</a>
{% endif %}
</div>
<!--
<button class="navbar-toggler position-absolute d-md-none collapsed" type="button" data-bs-toggle="collapse"
Expand Down
1 change: 1 addition & 0 deletions colander/templates/helpers/square_pill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span class="border text-white bg-secondary border-0 rounded-1 px-1"><strong>{{ value }}</strong></span>
105 changes: 105 additions & 0 deletions colander/templates/pages/status/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{% extends "base.html" %}
{% load i18n %}
{% load colander_tags %}
{% load humanize %}
{% block content %}
<div class='row mt-2 p-1'>
<div class='col-12'>
<h3>
<i class="nf nf-fa-circle text-success-light"></i> Colander
<a href="https://pts-project.org/docs/colander/" target="_blank">
<i class="nf nf-cod-book text-secondary"></i>
</a>
<a href="https://github.com/PiRogueToolSuite/colander" target="_blank">
<i class="nf nf-cod-github text-secondary"></i>
</a>
</h3>
<ul class="">
<li>Version:
<a href="https://github.com/PiRogueToolSuite/colander/commit/{{ colander.git_commit_hash }}" target="_blank">
{{ colander.git_commit_hash|truncatechars:7 }}
</a>
</li>
</ul>
</div>
</div>
<div class='row mt-2 p-1'>
<div class='col-12'>
<h3>
<i class="nf nf-fa-circle {% if threatr.configured %}text-success{% else %}text-dark{% endif %}-light"></i>
Threatr
<a href="https://pts-project.org/docs/colander/external-sources/" target="_blank">
<i class="nf nf-cod-book text-secondary"></i>
</a>
<a href="https://github.com/PiRogueToolSuite/threatr" target="_blank">
<i class="nf nf-cod-github text-secondary"></i>
</a>
</h3>
{% if threatr.configured %}
<ul class="">
<li>Version:
<a href="https://github.com/PiRogueToolSuite/threatr/commit/{{ threatr.git_commit_hash }}" target="_blank">
{{ threatr.git_commit_hash|truncatechars:7 }}
</a>
</li>
<li>{% include "helpers/square_pill.html" with value=threatr.cached_entities %} cached entities</li>
<li>{% include "helpers/square_pill.html" with value=threatr.cached_relations %} cached relations</li>
</ul>
{% endif %}
</div>
</div>
{% if threatr.configured %}
<div class='row p-1 g-1'>
<div class='col-12'>
<h5>
<i class="nf nf-fa-plug"></i> Available modules
</h5>
<table class="table table-responsive table-hover table-bordered">
<tbody>
{% for module in threatr.available_modules %}
{% include "pages/status/module_row.html" %}
{% endfor %}
</tbody>
</table>
</div>
</div>
<div class='row justify-content-center p-1 g-1'>
<div class='col'>
<h5>
<i class="nf nf-cod-server_process"></i> Workers
</h5>
<table class="table table-responsive table-hover table-bordered">
<thead>
<tr>
<th>ID</th>
<th>Status</th>
<th class=" text-end">Uptime</th>
<th class=" text-end">Enqueued tasks</th>
<th class=" text-end">Available results</th>
</tr>
</thead>
<tbody>
{% for worker in threatr.workers %}
<tr>
<td class="font-monospace">
{% if worker.status == "Starting" %}
<i class="nf nf-fa-circle text-dark-light"></i>
{% elif worker.status == "Idle" or worker.status == "Working" %}
<i class="nf nf-fa-circle text-success-light"></i>
{% else %}
<i class="nf nf-fa-circle text-danger-light"></i>
{% endif %}
{{ worker.id }}
</td>
<td class="font-monospace">{{ worker.status }}</td>
<td class="text-end">{{ worker.uptime|humanize_duration }}</td>
<td class="text-end">{{ worker.enqueued_tasks }}</td>
<td class="text-end">{{ worker.available_results }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
{% endblock %}
19 changes: 19 additions & 0 deletions colander/templates/pages/status/module_card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="card">
<div class="card-body">
<h5 class="card-title">
{{ module.vendor }}
{% if module.configured > 0 %}
<i class=" nf nf-fa-circle text-success-light"></i>
{% else %}
<i class=" nf nf-fa-circle text-dark-light"></i>
{% endif %}
</h5>
<div class="card-subtitle mb-1">
{% include "helpers/square_pill.html" with value=module.configured %}
<span class=" text-muted">API key{{ module.configured|pluralize }} configured</span>
</div>
<div class="card-text">
<p>{{ module.description }}</p>
</div>
</div>
</div>
Loading

0 comments on commit e186005

Please sign in to comment.