Skip to content

Commit

Permalink
Changes to the WebGUI: changes to jinja2 templates, uses FastAPI serv…
Browse files Browse the repository at this point in the history
…er, hides login button when session_store is null, fixes double slash issue.
  • Loading branch information
gethvi committed Dec 21, 2023
1 parent 4ea2879 commit b78d9e5
Show file tree
Hide file tree
Showing 20 changed files with 359 additions and 334 deletions.
8 changes: 8 additions & 0 deletions intelmq/app/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
"""

import os
import pathlib

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.middleware.cors import CORSMiddleware

from intelmq.version import __version__
Expand All @@ -15,6 +17,7 @@

from intelmq.app.config import config
from intelmq.app.api.router import router as api_router
from intelmq.app.webgui.router import router as web_router

app = FastAPI(
title="IntelMQ",
Expand All @@ -32,4 +35,9 @@ def init_app():

app.include_router(api_router, prefix="/api/v1")

if config.enable_webgui:
static_files = pathlib.Path(__file__).parent / "webgui" / "static"
app.mount("/static", StaticFiles(directory=static_files), name="static")
app.include_router(web_router)

intelmq.app.api.exceptions.register(app)
10 changes: 0 additions & 10 deletions intelmq/app/webgui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +0,0 @@
"""Python __init__ file that provides the path to the module
SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>
SPDX-License-Identifier: AGPL-3.0-or-later
"""
import pathlib
from .version import __version__, __version_info__ # noqa

path = pathlib.Path(__file__).parent
60 changes: 0 additions & 60 deletions intelmq/app/webgui/build.py

This file was deleted.

101 changes: 101 additions & 0 deletions intelmq/app/webgui/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# SPDX-FileCopyrightText: 2023 IntelMQ Team
# SPDX-License-Identifier: AGPL-3.0-or-later

import collections
import pathlib

from fastapi import APIRouter, Request
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates

from intelmq.app.config import config

SHOW_LOGIN = True if config.session_store else False

router = APIRouter(default_response_class=HTMLResponse)
templates_dir = pathlib.Path(__file__).parent / "templates"
templates = Jinja2Templates(directory=templates_dir)
Page = collections.namedtuple("Page", ["name", "title", "url", "icon_url"])


def get_pages(request: Request):
return [
Page(
name="configs",
title="Configuration",
url=request.url_for('get_configuration'),
icon_url=request.url_for('static', path='images/configuration.png'),
),
Page(
name="management",
title="Management",
url=request.url_for('get_management'),
icon_url=request.url_for('static', path='images/management.png'),
),
Page(
name="monitor",
title="Monitor",
url=request.url_for('get_monitor'),
icon_url=request.url_for('static', path='images/monitor.png'),
),
Page(
name="check",
title="Check",
url=request.url_for('get_check'),
icon_url=request.url_for('static', path='images/check.png'),
),
Page(
name="about",
title="About",
url=request.url_for('get_about'),
icon_url=request.url_for('static', path='images/about.png'),
)
]


@router.get("/", include_in_schema=False)
async def get_index(request: Request):
return templates.TemplateResponse("index.html", {
"request": request,
"pages": get_pages(request)
})


@router.get("/configuration", include_in_schema=False)
async def get_configuration(request: Request):
return templates.TemplateResponse("configuration.html", {
"request": request,
"pages": get_pages(request)
})


@router.get("/management", include_in_schema=False)
def get_management(request: Request):
return templates.TemplateResponse("management.html", {
"request": request,
"pages": get_pages(request)
})


@router.get("/monitor", include_in_schema=False)
def get_monitor(request: Request):
return templates.TemplateResponse("monitor.html", {
"request": request,
"pages": get_pages(request)
})


@router.get("/check", include_in_schema=False)
def get_check(request: Request):
return templates.TemplateResponse("check.html", {
"request": request,
"pages": get_pages(request)
})


@router.get("/about", include_in_schema=False)
def get_about(request: Request):
return templates.TemplateResponse("about.html", {
"request": request,
"pages": get_pages(request)
})
4 changes: 0 additions & 4 deletions intelmq/app/webgui/static/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

function get_versions() {
let intelmq_version_element = document.getElementById('intelmq-version');
let intelmq_api_version_element = document.getElementById('intelmq-api-version');
let intelmq_manager_version_element = document.getElementById('intelmq-manager-version');

authenticatedGetJson(managementUrl('version'))
.done(function (data) {
intelmq_version_element.innerHTML = data.intelmq;
intelmq_api_version_element.innerHTML = data['intelmq-api'];
intelmq_manager_version_element.innerHTML = '3.2.0';
})
.fail(function (jqxhr, textStatus, error) {
let err = `${textStatus}, ${error}`;
Expand Down
6 changes: 3 additions & 3 deletions intelmq/app/webgui/static/js/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var documentation = null;
var span = null;
var table = null;
var disabledKeys = ['group', 'name', 'module'];
var $manipulation, $saveButton; // jQuery of Vis control panel; elements reseted with network
var $manipulation, $saveButton; // jQuery of Vis control panel; elements reset with network
var node = null;

var $EDIT_DEFAULT_BUTTON = $("#editDefaults");
Expand Down Expand Up @@ -544,7 +544,7 @@ function saveData(data, callback) {

saveFormData();

// check inputs beeing valid
// check inputs being valid
if (node.bot_id === '' && node.group === '') {
show_error('fields id and group must not be empty!');
return;
Expand Down Expand Up @@ -740,7 +740,7 @@ function draw() {
initNetwork();
if (window.location.hash) {
let node = window.location.hash.substr(1);
setTimeout(() => { // doesnt work immediately, I don't know why. Maybe a js guru would bind to visjs onready if that exists or sth.
setTimeout(() => { // doesn't work immediately, I don't know why. Maybe a js guru would bind to visjs onready if that exists or sth.
try {
fitNode(node);
} catch (e) {
Expand Down
29 changes: 0 additions & 29 deletions intelmq/app/webgui/static/js/intelmq-manager.js

This file was deleted.

2 changes: 1 addition & 1 deletion intelmq/app/webgui/static/js/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var LOAD_X_LOG_LINES = 30;

var MESSAGE_LENGTH = 200;

var MONITOR_BOT_URL = "monitor.html?bot_id={0}";
var MONITOR_BOT_URL = "monitor?bot_id={0}";

var page_is_exiting = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## SPDX-FileCopyrightText: 2020 IntelMQ Team <[email protected]>
## SPDX-License-Identifier: AGPL-3.0-or-later
{#SPDX-FileCopyrightText: 2020 IntelMQ Team <intelmq-team@cert.at>#}
{#SPDX-License-Identifier: AGPL-3.0-or-later#}

<%inherit file="base.mako" />
{% extends "base.html" %}

{% block title %}About{% endblock %}

{% block content %}
<!-- Page Content -->
<div id="page-wrapper">
<div class="row" style="padding: 20px">
Expand Down Expand Up @@ -51,8 +54,6 @@
<h2>Version</h2>
<table class="table">
<tr><td>IntelMQ<td><td id="intelmq-version"></td></tr>
<tr><td>IntelMQ API<td><td id="intelmq-api-version"></td></tr>
<tr><td>IntelMQ Manager<td><td id="intelmq-manager-version"></td></tr>
</table>
</div>
</div>
Expand All @@ -63,3 +64,8 @@ <h2 id="debugging-heading" class="waiting">Debugging</h2>
</div>
</div>
</div>
{% endblock %}

{% block javascript %}
<script src="{{ url_for('static', path='js/about.js') }}"></script>
{% endblock %}
Loading

0 comments on commit b78d9e5

Please sign in to comment.