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:
2026-03-12 20:30:21 +01:00
parent ea35695221
commit e3375fd187
10 changed files with 386 additions and 0 deletions

View File

@@ -117,6 +117,7 @@ const MOCK_JAIL: JailConfig = {
log_encoding: "UTF-8",
backend: "auto",
actions: [],
bantime_escalation: null,
};
// ---------------------------------------------------------------------------

View File

@@ -65,6 +65,7 @@ import {
} from "../api/config";
import type {
AddLogPathRequest,
BantimeEscalationUpdate,
ConfFileEntry,
GlobalConfigUpdate,
JailConfig,
@@ -260,6 +261,16 @@ function JailAccordionPanel({
const [saving, setSaving] = useState(false);
const [msg, setMsg] = useState<{ text: string; ok: boolean } | null>(null);
// Ban-time escalation state (mirrors jail.bantime_escalation or defaults).
const esc0 = jail.bantime_escalation;
const [escEnabled, setEscEnabled] = useState(esc0?.increment ?? false);
const [escFactor, setEscFactor] = useState(esc0?.factor != null ? String(esc0.factor) : "");
const [escFormula, setEscFormula] = useState(esc0?.formula ?? "");
const [escMultipliers, setEscMultipliers] = useState(esc0?.multipliers ?? "");
const [escMaxTime, setEscMaxTime] = useState(esc0?.max_time != null ? String(esc0.max_time) : "");
const [escRndTime, setEscRndTime] = useState(esc0?.rnd_time != null ? String(esc0.rnd_time) : "");
const [escOverallJails, setEscOverallJails] = useState(esc0?.overall_jails ?? false);
const handleDeleteLogPath = useCallback(
async (path: string) => {
setDeletingPath(path);
@@ -305,12 +316,22 @@ function JailAccordionPanel({
setSaving(true);
setMsg(null);
try {
const escalation: BantimeEscalationUpdate = {
increment: escEnabled,
factor: escFactor !== "" ? Number(escFactor) : null,
formula: escFormula !== "" ? escFormula : null,
multipliers: escMultipliers !== "" ? escMultipliers : null,
max_time: escMaxTime !== "" ? Number(escMaxTime) : null,
rnd_time: escRndTime !== "" ? Number(escRndTime) : null,
overall_jails: escOverallJails,
};
await onSave(jail.name, {
ban_time: Number(banTime) || jail.ban_time,
find_time: Number(findTime) || jail.find_time,
max_retry: Number(maxRetry) || jail.max_retry,
fail_regex: failRegex,
ignore_regex: ignoreRegex,
bantime_escalation: escalation,
});
setMsg({ text: "Saved.", ok: true });
} catch (err: unknown) {
@@ -325,6 +346,13 @@ function JailAccordionPanel({
maxRetry,
failRegex,
ignoreRegex,
escEnabled,
escFactor,
escFormula,
escMultipliers,
escMaxTime,
escRndTime,
escOverallJails,
jail.ban_time,
jail.find_time,
jail.max_retry,
@@ -459,6 +487,77 @@ function JailAccordionPanel({
</div>
</Field>
)}
{/* Ban-time Escalation */}
<div style={{ marginTop: tokens.spacingVerticalM }}>
<Text weight="semibold" size={400} block>
Ban-time Escalation
</Text>
<Switch
label="Enable incremental banning"
checked={escEnabled}
onChange={(_e, d) => {
setEscEnabled(d.checked);
}}
/>
{escEnabled && (
<div>
<div className={styles.fieldRowThree}>
<Field label="Factor">
<Input
type="number"
value={escFactor}
onChange={(_e, d) => {
setEscFactor(d.value);
}}
/>
</Field>
<Field label="Max Time (s)">
<Input
type="number"
value={escMaxTime}
onChange={(_e, d) => {
setEscMaxTime(d.value);
}}
/>
</Field>
<Field label="Random Jitter (s)">
<Input
type="number"
value={escRndTime}
onChange={(_e, d) => {
setEscRndTime(d.value);
}}
/>
</Field>
</div>
<Field label="Formula">
<Input
value={escFormula}
onChange={(_e, d) => {
setEscFormula(d.value);
}}
/>
</Field>
<Field label="Multipliers (space-separated)">
<Input
value={escMultipliers}
onChange={(_e, d) => {
setEscMultipliers(d.value);
}}
/>
</Field>
<Switch
label="Count repeat offences across all jails"
checked={escOverallJails}
onChange={(_e, d) => {
setEscOverallJails(d.checked);
}}
/>
</div>
)}
</div>
<div className={styles.buttonRow}>
<Button
appearance="primary"

View File

@@ -377,6 +377,61 @@ function PatternsSection({ jail }: { jail: Jail }): React.JSX.Element {
);
}
// ---------------------------------------------------------------------------
// Sub-component: Ban-time escalation section
// ---------------------------------------------------------------------------
function BantimeEscalationSection({ jail }: { jail: Jail }): React.JSX.Element | null {
const styles = useStyles();
const esc = jail.bantime_escalation;
if (!esc?.increment) return null;
return (
<div className={styles.section}>
<div className={styles.sectionHeader}>
<Text as="h2" size={500} weight="semibold">
Ban-time Escalation
</Text>
<Badge appearance="filled" color="informative">enabled</Badge>
</div>
<div className={styles.grid}>
{esc.factor !== null && (
<>
<Text className={styles.label}>Factor:</Text>
<Text className={styles.mono}>{String(esc.factor)}</Text>
</>
)}
{esc.formula && (
<>
<Text className={styles.label}>Formula:</Text>
<Text className={styles.mono}>{esc.formula}</Text>
</>
)}
{esc.multipliers && (
<>
<Text className={styles.label}>Multipliers:</Text>
<Text className={styles.mono}>{esc.multipliers}</Text>
</>
)}
{esc.max_time !== null && (
<>
<Text className={styles.label}>Max time:</Text>
<Text>{fmtSeconds(esc.max_time)}</Text>
</>
)}
{esc.rnd_time !== null && (
<>
<Text className={styles.label}>Random jitter:</Text>
<Text>{fmtSeconds(esc.rnd_time)}</Text>
</>
)}
<Text className={styles.label}>Count across all jails:</Text>
<Text>{esc.overall_jails ? "yes" : "no"}</Text>
</div>
</div>
);
}
// ---------------------------------------------------------------------------
// Sub-component: Ignore list section
// ---------------------------------------------------------------------------
@@ -570,6 +625,7 @@ export function JailDetailPage(): React.JSX.Element {
<JailInfoSection jail={jail} onRefresh={refresh} />
<PatternsSection jail={jail} />
<BantimeEscalationSection jail={jail} />
<IgnoreListSection
jailName={name}
ignoreList={ignoreList}

View File

@@ -2,6 +2,39 @@
* TypeScript interfaces for the configuration and server settings API.
*/
// ---------------------------------------------------------------------------
// Ban-time escalation
// ---------------------------------------------------------------------------
/** Incremental ban-time escalation settings for a jail. */
export interface BantimeEscalation {
/** Whether incremental banning is enabled. */
increment: boolean;
/** Multiplier applied to base ban time on each repeat offence, or null. */
factor: number | null;
/** Python expression for escalated ban time, or null. */
formula: string | null;
/** Space-separated per-offence multipliers, or null. */
multipliers: string | null;
/** Maximum ban duration in seconds, or null (no cap). */
max_time: number | null;
/** Random jitter (seconds) added to escalated ban time, or null. */
rnd_time: number | null;
/** Count repeat offences across all jails, not just the current one. */
overall_jails: boolean;
}
/** Partial update payload for ban-time escalation settings. */
export interface BantimeEscalationUpdate {
increment?: boolean | null;
factor?: number | null;
formula?: string | null;
multipliers?: string | null;
max_time?: number | null;
rnd_time?: number | null;
overall_jails?: boolean | null;
}
// ---------------------------------------------------------------------------
// Jail Configuration
// ---------------------------------------------------------------------------
@@ -18,6 +51,7 @@ export interface JailConfig {
log_encoding: string;
backend: string;
actions: string[];
bantime_escalation: BantimeEscalation | null;
}
export interface JailConfigResponse {
@@ -38,6 +72,7 @@ export interface JailConfigUpdate {
date_pattern?: string | null;
dns_mode?: string | null;
enabled?: boolean | null;
bantime_escalation?: BantimeEscalationUpdate | null;
}
// ---------------------------------------------------------------------------

View File

@@ -7,6 +7,8 @@
* - `backend/app/models/geo.py` (GeoDetail / IpLookupResponse)
*/
import type { BantimeEscalation } from "./config";
// ---------------------------------------------------------------------------
// Jail statistics
// ---------------------------------------------------------------------------
@@ -107,6 +109,8 @@ export interface Jail {
max_retry: number;
/** Live counters, or `null` when not available. */
status: JailStatus | null;
/** Incremental ban-time escalation settings, or `null` if not configured. */
bantime_escalation: BantimeEscalation | null;
}
/**