Compare commits
29 Commits
ee73373111
...
refactorin
| Author | SHA1 | Date | |
|---|---|---|---|
| a92a8220c2 | |||
| 9c5b7ba091 | |||
| 20dd890746 | |||
| 7306b98a54 | |||
| e0c21dcc10 | |||
| e2876fc35c | |||
| 96370ee6aa | |||
| 2022bcde99 | |||
| 1f4ee360f6 | |||
| 9646b1c119 | |||
| 2e3ac5f005 | |||
| 90e42e96b4 | |||
| aff67b3a78 | |||
| ffaa5c3adb | |||
| 5a49106f4d | |||
| 452901913f | |||
| 25b4ebbd96 | |||
| 7627ae7edb | |||
| 377cc7ac88 | |||
| 77711e202d | |||
| 3568e9caf3 | |||
| 250bb1a2e5 | |||
| 6515164d53 | |||
| 25d43ffb96 | |||
| 29762664d7 | |||
| a2b8e14cbc | |||
| 68114924bb | |||
| 7866f9cbb2 | |||
| dcd8059b27 |
@@ -1 +1 @@
|
|||||||
v0.9.10
|
v0.9.4
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ logpath = /dev/null
|
|||||||
backend = auto
|
backend = auto
|
||||||
maxretry = 1
|
maxretry = 1
|
||||||
findtime = 1d
|
findtime = 1d
|
||||||
# Block imported IPs for 24 hours.
|
# Block imported IPs for one week.
|
||||||
bantime = 86400
|
bantime = 1w
|
||||||
|
|
||||||
# Never ban the Docker bridge network or localhost.
|
# Never ban the Docker bridge network or localhost.
|
||||||
ignoreip = 127.0.0.0/8 ::1 172.16.0.0/12
|
ignoreip = 127.0.0.0/8 ::1 172.16.0.0/12
|
||||||
|
|||||||
@@ -56,8 +56,11 @@ echo " Registry : ${REGISTRY}"
|
|||||||
echo " Tag : ${TAG}"
|
echo " Tag : ${TAG}"
|
||||||
echo "============================================"
|
echo "============================================"
|
||||||
|
|
||||||
log "Logging in to ${REGISTRY}"
|
if [[ "${ENGINE}" == "podman" ]]; then
|
||||||
"${ENGINE}" login "${REGISTRY}"
|
if ! podman login --get-login "${REGISTRY}" &>/dev/null; then
|
||||||
|
err "Not logged in. Run:\n podman login ${REGISTRY}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Build
|
# Build
|
||||||
|
|||||||
@@ -69,23 +69,18 @@ sed -i "s/\"version\": \"[^\"]*\"/\"version\": \"${FRONT_VERSION}\"/" "${FRONT_P
|
|||||||
echo "frontend/package.json version updated → ${FRONT_VERSION}"
|
echo "frontend/package.json version updated → ${FRONT_VERSION}"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Git tag (local only; push after container build)
|
# Git tag
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
cd "${SCRIPT_DIR}/.."
|
cd "${SCRIPT_DIR}/.."
|
||||||
git add Docker/VERSION frontend/package.json
|
git add Docker/VERSION frontend/package.json
|
||||||
git commit -m "chore: release ${NEW_TAG}"
|
git commit -m "chore: release ${NEW_TAG}"
|
||||||
git tag -a "${NEW_TAG}" -m "Release ${NEW_TAG}"
|
git tag -a "${NEW_TAG}" -m "Release ${NEW_TAG}"
|
||||||
echo "Local git commit + tag ${NEW_TAG} created."
|
git push origin HEAD
|
||||||
|
git push origin "${NEW_TAG}"
|
||||||
|
echo "Git tag ${NEW_TAG} created and pushed."
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Push containers
|
# Push
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
bash "${SCRIPT_DIR}/push.sh" "${NEW_TAG}"
|
bash "${SCRIPT_DIR}/push.sh" "${NEW_TAG}"
|
||||||
bash "${SCRIPT_DIR}/push.sh"
|
bash "${SCRIPT_DIR}/push.sh"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# Push git commits & tag
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
git push origin HEAD
|
|
||||||
git push origin "${NEW_TAG}"
|
|
||||||
echo "Git commit and tag ${NEW_TAG} pushed."
|
|
||||||
|
|||||||
@@ -1,68 +1 @@
|
|||||||
"""BanGUI backend application package.
|
"""BanGUI backend application package."""
|
||||||
|
|
||||||
This package exposes the application version based on the project metadata.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
from typing import Final
|
|
||||||
|
|
||||||
import importlib.metadata
|
|
||||||
import tomllib
|
|
||||||
|
|
||||||
PACKAGE_NAME: Final[str] = "bangui-backend"
|
|
||||||
|
|
||||||
|
|
||||||
def _read_pyproject_version() -> str:
|
|
||||||
"""Read the project version from ``pyproject.toml``.
|
|
||||||
|
|
||||||
This is used as a fallback when the package metadata is not available (e.g.
|
|
||||||
when running directly from a source checkout without installing the package).
|
|
||||||
"""
|
|
||||||
|
|
||||||
project_root = Path(__file__).resolve().parents[1]
|
|
||||||
pyproject_path = project_root / "pyproject.toml"
|
|
||||||
if not pyproject_path.exists():
|
|
||||||
raise FileNotFoundError(f"pyproject.toml not found at {pyproject_path}")
|
|
||||||
|
|
||||||
data = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
|
|
||||||
return str(data["project"]["version"])
|
|
||||||
|
|
||||||
|
|
||||||
def _read_docker_version() -> str:
|
|
||||||
"""Read the project version from ``Docker/VERSION``.
|
|
||||||
|
|
||||||
This file is the single source of truth for release scripts and must not be
|
|
||||||
out of sync with the frontend and backend versions.
|
|
||||||
"""
|
|
||||||
|
|
||||||
repo_root = Path(__file__).resolve().parents[2]
|
|
||||||
version_path = repo_root / "Docker" / "VERSION"
|
|
||||||
if not version_path.exists():
|
|
||||||
raise FileNotFoundError(f"Docker/VERSION not found at {version_path}")
|
|
||||||
|
|
||||||
version = version_path.read_text(encoding="utf-8").strip()
|
|
||||||
return version.lstrip("v")
|
|
||||||
|
|
||||||
|
|
||||||
def _read_version() -> str:
|
|
||||||
"""Return the current package version.
|
|
||||||
|
|
||||||
Prefer the release artifact in ``Docker/VERSION`` when available so the
|
|
||||||
backend version always matches what the release tooling publishes.
|
|
||||||
|
|
||||||
If that file is missing (e.g. in a production wheel or a local checkout),
|
|
||||||
fall back to ``pyproject.toml`` and finally installed package metadata.
|
|
||||||
"""
|
|
||||||
|
|
||||||
try:
|
|
||||||
return _read_docker_version()
|
|
||||||
except FileNotFoundError:
|
|
||||||
try:
|
|
||||||
return _read_pyproject_version()
|
|
||||||
except FileNotFoundError:
|
|
||||||
return importlib.metadata.version(PACKAGE_NAME)
|
|
||||||
|
|
||||||
|
|
||||||
__version__ = _read_version()
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
|||||||
from fastapi.responses import JSONResponse, RedirectResponse
|
from fastapi.responses import JSONResponse, RedirectResponse
|
||||||
from starlette.middleware.base import BaseHTTPMiddleware
|
from starlette.middleware.base import BaseHTTPMiddleware
|
||||||
|
|
||||||
from app import __version__
|
|
||||||
from app.config import Settings, get_settings
|
from app.config import Settings, get_settings
|
||||||
from app.db import init_db
|
from app.db import init_db
|
||||||
from app.routers import (
|
from app.routers import (
|
||||||
@@ -362,7 +361,7 @@ def create_app(settings: Settings | None = None) -> FastAPI:
|
|||||||
app: FastAPI = FastAPI(
|
app: FastAPI = FastAPI(
|
||||||
title="BanGUI",
|
title="BanGUI",
|
||||||
description="Web interface for monitoring, managing, and configuring fail2ban.",
|
description="Web interface for monitoring, managing, and configuring fail2ban.",
|
||||||
version=__version__,
|
version="0.1.0",
|
||||||
lifespan=_lifespan,
|
lifespan=_lifespan,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1002,7 +1002,6 @@ class ServiceStatusResponse(BaseModel):
|
|||||||
|
|
||||||
online: bool = Field(..., description="Whether fail2ban is reachable via its socket.")
|
online: bool = Field(..., description="Whether fail2ban is reachable via its socket.")
|
||||||
version: str | None = Field(default=None, description="fail2ban version string, or None when offline.")
|
version: str | None = Field(default=None, description="fail2ban version string, or None when offline.")
|
||||||
bangui_version: str = Field(..., description="BanGUI application version.")
|
|
||||||
jail_count: int = Field(default=0, ge=0, description="Number of currently active jails.")
|
jail_count: int = Field(default=0, ge=0, description="Number of currently active jails.")
|
||||||
total_bans: int = Field(default=0, ge=0, description="Aggregated current ban count across all jails.")
|
total_bans: int = Field(default=0, ge=0, description="Aggregated current ban count across all jails.")
|
||||||
total_failures: int = Field(default=0, ge=0, description="Aggregated current failure count across all jails.")
|
total_failures: int = Field(default=0, ge=0, description="Aggregated current failure count across all jails.")
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ class ServerStatusResponse(BaseModel):
|
|||||||
model_config = ConfigDict(strict=True)
|
model_config = ConfigDict(strict=True)
|
||||||
|
|
||||||
status: ServerStatus
|
status: ServerStatus
|
||||||
bangui_version: str = Field(..., description="BanGUI application version.")
|
|
||||||
|
|
||||||
|
|
||||||
class ServerSettings(BaseModel):
|
class ServerSettings(BaseModel):
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
from fastapi import APIRouter, Query, Request
|
from fastapi import APIRouter, Query, Request
|
||||||
|
|
||||||
from app import __version__
|
|
||||||
from app.dependencies import AuthDep
|
from app.dependencies import AuthDep
|
||||||
from app.models.ban import (
|
from app.models.ban import (
|
||||||
BanOrigin,
|
BanOrigin,
|
||||||
@@ -70,7 +69,7 @@ async def get_server_status(
|
|||||||
"server_status",
|
"server_status",
|
||||||
ServerStatus(online=False),
|
ServerStatus(online=False),
|
||||||
)
|
)
|
||||||
return ServerStatusResponse(status=cached, bangui_version=__version__)
|
return ServerStatusResponse(status=cached)
|
||||||
|
|
||||||
|
|
||||||
@router.get(
|
@router.get(
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ if TYPE_CHECKING:
|
|||||||
from fastapi import APIRouter, HTTPException, Query, Request
|
from fastapi import APIRouter, HTTPException, Query, Request
|
||||||
|
|
||||||
from app.dependencies import AuthDep
|
from app.dependencies import AuthDep
|
||||||
from app.models.ban import BanOrigin, TimeRange
|
from app.models.ban import TimeRange
|
||||||
from app.models.history import HistoryListResponse, IpDetailResponse
|
from app.models.history import HistoryListResponse, IpDetailResponse
|
||||||
from app.services import geo_service, history_service
|
from app.services import geo_service, history_service
|
||||||
|
|
||||||
@@ -52,10 +52,6 @@ async def get_history(
|
|||||||
default=None,
|
default=None,
|
||||||
description="Restrict results to IPs matching this prefix.",
|
description="Restrict results to IPs matching this prefix.",
|
||||||
),
|
),
|
||||||
origin: BanOrigin | None = Query(
|
|
||||||
default=None,
|
|
||||||
description="Filter by ban origin: 'blocklist' or 'selfblock'. Omit for all.",
|
|
||||||
),
|
|
||||||
page: int = Query(default=1, ge=1, description="1-based page number."),
|
page: int = Query(default=1, ge=1, description="1-based page number."),
|
||||||
page_size: int = Query(
|
page_size: int = Query(
|
||||||
default=_DEFAULT_PAGE_SIZE,
|
default=_DEFAULT_PAGE_SIZE,
|
||||||
@@ -93,7 +89,6 @@ async def get_history(
|
|||||||
range_=range,
|
range_=range,
|
||||||
jail=jail,
|
jail=jail,
|
||||||
ip_filter=ip,
|
ip_filter=ip,
|
||||||
origin=origin,
|
|
||||||
page=page,
|
page=page,
|
||||||
page_size=page_size,
|
page_size=page_size,
|
||||||
geo_enricher=_enricher,
|
geo_enricher=_enricher,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ logpath = /dev/null
|
|||||||
backend = auto
|
backend = auto
|
||||||
maxretry = 1
|
maxretry = 1
|
||||||
findtime = 1d
|
findtime = 1d
|
||||||
bantime = 86400
|
bantime = 1w
|
||||||
ignoreip = 127.0.0.0/8 ::1 172.16.0.0/12
|
ignoreip = 127.0.0.0/8 ::1 172.16.0.0/12
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "bangui-backend"
|
name = "bangui-backend"
|
||||||
version = "0.9.8"
|
version = "0.9.0"
|
||||||
description = "BanGUI backend — fail2ban web management interface"
|
description = "BanGUI backend — fail2ban web management interface"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import aiosqlite
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
import app
|
|
||||||
|
|
||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
from app.db import init_db
|
from app.db import init_db
|
||||||
from app.main import create_app
|
from app.main import create_app
|
||||||
@@ -2002,7 +2000,6 @@ class TestGetServiceStatus:
|
|||||||
return ServiceStatusResponse(
|
return ServiceStatusResponse(
|
||||||
online=online,
|
online=online,
|
||||||
version="1.0.0" if online else None,
|
version="1.0.0" if online else None,
|
||||||
bangui_version=app.__version__,
|
|
||||||
jail_count=2 if online else 0,
|
jail_count=2 if online else 0,
|
||||||
total_bans=10 if online else 0,
|
total_bans=10 if online else 0,
|
||||||
total_failures=3 if online else 0,
|
total_failures=3 if online else 0,
|
||||||
@@ -2021,7 +2018,6 @@ class TestGetServiceStatus:
|
|||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert data["online"] is True
|
assert data["online"] is True
|
||||||
assert data["bangui_version"] == app.__version__
|
|
||||||
assert data["jail_count"] == 2
|
assert data["jail_count"] == 2
|
||||||
assert data["log_level"] == "INFO"
|
assert data["log_level"] == "INFO"
|
||||||
|
|
||||||
@@ -2035,7 +2031,6 @@ class TestGetServiceStatus:
|
|||||||
|
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
data = resp.json()
|
data = resp.json()
|
||||||
assert data["bangui_version"] == app.__version__
|
|
||||||
assert data["online"] is False
|
assert data["online"] is False
|
||||||
assert data["log_level"] == "UNKNOWN"
|
assert data["log_level"] == "UNKNOWN"
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ import aiosqlite
|
|||||||
import pytest
|
import pytest
|
||||||
from httpx import ASGITransport, AsyncClient
|
from httpx import ASGITransport, AsyncClient
|
||||||
|
|
||||||
import app
|
|
||||||
|
|
||||||
from app.config import Settings
|
from app.config import Settings
|
||||||
from app.db import init_db
|
from app.db import init_db
|
||||||
from app.main import create_app
|
from app.main import create_app
|
||||||
@@ -153,9 +151,6 @@ class TestDashboardStatus:
|
|||||||
body = response.json()
|
body = response.json()
|
||||||
|
|
||||||
assert "status" in body
|
assert "status" in body
|
||||||
assert "bangui_version" in body
|
|
||||||
assert body["bangui_version"] == app.__version__
|
|
||||||
|
|
||||||
status = body["status"]
|
status = body["status"]
|
||||||
assert "online" in status
|
assert "online" in status
|
||||||
assert "version" in status
|
assert "version" in status
|
||||||
@@ -168,10 +163,8 @@ class TestDashboardStatus:
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Endpoint returns the exact values from ``app.state.server_status``."""
|
"""Endpoint returns the exact values from ``app.state.server_status``."""
|
||||||
response = await dashboard_client.get("/api/dashboard/status")
|
response = await dashboard_client.get("/api/dashboard/status")
|
||||||
body = response.json()
|
status = response.json()["status"]
|
||||||
status = body["status"]
|
|
||||||
|
|
||||||
assert body["bangui_version"] == app.__version__
|
|
||||||
assert status["online"] is True
|
assert status["online"] is True
|
||||||
assert status["version"] == "1.0.2"
|
assert status["version"] == "1.0.2"
|
||||||
assert status["active_jails"] == 2
|
assert status["active_jails"] == 2
|
||||||
@@ -184,10 +177,8 @@ class TestDashboardStatus:
|
|||||||
"""Endpoint returns online=False when the cache holds an offline snapshot."""
|
"""Endpoint returns online=False when the cache holds an offline snapshot."""
|
||||||
response = await offline_dashboard_client.get("/api/dashboard/status")
|
response = await offline_dashboard_client.get("/api/dashboard/status")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
body = response.json()
|
status = response.json()["status"]
|
||||||
status = body["status"]
|
|
||||||
|
|
||||||
assert body["bangui_version"] == app.__version__
|
|
||||||
assert status["online"] is False
|
assert status["online"] is False
|
||||||
assert status["version"] is None
|
assert status["version"] is None
|
||||||
assert status["active_jails"] == 0
|
assert status["active_jails"] == 0
|
||||||
|
|||||||
@@ -213,18 +213,6 @@ class TestHistoryList:
|
|||||||
_args, kwargs = mock_fn.call_args
|
_args, kwargs = mock_fn.call_args
|
||||||
assert kwargs.get("range_") == "7d"
|
assert kwargs.get("range_") == "7d"
|
||||||
|
|
||||||
async def test_forwards_origin_filter(self, history_client: AsyncClient) -> None:
|
|
||||||
"""The ``origin`` query parameter is forwarded to the service."""
|
|
||||||
mock_fn = AsyncMock(return_value=_make_history_list(n=0))
|
|
||||||
with patch(
|
|
||||||
"app.routers.history.history_service.list_history",
|
|
||||||
new=mock_fn,
|
|
||||||
):
|
|
||||||
await history_client.get("/api/history?origin=blocklist")
|
|
||||||
|
|
||||||
_args, kwargs = mock_fn.call_args
|
|
||||||
assert kwargs.get("origin") == "blocklist"
|
|
||||||
|
|
||||||
async def test_empty_result(self, history_client: AsyncClient) -> None:
|
async def test_empty_result(self, history_client: AsyncClient) -> None:
|
||||||
"""An empty history returns items=[] and total=0."""
|
"""An empty history returns items=[] and total=0."""
|
||||||
with patch(
|
with patch(
|
||||||
|
|||||||
@@ -256,27 +256,6 @@ class TestUpdateJailConfig:
|
|||||||
assert "bantime" in keys
|
assert "bantime" in keys
|
||||||
assert "maxretry" in keys
|
assert "maxretry" in keys
|
||||||
|
|
||||||
async def test_ignores_backend_field(self) -> None:
|
|
||||||
"""update_jail_config does not send a set command for backend."""
|
|
||||||
sent_commands: list[list[Any]] = []
|
|
||||||
|
|
||||||
async def _send(command: list[Any]) -> Any:
|
|
||||||
sent_commands.append(command)
|
|
||||||
return (0, "OK")
|
|
||||||
|
|
||||||
class _FakeClient:
|
|
||||||
def __init__(self, **_kw: Any) -> None:
|
|
||||||
self.send = AsyncMock(side_effect=_send)
|
|
||||||
|
|
||||||
from app.models.config import JailConfigUpdate
|
|
||||||
|
|
||||||
update = JailConfigUpdate(backend="polling")
|
|
||||||
with patch("app.services.config_service.Fail2BanClient", _FakeClient):
|
|
||||||
await config_service.update_jail_config(_SOCKET, "sshd", update)
|
|
||||||
|
|
||||||
keys = [cmd[2] for cmd in sent_commands if len(cmd) >= 3 and cmd[0] == "set"]
|
|
||||||
assert "backend" not in keys
|
|
||||||
|
|
||||||
async def test_raises_validation_error_on_bad_regex(self) -> None:
|
async def test_raises_validation_error_on_bad_regex(self) -> None:
|
||||||
"""update_jail_config raises ConfigValidationError for invalid regex."""
|
"""update_jail_config raises ConfigValidationError for invalid regex."""
|
||||||
from app.models.config import JailConfigUpdate
|
from app.models.config import JailConfigUpdate
|
||||||
|
|||||||
@@ -65,10 +65,6 @@ class TestEnsureJailConfigs:
|
|||||||
content = _read(jail_d, conf_file)
|
content = _read(jail_d, conf_file)
|
||||||
assert "enabled = false" in content
|
assert "enabled = false" in content
|
||||||
|
|
||||||
# Blocklist-import jail must have a 24-hour ban time
|
|
||||||
blocklist_conf = _read(jail_d, _BLOCKLIST_CONF)
|
|
||||||
assert "bantime = 86400" in blocklist_conf
|
|
||||||
|
|
||||||
# .local files must set enabled = true and nothing else
|
# .local files must set enabled = true and nothing else
|
||||||
for local_file in (_MANUAL_LOCAL, _BLOCKLIST_LOCAL):
|
for local_file in (_MANUAL_LOCAL, _BLOCKLIST_LOCAL):
|
||||||
content = _read(jail_d, local_file)
|
content = _read(jail_d, local_file)
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import app
|
|
||||||
|
|
||||||
|
|
||||||
def test_app_version_matches_docker_version() -> None:
|
|
||||||
"""The backend version should match the signed off Docker release version."""
|
|
||||||
|
|
||||||
repo_root = Path(__file__).resolve().parents[2]
|
|
||||||
version_file = repo_root / "Docker" / "VERSION"
|
|
||||||
expected = version_file.read_text(encoding="utf-8").strip().lstrip("v")
|
|
||||||
|
|
||||||
assert app.__version__ == expected
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "bangui-frontend",
|
"name": "bangui-frontend",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.9.10",
|
"version": "0.9.4",
|
||||||
"description": "BanGUI frontend — fail2ban web management interface",
|
"description": "BanGUI frontend — fail2ban web management interface",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ export async function fetchHistory(
|
|||||||
): Promise<HistoryListResponse> {
|
): Promise<HistoryListResponse> {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
if (query.range) params.set("range", query.range);
|
if (query.range) params.set("range", query.range);
|
||||||
if (query.origin) params.set("origin", query.origin);
|
|
||||||
if (query.jail) params.set("jail", query.jail);
|
if (query.jail) params.set("jail", query.jail);
|
||||||
if (query.ip) params.set("ip", query.ip);
|
if (query.ip) params.set("ip", query.ip);
|
||||||
if (query.page !== undefined) params.set("page", String(query.page));
|
if (query.page !== undefined) params.set("page", String(query.page));
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ const useStyles = makeStyles({
|
|||||||
*/
|
*/
|
||||||
export function ServerStatusBar(): React.JSX.Element {
|
export function ServerStatusBar(): React.JSX.Element {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const { status, banguiVersion, loading, error, refresh } = useServerStatus();
|
const { status, loading, error, refresh } = useServerStatus();
|
||||||
|
|
||||||
const cardStyles = useCardStyles();
|
const cardStyles = useCardStyles();
|
||||||
|
|
||||||
@@ -105,14 +105,6 @@ export function ServerStatusBar(): React.JSX.Element {
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{banguiVersion != null && (
|
|
||||||
<Tooltip content="BanGUI version" relationship="description">
|
|
||||||
<Badge appearance="filled" size="small">
|
|
||||||
BanGUI v{banguiVersion}
|
|
||||||
</Badge>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* ---------------------------------------------------------------- */}
|
{/* ---------------------------------------------------------------- */}
|
||||||
{/* Stats (only when online) */}
|
{/* Stats (only when online) */}
|
||||||
{/* ---------------------------------------------------------------- */}
|
{/* ---------------------------------------------------------------- */}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
* country filters the companion table.
|
* country filters the companion table.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createPortal } from "react-dom";
|
|
||||||
import { useCallback, useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { ComposableMap, ZoomableGroup, Geography, useGeographies } from "react-simple-maps";
|
import { ComposableMap, ZoomableGroup, Geography, useGeographies } from "react-simple-maps";
|
||||||
import { Button, makeStyles, tokens } from "@fluentui/react-components";
|
import { Button, makeStyles, tokens } from "@fluentui/react-components";
|
||||||
@@ -49,28 +48,6 @@ const useStyles = makeStyles({
|
|||||||
gap: tokens.spacingVerticalXS,
|
gap: tokens.spacingVerticalXS,
|
||||||
zIndex: 10,
|
zIndex: 10,
|
||||||
},
|
},
|
||||||
tooltip: {
|
|
||||||
position: "fixed",
|
|
||||||
zIndex: 9999,
|
|
||||||
pointerEvents: "none",
|
|
||||||
backgroundColor: tokens.colorNeutralBackground1,
|
|
||||||
border: `1px solid ${tokens.colorNeutralStroke2}`,
|
|
||||||
borderRadius: tokens.borderRadiusSmall,
|
|
||||||
padding: `${tokens.spacingVerticalXS} ${tokens.spacingHorizontalS}`,
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
gap: tokens.spacingVerticalXXS,
|
|
||||||
boxShadow: tokens.shadow4,
|
|
||||||
},
|
|
||||||
tooltipCountry: {
|
|
||||||
fontSize: tokens.fontSizeBase200,
|
|
||||||
fontWeight: tokens.fontWeightSemibold,
|
|
||||||
color: tokens.colorNeutralForeground1,
|
|
||||||
},
|
|
||||||
tooltipCount: {
|
|
||||||
fontSize: tokens.fontSizeBase200,
|
|
||||||
color: tokens.colorNeutralForeground2,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -79,7 +56,6 @@ const useStyles = makeStyles({
|
|||||||
|
|
||||||
interface GeoLayerProps {
|
interface GeoLayerProps {
|
||||||
countries: Record<string, number>;
|
countries: Record<string, number>;
|
||||||
countryNames?: Record<string, string>;
|
|
||||||
selectedCountry: string | null;
|
selectedCountry: string | null;
|
||||||
onSelectCountry: (cc: string | null) => void;
|
onSelectCountry: (cc: string | null) => void;
|
||||||
thresholdLow: number;
|
thresholdLow: number;
|
||||||
@@ -89,7 +65,6 @@ interface GeoLayerProps {
|
|||||||
|
|
||||||
function GeoLayer({
|
function GeoLayer({
|
||||||
countries,
|
countries,
|
||||||
countryNames,
|
|
||||||
selectedCountry,
|
selectedCountry,
|
||||||
onSelectCountry,
|
onSelectCountry,
|
||||||
thresholdLow,
|
thresholdLow,
|
||||||
@@ -99,17 +74,6 @@ function GeoLayer({
|
|||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const { geographies, path } = useGeographies({ geography: GEO_URL });
|
const { geographies, path } = useGeographies({ geography: GEO_URL });
|
||||||
|
|
||||||
const [tooltip, setTooltip] = useState<
|
|
||||||
| {
|
|
||||||
cc: string;
|
|
||||||
count: number;
|
|
||||||
name: string;
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
}
|
|
||||||
| null
|
|
||||||
>(null);
|
|
||||||
|
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(cc: string | null): void => {
|
(cc: string | null): void => {
|
||||||
onSelectCountry(selectedCountry === cc ? null : cc);
|
onSelectCountry(selectedCountry === cc ? null : cc);
|
||||||
@@ -170,30 +134,6 @@ function GeoLayer({
|
|||||||
handleClick(cc);
|
handleClick(cc);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onMouseEnter={(e): void => {
|
|
||||||
if (!cc) return;
|
|
||||||
setTooltip({
|
|
||||||
cc,
|
|
||||||
count,
|
|
||||||
name: countryNames?.[cc] ?? cc,
|
|
||||||
x: e.clientX,
|
|
||||||
y: e.clientY,
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onMouseMove={(e): void => {
|
|
||||||
setTooltip((current) =>
|
|
||||||
current
|
|
||||||
? {
|
|
||||||
...current,
|
|
||||||
x: e.clientX,
|
|
||||||
y: e.clientY,
|
|
||||||
}
|
|
||||||
: current,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
onMouseLeave={(): void => {
|
|
||||||
setTooltip(null);
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<Geography
|
<Geography
|
||||||
geography={geo}
|
geography={geo}
|
||||||
@@ -237,22 +177,6 @@ function GeoLayer({
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{tooltip &&
|
|
||||||
createPortal(
|
|
||||||
<div
|
|
||||||
className={styles.tooltip}
|
|
||||||
style={{ left: tooltip.x + 12, top: tooltip.y + 12 }}
|
|
||||||
role="tooltip"
|
|
||||||
aria-live="polite"
|
|
||||||
>
|
|
||||||
<span className={styles.tooltipCountry}>{tooltip.name}</span>
|
|
||||||
<span className={styles.tooltipCount}>
|
|
||||||
{tooltip.count.toLocaleString()} ban{tooltip.count !== 1 ? "s" : ""}
|
|
||||||
</span>
|
|
||||||
</div>,
|
|
||||||
document.body,
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -264,8 +188,6 @@ function GeoLayer({
|
|||||||
export interface WorldMapProps {
|
export interface WorldMapProps {
|
||||||
/** ISO alpha-2 country code → ban count. */
|
/** ISO alpha-2 country code → ban count. */
|
||||||
countries: Record<string, number>;
|
countries: Record<string, number>;
|
||||||
/** Optional mapping from country code to display name. */
|
|
||||||
countryNames?: Record<string, string>;
|
|
||||||
/** Currently selected country filter (null means no filter). */
|
/** Currently selected country filter (null means no filter). */
|
||||||
selectedCountry: string | null;
|
selectedCountry: string | null;
|
||||||
/** Called when the user clicks a country or deselects. */
|
/** Called when the user clicks a country or deselects. */
|
||||||
@@ -280,7 +202,6 @@ export interface WorldMapProps {
|
|||||||
|
|
||||||
export function WorldMap({
|
export function WorldMap({
|
||||||
countries,
|
countries,
|
||||||
countryNames,
|
|
||||||
selectedCountry,
|
selectedCountry,
|
||||||
onSelectCountry,
|
onSelectCountry,
|
||||||
thresholdLow = 20,
|
thresholdLow = 20,
|
||||||
@@ -364,7 +285,6 @@ export function WorldMap({
|
|||||||
>
|
>
|
||||||
<GeoLayer
|
<GeoLayer
|
||||||
countries={countries}
|
countries={countries}
|
||||||
countryNames={countryNames}
|
|
||||||
selectedCountry={selectedCountry}
|
selectedCountry={selectedCountry}
|
||||||
onSelectCountry={onSelectCountry}
|
onSelectCountry={onSelectCountry}
|
||||||
thresholdLow={thresholdLow}
|
thresholdLow={thresholdLow}
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ describe("ServerStatusBar", () => {
|
|||||||
it("shows a spinner while the initial load is in progress", () => {
|
it("shows a spinner while the initial load is in progress", () => {
|
||||||
mockedUseServerStatus.mockReturnValue({
|
mockedUseServerStatus.mockReturnValue({
|
||||||
status: null,
|
status: null,
|
||||||
banguiVersion: null,
|
|
||||||
loading: true,
|
loading: true,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -60,7 +59,6 @@ describe("ServerStatusBar", () => {
|
|||||||
total_bans: 10,
|
total_bans: 10,
|
||||||
total_failures: 5,
|
total_failures: 5,
|
||||||
},
|
},
|
||||||
banguiVersion: "1.1.0",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -78,7 +76,6 @@ describe("ServerStatusBar", () => {
|
|||||||
total_bans: 0,
|
total_bans: 0,
|
||||||
total_failures: 0,
|
total_failures: 0,
|
||||||
},
|
},
|
||||||
banguiVersion: "1.1.0",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -96,7 +93,6 @@ describe("ServerStatusBar", () => {
|
|||||||
total_bans: 0,
|
total_bans: 0,
|
||||||
total_failures: 0,
|
total_failures: 0,
|
||||||
},
|
},
|
||||||
banguiVersion: "1.2.3",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -105,24 +101,6 @@ describe("ServerStatusBar", () => {
|
|||||||
expect(screen.getByText("v1.2.3")).toBeInTheDocument();
|
expect(screen.getByText("v1.2.3")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("renders a BanGUI version badge", () => {
|
|
||||||
mockedUseServerStatus.mockReturnValue({
|
|
||||||
status: {
|
|
||||||
online: true,
|
|
||||||
version: "1.2.3",
|
|
||||||
active_jails: 1,
|
|
||||||
total_bans: 0,
|
|
||||||
total_failures: 0,
|
|
||||||
},
|
|
||||||
banguiVersion: "9.9.9",
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
refresh: vi.fn(),
|
|
||||||
});
|
|
||||||
renderBar();
|
|
||||||
expect(screen.getByText("BanGUI v9.9.9")).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not render the version element when version is null", () => {
|
it("does not render the version element when version is null", () => {
|
||||||
mockedUseServerStatus.mockReturnValue({
|
mockedUseServerStatus.mockReturnValue({
|
||||||
status: {
|
status: {
|
||||||
@@ -132,7 +110,6 @@ describe("ServerStatusBar", () => {
|
|||||||
total_bans: 0,
|
total_bans: 0,
|
||||||
total_failures: 0,
|
total_failures: 0,
|
||||||
},
|
},
|
||||||
banguiVersion: "1.2.3",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -151,7 +128,6 @@ describe("ServerStatusBar", () => {
|
|||||||
total_bans: 21,
|
total_bans: 21,
|
||||||
total_failures: 99,
|
total_failures: 99,
|
||||||
},
|
},
|
||||||
banguiVersion: "1.0.0",
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: null,
|
error: null,
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
@@ -167,7 +143,6 @@ describe("ServerStatusBar", () => {
|
|||||||
it("renders an error message when the status fetch fails", () => {
|
it("renders an error message when the status fetch fails", () => {
|
||||||
mockedUseServerStatus.mockReturnValue({
|
mockedUseServerStatus.mockReturnValue({
|
||||||
status: null,
|
status: null,
|
||||||
banguiVersion: null,
|
|
||||||
loading: false,
|
loading: false,
|
||||||
error: "Network error",
|
error: "Network error",
|
||||||
refresh: vi.fn(),
|
refresh: vi.fn(),
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* Tests for WorldMap component.
|
|
||||||
*
|
|
||||||
* Verifies that hovering a country shows a tooltip with the country name and ban count.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { fireEvent, render, screen } from "@testing-library/react";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
|
|
||||||
// Mock react-simple-maps to avoid fetching real TopoJSON and to control geometry.
|
|
||||||
vi.mock("react-simple-maps", () => ({
|
|
||||||
ComposableMap: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
||||||
ZoomableGroup: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
|
||||||
Geography: ({ children }: { children?: React.ReactNode }) => <g>{children}</g>,
|
|
||||||
useGeographies: () => ({
|
|
||||||
geographies: [{ rsmKey: "geo-1", id: 840 }],
|
|
||||||
path: { centroid: () => [10, 10] },
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
import { WorldMap } from "../WorldMap";
|
|
||||||
|
|
||||||
describe("WorldMap", () => {
|
|
||||||
it("shows a tooltip with country name and ban count on hover", () => {
|
|
||||||
render(
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<WorldMap
|
|
||||||
countries={{ US: 42 }}
|
|
||||||
countryNames={{ US: "United States" }}
|
|
||||||
selectedCountry={null}
|
|
||||||
onSelectCountry={vi.fn()}
|
|
||||||
/>
|
|
||||||
</FluentProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Tooltip should not be present initially
|
|
||||||
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
||||||
|
|
||||||
const countryButton = screen.getByRole("button", { name: /US: 42 bans/i });
|
|
||||||
fireEvent.mouseEnter(countryButton, { clientX: 10, clientY: 10 });
|
|
||||||
|
|
||||||
const tooltip = screen.getByRole("tooltip");
|
|
||||||
expect(tooltip).toHaveTextContent("United States");
|
|
||||||
expect(tooltip).toHaveTextContent("42 bans");
|
|
||||||
expect(tooltip).toHaveStyle({ left: "22px", top: "22px" });
|
|
||||||
|
|
||||||
fireEvent.mouseLeave(countryButton);
|
|
||||||
expect(screen.queryByRole("tooltip")).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -216,6 +216,7 @@ function JailConfigDetail({
|
|||||||
ignore_regex: ignoreRegex,
|
ignore_regex: ignoreRegex,
|
||||||
date_pattern: datePattern !== "" ? datePattern : null,
|
date_pattern: datePattern !== "" ? datePattern : null,
|
||||||
dns_mode: dnsMode,
|
dns_mode: dnsMode,
|
||||||
|
backend,
|
||||||
log_encoding: logEncoding,
|
log_encoding: logEncoding,
|
||||||
prefregex: prefRegex !== "" ? prefRegex : null,
|
prefregex: prefRegex !== "" ? prefRegex : null,
|
||||||
bantime_escalation: {
|
bantime_escalation: {
|
||||||
@@ -230,7 +231,7 @@ function JailConfigDetail({
|
|||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
banTime, findTime, maxRetry, failRegex, ignoreRegex, datePattern,
|
banTime, findTime, maxRetry, failRegex, ignoreRegex, datePattern,
|
||||||
dnsMode, logEncoding, prefRegex, escEnabled, escFactor,
|
dnsMode, backend, logEncoding, prefRegex, escEnabled, escFactor,
|
||||||
escFormula, escMultipliers, escMaxTime, escRndTime, escOverallJails,
|
escFormula, escMultipliers, escMaxTime, escRndTime, escOverallJails,
|
||||||
jail.ban_time, jail.find_time, jail.max_retry,
|
jail.ban_time, jail.find_time, jail.max_retry,
|
||||||
],
|
],
|
||||||
@@ -757,12 +758,7 @@ function InactiveJailDetail({
|
|||||||
*
|
*
|
||||||
* @returns JSX element.
|
* @returns JSX element.
|
||||||
*/
|
*/
|
||||||
interface JailsTabProps {
|
export function JailsTab(): React.JSX.Element {
|
||||||
/** Jail name to pre-select when the component mounts. */
|
|
||||||
initialJail?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function JailsTab({ initialJail }: JailsTabProps): React.JSX.Element {
|
|
||||||
const styles = useConfigStyles();
|
const styles = useConfigStyles();
|
||||||
const { jails, loading, error, refresh, updateJail } =
|
const { jails, loading, error, refresh, updateJail } =
|
||||||
useJailConfigs();
|
useJailConfigs();
|
||||||
@@ -823,13 +819,6 @@ export function JailsTab({ initialJail }: JailsTabProps): React.JSX.Element {
|
|||||||
return [...activeItems, ...inactiveItems];
|
return [...activeItems, ...inactiveItems];
|
||||||
}, [jails, inactiveJails]);
|
}, [jails, inactiveJails]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!initialJail || selectedName) return;
|
|
||||||
if (listItems.some((item) => item.name === initialJail)) {
|
|
||||||
setSelectedName(initialJail);
|
|
||||||
}
|
|
||||||
}, [initialJail, listItems, selectedName]);
|
|
||||||
|
|
||||||
const activeJailMap = useMemo(
|
const activeJailMap = useMemo(
|
||||||
() => new Map(jails.map((j) => [j.name, j])),
|
() => new Map(jails.map((j) => [j.name, j])),
|
||||||
[jails],
|
[jails],
|
||||||
|
|||||||
@@ -352,12 +352,6 @@ export function ServerHealthSection(): React.JSX.Element {
|
|||||||
<Text className={styles.statValue}>{status.version}</Text>
|
<Text className={styles.statValue}>{status.version}</Text>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{status.bangui_version && (
|
|
||||||
<div className={styles.statCard}>
|
|
||||||
<Text className={styles.statLabel}>BanGUI</Text>
|
|
||||||
<Text className={styles.statValue}>{status.bangui_version}</Text>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div className={styles.statCard}>
|
<div className={styles.statCard}>
|
||||||
<Text className={styles.statLabel}>Active Jails</Text>
|
<Text className={styles.statLabel}>Active Jails</Text>
|
||||||
<Text className={styles.statValue}>{status.jail_count}</Text>
|
<Text className={styles.statValue}>{status.jail_count}</Text>
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { render } from "@testing-library/react";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
|
|
||||||
import { JailsTab } from "../JailsTab";
|
|
||||||
import type { JailConfig } from "../../../types/config";
|
|
||||||
import { useAutoSave } from "../../../hooks/useAutoSave";
|
|
||||||
import { useJailConfigs } from "../../../hooks/useConfig";
|
|
||||||
import { useConfigActiveStatus } from "../../../hooks/useConfigActiveStatus";
|
|
||||||
|
|
||||||
vi.mock("../../../hooks/useAutoSave");
|
|
||||||
vi.mock("../../../hooks/useConfig");
|
|
||||||
vi.mock("../../../hooks/useConfigActiveStatus");
|
|
||||||
vi.mock("../../../api/config", () => ({
|
|
||||||
fetchInactiveJails: vi.fn().mockResolvedValue({ jails: [] }),
|
|
||||||
deactivateJail: vi.fn(),
|
|
||||||
deleteJailLocalOverride: vi.fn(),
|
|
||||||
addLogPath: vi.fn(),
|
|
||||||
deleteLogPath: vi.fn(),
|
|
||||||
fetchJailConfigFileContent: vi.fn(),
|
|
||||||
updateJailConfigFile: vi.fn(),
|
|
||||||
validateJailConfig: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockUseAutoSave = vi.mocked(useAutoSave);
|
|
||||||
const mockUseJailConfigs = vi.mocked(useJailConfigs);
|
|
||||||
const mockUseConfigActiveStatus = vi.mocked(useConfigActiveStatus);
|
|
||||||
|
|
||||||
const basicJail: JailConfig = {
|
|
||||||
name: "sshd",
|
|
||||||
ban_time: 600,
|
|
||||||
max_retry: 5,
|
|
||||||
find_time: 600,
|
|
||||||
fail_regex: [],
|
|
||||||
ignore_regex: [],
|
|
||||||
log_paths: [],
|
|
||||||
date_pattern: null,
|
|
||||||
log_encoding: "auto",
|
|
||||||
backend: "polling",
|
|
||||||
use_dns: "warn",
|
|
||||||
prefregex: "",
|
|
||||||
actions: [],
|
|
||||||
bantime_escalation: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("JailsTab", () => {
|
|
||||||
it("does not include backend in auto-save payload", () => {
|
|
||||||
const autoSavePayloads: Array<Record<string, unknown>> = [];
|
|
||||||
mockUseAutoSave.mockImplementation((value) => {
|
|
||||||
autoSavePayloads.push(value as Record<string, unknown>);
|
|
||||||
return { status: "idle", errorText: null, retry: vi.fn() };
|
|
||||||
});
|
|
||||||
|
|
||||||
mockUseJailConfigs.mockReturnValue({
|
|
||||||
jails: [basicJail],
|
|
||||||
total: 1,
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
refresh: vi.fn(),
|
|
||||||
updateJail: vi.fn(),
|
|
||||||
reloadAll: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
mockUseConfigActiveStatus.mockReturnValue({
|
|
||||||
activeJails: new Set<string>(),
|
|
||||||
activeFilters: new Set<string>(),
|
|
||||||
activeActions: new Set<string>(),
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
refresh: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<JailsTab initialJail="sshd" />
|
|
||||||
</FluentProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(autoSavePayloads.length).toBeGreaterThan(0);
|
|
||||||
const lastPayload = autoSavePayloads[autoSavePayloads.length - 1];
|
|
||||||
|
|
||||||
expect(lastPayload).not.toHaveProperty("backend");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
import { ServerHealthSection } from "../ServerHealthSection";
|
|
||||||
|
|
||||||
vi.mock("../../../api/config");
|
|
||||||
|
|
||||||
import { fetchFail2BanLog, fetchServiceStatus } from "../../../api/config";
|
|
||||||
|
|
||||||
const mockedFetchServiceStatus = vi.mocked(fetchServiceStatus);
|
|
||||||
const mockedFetchFail2BanLog = vi.mocked(fetchFail2BanLog);
|
|
||||||
|
|
||||||
describe("ServerHealthSection", () => {
|
|
||||||
beforeEach(() => {
|
|
||||||
vi.clearAllMocks();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("shows the BanGUI version in the service health panel", async () => {
|
|
||||||
mockedFetchServiceStatus.mockResolvedValue({
|
|
||||||
online: true,
|
|
||||||
version: "1.2.3",
|
|
||||||
bangui_version: "1.2.3",
|
|
||||||
jail_count: 2,
|
|
||||||
total_bans: 5,
|
|
||||||
total_failures: 1,
|
|
||||||
log_level: "INFO",
|
|
||||||
log_target: "STDOUT",
|
|
||||||
});
|
|
||||||
|
|
||||||
mockedFetchFail2BanLog.mockResolvedValue({
|
|
||||||
log_path: "/var/log/fail2ban.log",
|
|
||||||
lines: ["2026-01-01 fail2ban[123]: INFO Test"],
|
|
||||||
total_lines: 1,
|
|
||||||
log_level: "INFO",
|
|
||||||
log_target: "STDOUT",
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<ServerHealthSection />
|
|
||||||
</FluentProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// The service health panel should render and include the BanGUI version.
|
|
||||||
const banGuiLabel = await screen.findByText("BanGUI");
|
|
||||||
expect(banGuiLabel).toBeInTheDocument();
|
|
||||||
|
|
||||||
const banGuiCard = banGuiLabel.closest("div");
|
|
||||||
expect(banGuiCard).toHaveTextContent("1.2.3");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -18,8 +18,6 @@ const POLL_INTERVAL_MS = 30_000;
|
|||||||
export interface UseServerStatusResult {
|
export interface UseServerStatusResult {
|
||||||
/** The most recent server status snapshot, or `null` before the first fetch. */
|
/** The most recent server status snapshot, or `null` before the first fetch. */
|
||||||
status: ServerStatus | null;
|
status: ServerStatus | null;
|
||||||
/** BanGUI application version string. */
|
|
||||||
banguiVersion: string | null;
|
|
||||||
/** Whether a fetch is currently in flight. */
|
/** Whether a fetch is currently in flight. */
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
/** Error message string when the last fetch failed, otherwise `null`. */
|
/** Error message string when the last fetch failed, otherwise `null`. */
|
||||||
@@ -35,7 +33,6 @@ export interface UseServerStatusResult {
|
|||||||
*/
|
*/
|
||||||
export function useServerStatus(): UseServerStatusResult {
|
export function useServerStatus(): UseServerStatusResult {
|
||||||
const [status, setStatus] = useState<ServerStatus | null>(null);
|
const [status, setStatus] = useState<ServerStatus | null>(null);
|
||||||
const [banguiVersion, setBanguiVersion] = useState<string | null>(null);
|
|
||||||
const [loading, setLoading] = useState<boolean>(true);
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
@@ -47,7 +44,6 @@ export function useServerStatus(): UseServerStatusResult {
|
|||||||
try {
|
try {
|
||||||
const data = await fetchServerStatus();
|
const data = await fetchServerStatus();
|
||||||
setStatus(data.status);
|
setStatus(data.status);
|
||||||
setBanguiVersion(data.bangui_version);
|
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
handleFetchError(err, setError, "Failed to fetch server status");
|
handleFetchError(err, setError, "Failed to fetch server status");
|
||||||
@@ -82,5 +78,5 @@ export function useServerStatus(): UseServerStatusResult {
|
|||||||
void doFetch().catch((): void => undefined);
|
void doFetch().catch((): void => undefined);
|
||||||
}, [doFetch]);
|
}, [doFetch]);
|
||||||
|
|
||||||
return { status, banguiVersion, loading, error, refresh };
|
return { status, loading, error, refresh };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ export function MainLayout(): React.JSX.Element {
|
|||||||
<div className={styles.sidebarFooter}>
|
<div className={styles.sidebarFooter}>
|
||||||
{!collapsed && (
|
{!collapsed && (
|
||||||
<Text className={styles.versionText}>
|
<Text className={styles.versionText}>
|
||||||
BanGUI
|
BanGUI v{__APP_VERSION__}
|
||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
<Tooltip
|
<Tooltip
|
||||||
|
|||||||
@@ -63,16 +63,16 @@ describe("MainLayout", () => {
|
|||||||
expect(screen.getByRole("navigation", { name: "Main navigation" })).toBeInTheDocument();
|
expect(screen.getByRole("navigation", { name: "Main navigation" })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not show the BanGUI application version in the sidebar footer", () => {
|
it("shows the BanGUI version in the sidebar footer when expanded", () => {
|
||||||
renderLayout();
|
renderLayout();
|
||||||
// __APP_VERSION__ is stubbed to "0.0.0-test" via vitest.config.ts define.
|
// __APP_VERSION__ is stubbed to "0.0.0-test" via vitest.config.ts define.
|
||||||
expect(screen.queryByText(/BanGUI v/)).not.toBeInTheDocument();
|
expect(screen.getByText("BanGUI v0.0.0-test")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("hides the logo text when the sidebar is collapsed", async () => {
|
it("hides the BanGUI version text when the sidebar is collapsed", async () => {
|
||||||
renderLayout();
|
renderLayout();
|
||||||
const toggleButton = screen.getByRole("button", { name: /collapse sidebar/i });
|
const toggleButton = screen.getByRole("button", { name: /collapse sidebar/i });
|
||||||
await userEvent.click(toggleButton);
|
await userEvent.click(toggleButton);
|
||||||
expect(screen.queryByText("BanGUI")).not.toBeInTheDocument();
|
expect(screen.queryByText("BanGUI v0.0.0-test")).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,8 +13,7 @@
|
|||||||
* Export — raw file editors for jail, filter, and action files
|
* Export — raw file editors for jail, filter, and action files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
import { useLocation } from "react-router-dom";
|
|
||||||
import { Tab, TabList, Text, makeStyles, tokens } from "@fluentui/react-components";
|
import { Tab, TabList, Text, makeStyles, tokens } from "@fluentui/react-components";
|
||||||
import {
|
import {
|
||||||
ActionsTab,
|
ActionsTab,
|
||||||
@@ -59,16 +58,8 @@ type TabValue =
|
|||||||
|
|
||||||
export function ConfigPage(): React.JSX.Element {
|
export function ConfigPage(): React.JSX.Element {
|
||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
const location = useLocation();
|
|
||||||
const [tab, setTab] = useState<TabValue>("jails");
|
const [tab, setTab] = useState<TabValue>("jails");
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const state = location.state as { tab?: string; jail?: string } | null;
|
|
||||||
if (state?.tab === "jails") {
|
|
||||||
setTab("jails");
|
|
||||||
}
|
|
||||||
}, [location.state]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.page}>
|
<div className={styles.page}>
|
||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
@@ -95,11 +86,7 @@ export function ConfigPage(): React.JSX.Element {
|
|||||||
</TabList>
|
</TabList>
|
||||||
|
|
||||||
<div className={styles.tabContent} key={tab}>
|
<div className={styles.tabContent} key={tab}>
|
||||||
{tab === "jails" && (
|
{tab === "jails" && <JailsTab />}
|
||||||
<JailsTab
|
|
||||||
initialJail={(location.state as { jail?: string } | null)?.jail}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{tab === "filters" && <FiltersTab />}
|
{tab === "filters" && <FiltersTab />}
|
||||||
{tab === "actions" && <ActionsTab />}
|
{tab === "actions" && <ActionsTab />}
|
||||||
{tab === "server" && <ServerTab />}
|
{tab === "server" && <ServerTab />}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
Input,
|
Input,
|
||||||
MessageBar,
|
MessageBar,
|
||||||
MessageBarBody,
|
MessageBarBody,
|
||||||
|
Select,
|
||||||
Spinner,
|
Spinner,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -42,10 +43,8 @@ import {
|
|||||||
ChevronLeftRegular,
|
ChevronLeftRegular,
|
||||||
ChevronRightRegular,
|
ChevronRightRegular,
|
||||||
} from "@fluentui/react-icons";
|
} from "@fluentui/react-icons";
|
||||||
import { DashboardFilterBar } from "../components/DashboardFilterBar";
|
|
||||||
import { useHistory, useIpHistory } from "../hooks/useHistory";
|
import { useHistory, useIpHistory } from "../hooks/useHistory";
|
||||||
import type { HistoryBanItem, HistoryQuery, TimeRange } from "../types/history";
|
import type { HistoryBanItem, HistoryQuery, TimeRange } from "../types/history";
|
||||||
import type { BanOriginFilter } from "../types/ban";
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Constants
|
// Constants
|
||||||
@@ -56,6 +55,13 @@ const HIGH_BAN_THRESHOLD = 5;
|
|||||||
|
|
||||||
const PAGE_SIZE = 50;
|
const PAGE_SIZE = 50;
|
||||||
|
|
||||||
|
const TIME_RANGE_OPTIONS: { label: string; value: TimeRange }[] = [
|
||||||
|
{ label: "Last 24 hours", value: "24h" },
|
||||||
|
{ label: "Last 7 days", value: "7d" },
|
||||||
|
{ label: "Last 30 days", value: "30d" },
|
||||||
|
{ label: "Last 365 days", value: "365d" },
|
||||||
|
];
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Styles
|
// Styles
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -374,8 +380,7 @@ export function HistoryPage(): React.JSX.Element {
|
|||||||
const styles = useStyles();
|
const styles = useStyles();
|
||||||
|
|
||||||
// Filter state
|
// Filter state
|
||||||
const [range, setRange] = useState<TimeRange>("24h");
|
const [range, setRange] = useState<TimeRange | undefined>(undefined);
|
||||||
const [originFilter, setOriginFilter] = useState<BanOriginFilter>("all");
|
|
||||||
const [jailFilter, setJailFilter] = useState("");
|
const [jailFilter, setJailFilter] = useState("");
|
||||||
const [ipFilter, setIpFilter] = useState("");
|
const [ipFilter, setIpFilter] = useState("");
|
||||||
const [appliedQuery, setAppliedQuery] = useState<HistoryQuery>({
|
const [appliedQuery, setAppliedQuery] = useState<HistoryQuery>({
|
||||||
@@ -391,12 +396,11 @@ export function HistoryPage(): React.JSX.Element {
|
|||||||
const applyFilters = useCallback((): void => {
|
const applyFilters = useCallback((): void => {
|
||||||
setAppliedQuery({
|
setAppliedQuery({
|
||||||
range: range,
|
range: range,
|
||||||
origin: originFilter !== "all" ? originFilter : undefined,
|
|
||||||
jail: jailFilter.trim() || undefined,
|
jail: jailFilter.trim() || undefined,
|
||||||
ip: ipFilter.trim() || undefined,
|
ip: ipFilter.trim() || undefined,
|
||||||
page_size: PAGE_SIZE,
|
page_size: PAGE_SIZE,
|
||||||
});
|
});
|
||||||
}, [range, originFilter, jailFilter, ipFilter]);
|
}, [range, jailFilter, ipFilter]);
|
||||||
|
|
||||||
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
||||||
|
|
||||||
@@ -447,16 +451,24 @@ export function HistoryPage(): React.JSX.Element {
|
|||||||
{/* Filter bar */}
|
{/* Filter bar */}
|
||||||
{/* ---------------------------------------------------------------- */}
|
{/* ---------------------------------------------------------------- */}
|
||||||
<div className={styles.filterRow}>
|
<div className={styles.filterRow}>
|
||||||
<DashboardFilterBar
|
<div className={styles.filterLabel}>
|
||||||
timeRange={range}
|
<Text size={200}>Time range</Text>
|
||||||
onTimeRangeChange={(value) => {
|
<Select
|
||||||
setRange(value);
|
aria-label="Time range"
|
||||||
|
value={range ?? ""}
|
||||||
|
onChange={(_ev, data): void => {
|
||||||
|
setRange(data.value === "" ? undefined : (data.value as TimeRange));
|
||||||
}}
|
}}
|
||||||
originFilter={originFilter}
|
size="small"
|
||||||
onOriginFilterChange={(value) => {
|
>
|
||||||
setOriginFilter(value);
|
<option value="">All time</option>
|
||||||
}}
|
{TIME_RANGE_OPTIONS.map((o) => (
|
||||||
/>
|
<option key={o.value} value={o.value}>
|
||||||
|
{o.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className={styles.filterLabel}>
|
<div className={styles.filterLabel}>
|
||||||
<Text size={200}>Jail</Text>
|
<Text size={200}>Jail</Text>
|
||||||
@@ -493,8 +505,7 @@ export function HistoryPage(): React.JSX.Element {
|
|||||||
appearance="subtle"
|
appearance="subtle"
|
||||||
size="small"
|
size="small"
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
setRange("24h");
|
setRange(undefined);
|
||||||
setOriginFilter("all");
|
|
||||||
setJailFilter("");
|
setJailFilter("");
|
||||||
setIpFilter("");
|
setIpFilter("");
|
||||||
setAppliedQuery({ page_size: PAGE_SIZE });
|
setAppliedQuery({ page_size: PAGE_SIZE });
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
MessageBar,
|
MessageBar,
|
||||||
MessageBarBody,
|
MessageBarBody,
|
||||||
|
Select,
|
||||||
Spinner,
|
Spinner,
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -21,17 +22,19 @@ import {
|
|||||||
TableHeaderCell,
|
TableHeaderCell,
|
||||||
TableRow,
|
TableRow,
|
||||||
Text,
|
Text,
|
||||||
|
Toolbar,
|
||||||
|
ToolbarButton,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
makeStyles,
|
makeStyles,
|
||||||
tokens,
|
tokens,
|
||||||
} from "@fluentui/react-components";
|
} from "@fluentui/react-components";
|
||||||
import { ArrowCounterclockwiseRegular, DismissRegular } from "@fluentui/react-icons";
|
import { ArrowCounterclockwiseRegular, DismissRegular } from "@fluentui/react-icons";
|
||||||
import { DashboardFilterBar } from "../components/DashboardFilterBar";
|
|
||||||
import { WorldMap } from "../components/WorldMap";
|
import { WorldMap } from "../components/WorldMap";
|
||||||
import { useMapData } from "../hooks/useMapData";
|
import { useMapData } from "../hooks/useMapData";
|
||||||
import { useMapColorThresholds } from "../hooks/useMapColorThresholds";
|
import { useMapColorThresholds } from "../hooks/useMapColorThresholds";
|
||||||
import type { TimeRange } from "../types/map";
|
import type { TimeRange } from "../types/map";
|
||||||
import type { BanOriginFilter } from "../types/ban";
|
import type { BanOriginFilter } from "../types/ban";
|
||||||
|
import { BAN_ORIGIN_FILTER_LABELS } from "../types/ban";
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Styles
|
// Styles
|
||||||
@@ -53,23 +56,34 @@ const useStyles = makeStyles({
|
|||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
gap: tokens.spacingHorizontalM,
|
gap: tokens.spacingHorizontalM,
|
||||||
},
|
},
|
||||||
|
filterBar: {
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: tokens.spacingHorizontalM,
|
||||||
|
padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`,
|
||||||
|
background: tokens.colorNeutralBackground3,
|
||||||
|
borderRadius: tokens.borderRadiusMedium,
|
||||||
|
border: `1px solid ${tokens.colorNeutralStroke2}`,
|
||||||
|
},
|
||||||
tableWrapper: {
|
tableWrapper: {
|
||||||
overflow: "auto",
|
overflow: "auto",
|
||||||
maxHeight: "420px",
|
maxHeight: "420px",
|
||||||
borderRadius: tokens.borderRadiusMedium,
|
borderRadius: tokens.borderRadiusMedium,
|
||||||
border: `1px solid ${tokens.colorNeutralStroke1}`,
|
border: `1px solid ${tokens.colorNeutralStroke1}`,
|
||||||
},
|
},
|
||||||
filterBar: {
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
gap: tokens.spacingHorizontalM,
|
|
||||||
padding: tokens.spacingVerticalS,
|
|
||||||
borderRadius: tokens.borderRadiusMedium,
|
|
||||||
backgroundColor: tokens.colorNeutralBackground2,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Time-range options
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const TIME_RANGE_OPTIONS: { label: string; value: TimeRange }[] = [
|
||||||
|
{ label: "Last 24 hours", value: "24h" },
|
||||||
|
{ label: "Last 7 days", value: "7d" },
|
||||||
|
{ label: "Last 30 days", value: "30d" },
|
||||||
|
{ label: "Last 365 days", value: "365d" },
|
||||||
|
];
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// MapPage
|
// MapPage
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -119,20 +133,41 @@ export function MapPage(): React.JSX.Element {
|
|||||||
World Map
|
World Map
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
<div style={{ display: "flex", alignItems: "center", gap: tokens.spacingHorizontalM, flexWrap: "wrap" }}>
|
<Toolbar size="small">
|
||||||
<DashboardFilterBar
|
<Select
|
||||||
timeRange={range}
|
aria-label="Time range"
|
||||||
onTimeRangeChange={(value) => {
|
value={range}
|
||||||
setRange(value);
|
onChange={(_ev, data): void => {
|
||||||
|
setRange(data.value as TimeRange);
|
||||||
setSelectedCountry(null);
|
setSelectedCountry(null);
|
||||||
}}
|
}}
|
||||||
originFilter={originFilter}
|
size="small"
|
||||||
onOriginFilterChange={(value) => {
|
>
|
||||||
setOriginFilter(value);
|
{TIME_RANGE_OPTIONS.map((o) => (
|
||||||
|
<option key={o.value} value={o.value}>
|
||||||
|
{o.label}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
{/* Origin filter */}
|
||||||
|
<Select
|
||||||
|
aria-label="Origin filter"
|
||||||
|
value={originFilter}
|
||||||
|
onChange={(_ev, data): void => {
|
||||||
|
setOriginFilter(data.value as BanOriginFilter);
|
||||||
setSelectedCountry(null);
|
setSelectedCountry(null);
|
||||||
}}
|
}}
|
||||||
/>
|
size="small"
|
||||||
<Button
|
>
|
||||||
|
{(["all", "blocklist", "selfblock"] as BanOriginFilter[]).map((f) => (
|
||||||
|
<option key={f} value={f}>
|
||||||
|
{BAN_ORIGIN_FILTER_LABELS[f]}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
|
||||||
|
<ToolbarButton
|
||||||
icon={<ArrowCounterclockwiseRegular />}
|
icon={<ArrowCounterclockwiseRegular />}
|
||||||
onClick={(): void => {
|
onClick={(): void => {
|
||||||
refresh();
|
refresh();
|
||||||
@@ -140,7 +175,7 @@ export function MapPage(): React.JSX.Element {
|
|||||||
disabled={loading}
|
disabled={loading}
|
||||||
title="Refresh"
|
title="Refresh"
|
||||||
/>
|
/>
|
||||||
</div>
|
</Toolbar>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* ---------------------------------------------------------------- */}
|
{/* ---------------------------------------------------------------- */}
|
||||||
@@ -164,7 +199,6 @@ export function MapPage(): React.JSX.Element {
|
|||||||
{!loading && !error && (
|
{!loading && !error && (
|
||||||
<WorldMap
|
<WorldMap
|
||||||
countries={countries}
|
countries={countries}
|
||||||
countryNames={countryNames}
|
|
||||||
selectedCountry={selectedCountry}
|
selectedCountry={selectedCountry}
|
||||||
onSelectCountry={setSelectedCountry}
|
onSelectCountry={setSelectedCountry}
|
||||||
thresholdLow={thresholdLow}
|
thresholdLow={thresholdLow}
|
||||||
|
|||||||
@@ -6,11 +6,7 @@ import { ConfigPage } from "../ConfigPage";
|
|||||||
|
|
||||||
// Mock all tab components to avoid deep render trees and API calls.
|
// Mock all tab components to avoid deep render trees and API calls.
|
||||||
vi.mock("../../components/config", () => ({
|
vi.mock("../../components/config", () => ({
|
||||||
JailsTab: ({ initialJail }: { initialJail?: string }) => (
|
JailsTab: () => <div data-testid="jails-tab">JailsTab</div>,
|
||||||
<div data-testid="jails-tab" data-initial-jail={initialJail}>
|
|
||||||
JailsTab
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
FiltersTab: () => <div data-testid="filters-tab">FiltersTab</div>,
|
FiltersTab: () => <div data-testid="filters-tab">FiltersTab</div>,
|
||||||
ActionsTab: () => <div data-testid="actions-tab">ActionsTab</div>,
|
ActionsTab: () => <div data-testid="actions-tab">ActionsTab</div>,
|
||||||
ServerTab: () => <div data-testid="server-tab">ServerTab</div>,
|
ServerTab: () => <div data-testid="server-tab">ServerTab</div>,
|
||||||
@@ -57,22 +53,4 @@ describe("ConfigPage", () => {
|
|||||||
renderPage();
|
renderPage();
|
||||||
expect(screen.getByRole("heading", { name: /configuration/i })).toBeInTheDocument();
|
expect(screen.getByRole("heading", { name: /configuration/i })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("selects the Jails tab based on location state", () => {
|
|
||||||
render(
|
|
||||||
<MemoryRouter
|
|
||||||
initialEntries={[
|
|
||||||
{ pathname: "/config", state: { tab: "jails", jail: "sshd" } },
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<ConfigPage />
|
|
||||||
</FluentProvider>
|
|
||||||
</MemoryRouter>,
|
|
||||||
);
|
|
||||||
|
|
||||||
const jailsTab = screen.getByTestId("jails-tab");
|
|
||||||
expect(jailsTab).toBeInTheDocument();
|
|
||||||
expect(jailsTab).toHaveAttribute("data-initial-jail", "sshd");
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
import { HistoryPage } from "../HistoryPage";
|
|
||||||
|
|
||||||
let lastQuery: Record<string, unknown> | null = null;
|
|
||||||
const mockUseHistory = vi.fn((query: Record<string, unknown>) => {
|
|
||||||
lastQuery = query;
|
|
||||||
return {
|
|
||||||
items: [],
|
|
||||||
total: 0,
|
|
||||||
page: 1,
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
setPage: vi.fn(),
|
|
||||||
refresh: vi.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../hooks/useHistory", () => ({
|
|
||||||
useHistory: (query: Record<string, unknown>) => mockUseHistory(query),
|
|
||||||
useIpHistory: () => ({ detail: null, loading: false, error: null, refresh: vi.fn() }),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../components/WorldMap", () => ({
|
|
||||||
WorldMap: () => <div data-testid="world-map" />,
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../api/config", () => ({
|
|
||||||
fetchMapColorThresholds: async () => ({
|
|
||||||
threshold_low: 10,
|
|
||||||
threshold_medium: 50,
|
|
||||||
threshold_high: 100,
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("HistoryPage", () => {
|
|
||||||
it("renders DashboardFilterBar and applies origin+range filters", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<HistoryPage />
|
|
||||||
</FluentProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Initial load should include the default query.
|
|
||||||
expect(lastQuery).toEqual({ page_size: 50 });
|
|
||||||
|
|
||||||
// Change the time-range and origin filter, then apply.
|
|
||||||
await user.click(screen.getByRole("button", { name: /Last 7 days/i }));
|
|
||||||
await user.click(screen.getByRole("button", { name: /Blocklist/i }));
|
|
||||||
await user.click(screen.getByRole("button", { name: /Apply/i }));
|
|
||||||
|
|
||||||
expect(lastQuery).toMatchObject({ range: "7d", origin: "blocklist" });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
import { MemoryRouter } from "react-router-dom";
|
|
||||||
import { JailsPage } from "../JailsPage";
|
|
||||||
import type { JailSummary } from "../../types/jail";
|
|
||||||
|
|
||||||
const mockNavigate = vi.fn();
|
|
||||||
|
|
||||||
vi.mock("react-router-dom", async () => {
|
|
||||||
const actual = (await vi.importActual<typeof import("react-router-dom")>(
|
|
||||||
"react-router-dom",
|
|
||||||
)) as unknown as Record<string, unknown>;
|
|
||||||
return {
|
|
||||||
...actual,
|
|
||||||
useNavigate: () => mockNavigate,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../hooks/useJails", () => ({
|
|
||||||
useJails: () => ({
|
|
||||||
jails: [
|
|
||||||
{
|
|
||||||
name: "sshd",
|
|
||||||
enabled: true,
|
|
||||||
running: true,
|
|
||||||
idle: false,
|
|
||||||
backend: "systemd",
|
|
||||||
find_time: 600,
|
|
||||||
ban_time: 3600,
|
|
||||||
max_retry: 5,
|
|
||||||
status: {
|
|
||||||
currently_banned: 1,
|
|
||||||
total_banned: 10,
|
|
||||||
currently_failed: 0,
|
|
||||||
total_failed: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
] as JailSummary[],
|
|
||||||
total: 1,
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
refresh: vi.fn(),
|
|
||||||
startJail: vi.fn().mockResolvedValue(undefined),
|
|
||||||
stopJail: vi.fn().mockResolvedValue(undefined),
|
|
||||||
setIdle: vi.fn().mockResolvedValue(undefined),
|
|
||||||
reloadJail: vi.fn().mockResolvedValue(undefined),
|
|
||||||
reloadAll: vi.fn().mockResolvedValue(undefined),
|
|
||||||
}),
|
|
||||||
}));
|
|
||||||
|
|
||||||
function renderPage() {
|
|
||||||
return render(
|
|
||||||
<MemoryRouter>
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<JailsPage />
|
|
||||||
</FluentProvider>
|
|
||||||
</MemoryRouter>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("JailsPage", () => {
|
|
||||||
it("navigates to Configuration → Jails when a jail is clicked", async () => {
|
|
||||||
renderPage();
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
await user.click(screen.getByText("sshd"));
|
|
||||||
|
|
||||||
expect(mockNavigate).toHaveBeenCalledWith("/config", {
|
|
||||||
state: { tab: "jails", jail: "sshd" },
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
|
||||||
import { render, screen } from "@testing-library/react";
|
|
||||||
import userEvent from "@testing-library/user-event";
|
|
||||||
import { FluentProvider, webLightTheme } from "@fluentui/react-components";
|
|
||||||
import { MapPage } from "../MapPage";
|
|
||||||
|
|
||||||
const mockFetchMapColorThresholds = vi.fn(async () => ({
|
|
||||||
threshold_low: 10,
|
|
||||||
threshold_medium: 50,
|
|
||||||
threshold_high: 100,
|
|
||||||
}));
|
|
||||||
|
|
||||||
let lastArgs: { range: string; origin: string } = { range: "", origin: "" };
|
|
||||||
const mockUseMapData = vi.fn((range: string, origin: string) => {
|
|
||||||
lastArgs = { range, origin };
|
|
||||||
return {
|
|
||||||
countries: {},
|
|
||||||
countryNames: {},
|
|
||||||
bans: [],
|
|
||||||
total: 0,
|
|
||||||
loading: false,
|
|
||||||
error: null,
|
|
||||||
refresh: vi.fn(),
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
vi.mock("../hooks/useMapData", () => ({
|
|
||||||
useMapData: (range: string, origin: string) => mockUseMapData(range, origin),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock("../api/config", async () => ({
|
|
||||||
fetchMapColorThresholds: mockFetchMapColorThresholds,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockWorldMap = vi.fn((_props: unknown) => <div data-testid="world-map" />);
|
|
||||||
vi.mock("../components/WorldMap", () => ({
|
|
||||||
WorldMap: (props: unknown) => {
|
|
||||||
mockWorldMap(props);
|
|
||||||
return <div data-testid="world-map" />;
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("MapPage", () => {
|
|
||||||
it("renders DashboardFilterBar and updates data when filters change", async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
render(
|
|
||||||
<FluentProvider theme={webLightTheme}>
|
|
||||||
<MapPage />
|
|
||||||
</FluentProvider>,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Initial load should call useMapData with default filters.
|
|
||||||
expect(lastArgs).toEqual({ range: "24h", origin: "all" });
|
|
||||||
|
|
||||||
// Map should receive country names from the hook so tooltips can show human-readable labels.
|
|
||||||
expect(mockWorldMap).toHaveBeenCalled();
|
|
||||||
const firstCallArgs = mockWorldMap.mock.calls[0]?.[0];
|
|
||||||
expect(firstCallArgs).toMatchObject({ countryNames: {} });
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: /Last 7 days/i }));
|
|
||||||
expect(lastArgs.range).toBe("7d");
|
|
||||||
|
|
||||||
await user.click(screen.getByRole("button", { name: /Blocklist/i }));
|
|
||||||
expect(lastArgs.origin).toBe("blocklist");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -661,8 +661,6 @@ export interface ServiceStatusResponse {
|
|||||||
online: boolean;
|
online: boolean;
|
||||||
/** fail2ban version string, or null when offline. */
|
/** fail2ban version string, or null when offline. */
|
||||||
version: string | null;
|
version: string | null;
|
||||||
/** BanGUI application version (from the API). */
|
|
||||||
bangui_version: string;
|
|
||||||
/** Number of currently active jails. */
|
/** Number of currently active jails. */
|
||||||
jail_count: number;
|
jail_count: number;
|
||||||
/** Aggregated current ban count across all jails. */
|
/** Aggregated current ban count across all jails. */
|
||||||
|
|||||||
@@ -50,11 +50,8 @@ export interface IpDetailResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Query parameters supported by GET /api/history */
|
/** Query parameters supported by GET /api/history */
|
||||||
import type { BanOriginFilter } from "./ban";
|
|
||||||
|
|
||||||
export interface HistoryQuery {
|
export interface HistoryQuery {
|
||||||
range?: TimeRange;
|
range?: TimeRange;
|
||||||
origin?: BanOriginFilter;
|
|
||||||
jail?: string;
|
jail?: string;
|
||||||
ip?: string;
|
ip?: string;
|
||||||
page?: number;
|
page?: number;
|
||||||
|
|||||||
@@ -21,6 +21,4 @@ export interface ServerStatus {
|
|||||||
/** Response shape for ``GET /api/dashboard/status``. */
|
/** Response shape for ``GET /api/dashboard/status``. */
|
||||||
export interface ServerStatusResponse {
|
export interface ServerStatusResponse {
|
||||||
status: ServerStatus;
|
status: ServerStatus;
|
||||||
/** BanGUI application version (from the API). */
|
|
||||||
bangui_version: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,16 @@ import react from "@vitejs/plugin-react";
|
|||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
import { readFileSync } from "node:fs";
|
import { readFileSync } from "node:fs";
|
||||||
|
|
||||||
const appVersion = readFileSync(
|
const pkg = JSON.parse(
|
||||||
resolve(__dirname, "../Docker/VERSION"),
|
readFileSync(resolve(__dirname, "package.json"), "utf-8"),
|
||||||
"utf-8",
|
) as { version: string };
|
||||||
)
|
|
||||||
.trim()
|
|
||||||
.replace(/^v/, "");
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
define: {
|
define: {
|
||||||
/** BanGUI application version injected at build time from Docker/VERSION. */
|
/** BanGUI application version injected at build time from package.json. */
|
||||||
__APP_VERSION__: JSON.stringify(appVersion),
|
__APP_VERSION__: JSON.stringify(pkg.version),
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
|
|||||||
10
pytest.ini
10
pytest.ini
@@ -1,10 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
# Ensure pytest-asyncio is in auto mode for async tests without explicit markers.
|
|
||||||
asyncio_mode = auto
|
|
||||||
|
|
||||||
# Run the backend test suite from the repository root.
|
|
||||||
testpaths = backend/tests
|
|
||||||
pythonpath = backend
|
|
||||||
|
|
||||||
# Keep coverage output consistent with backend/pyproject.toml settings.
|
|
||||||
addopts = --cov=backend/app --cov-report=term-missing
|
|
||||||
Reference in New Issue
Block a user