Expose ban-time escalation settings in jail detail and config UI
- Backend: Add BantimeEscalation + BantimeEscalationUpdate Pydantic models to app/models/config.py; add bantime_escalation field to Jail in jail.py - Backend: jail_service.get_jail_detail() fetches 7 bantime.* socket commands (increment, factor, formula, multipliers, maxtime, rndtime, overalljails) and populates bantime_escalation on the returned Jail object - Backend: config_service.get_jail_config() fetches same 7 commands; update_jail_config() writes escalation fields when provided - Frontend: Add BantimeEscalation + BantimeEscalationUpdate interfaces to types/config.ts; extend JailConfig + JailConfigUpdate; extend Jail in types/jail.ts - Frontend: JailDetailPage.tsx adds BantimeEscalationSection component that renders only when increment is enabled (shows factor, formula, multipliers, max_time, rnd_time, overall_jails) - Frontend: ConfigPage.tsx JailAccordionPanel adds full escalation edit form (Switch for enable/disable, number inputs for factor/max_time/rnd_time, text inputs for formula/multipliers, Switch for overall_jails); handleSave includes bantime_escalation in the JailConfigUpdate payload - Tests: Update ConfigPageLogPath.test.tsx mock to include bantime_escalation:null - Docs: Mark Task 6 as DONE in Tasks.md
This commit is contained in:
@@ -5,6 +5,60 @@ Request, response, and domain models for the config router and service.
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Ban-time escalation
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class BantimeEscalation(BaseModel):
|
||||
"""Incremental ban-time escalation configuration for a jail."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
increment: bool = Field(
|
||||
default=False,
|
||||
description="Whether incremental banning is enabled.",
|
||||
)
|
||||
factor: float | None = Field(
|
||||
default=None,
|
||||
description="Multiplier applied to the base ban time on each repeat offence.",
|
||||
)
|
||||
formula: str | None = Field(
|
||||
default=None,
|
||||
description="Python expression evaluated to compute the escalated ban time.",
|
||||
)
|
||||
multipliers: str | None = Field(
|
||||
default=None,
|
||||
description="Space-separated integers used as per-offence multipliers.",
|
||||
)
|
||||
max_time: int | None = Field(
|
||||
default=None,
|
||||
description="Maximum ban duration in seconds when escalation is active.",
|
||||
)
|
||||
rnd_time: int | None = Field(
|
||||
default=None,
|
||||
description="Random jitter (seconds) added to each escalated ban time.",
|
||||
)
|
||||
overall_jails: bool = Field(
|
||||
default=False,
|
||||
description="Count repeat offences across all jails, not just the current one.",
|
||||
)
|
||||
|
||||
|
||||
class BantimeEscalationUpdate(BaseModel):
|
||||
"""Partial update payload for ban-time escalation settings."""
|
||||
|
||||
model_config = ConfigDict(strict=True)
|
||||
|
||||
increment: bool | None = Field(default=None)
|
||||
factor: float | None = Field(default=None)
|
||||
formula: str | None = Field(default=None)
|
||||
multipliers: str | None = Field(default=None)
|
||||
max_time: int | None = Field(default=None)
|
||||
rnd_time: int | None = Field(default=None)
|
||||
overall_jails: bool | None = Field(default=None)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Jail configuration models
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -26,6 +80,10 @@ class JailConfig(BaseModel):
|
||||
log_encoding: str = Field(default="UTF-8", description="Log file encoding.")
|
||||
backend: str = Field(default="polling", description="Log monitoring backend.")
|
||||
actions: list[str] = Field(default_factory=list, description="Names of actions attached to this jail.")
|
||||
bantime_escalation: BantimeEscalation | None = Field(
|
||||
default=None,
|
||||
description="Incremental ban-time escalation settings, or None if not configured.",
|
||||
)
|
||||
|
||||
|
||||
class JailConfigResponse(BaseModel):
|
||||
@@ -58,6 +116,10 @@ class JailConfigUpdate(BaseModel):
|
||||
date_pattern: str | None = Field(default=None)
|
||||
dns_mode: str | None = Field(default=None, description="DNS lookup mode: raw | warn | no.")
|
||||
enabled: bool | None = Field(default=None)
|
||||
bantime_escalation: BantimeEscalationUpdate | None = Field(
|
||||
default=None,
|
||||
description="Incremental ban-time escalation settings to update.",
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -5,6 +5,8 @@ Request, response, and domain models used by the jails router and service.
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
from app.models.config import BantimeEscalation
|
||||
|
||||
|
||||
class JailStatus(BaseModel):
|
||||
"""Runtime metrics for a single jail."""
|
||||
@@ -37,6 +39,10 @@ class Jail(BaseModel):
|
||||
ban_time: int = Field(..., description="Duration (seconds) of a ban. -1 means permanent.")
|
||||
max_retry: int = Field(..., description="Number of failures before a ban is issued.")
|
||||
actions: list[str] = Field(default_factory=list, description="Names of actions attached to this jail.")
|
||||
bantime_escalation: BantimeEscalation | None = Field(
|
||||
default=None,
|
||||
description="Incremental ban-time escalation settings, or None if not configured.",
|
||||
)
|
||||
status: JailStatus | None = Field(default=None, description="Runtime counters.")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user