Expose usedns, date_pattern, and prefregex in jail config UI
- Add use_dns and prefregex fields to JailConfig model (backend + frontend types) - Add prefregex to JailConfigUpdate; validate as regex before writing - Fetch usedns and prefregex in get_jail_config via asyncio.gather - Write usedns and prefregex in update_jail_config - ConfigPage JailAccordionPanel: editable date_pattern input, dns_mode Select dropdown (yes/warn/no/raw), and prefregex input - 8 new service unit tests + 3 new router integration tests - 628 tests pass; 85% line coverage; ruff/mypy/tsc/eslint clean
This commit is contained in:
@@ -190,3 +190,73 @@ Reference config directory: `/home/lukas/Volume/repo/BanGUI/Docker/fail2ban-dev-
|
||||
- Backend: router integration tests in `test_config.py` verifying the escalation round-trip.
|
||||
- Frontend: update `ConfigPageLogPath.test.tsx` mock `JailConfig` to include `bantime_escalation: null`.
|
||||
|
||||
---
|
||||
|
||||
## Task 7 — Expose Remaining Per-Jail Config Fields (usedns, date_pattern, prefregex) ✅ DONE
|
||||
|
||||
**Goal:** Surface the three remaining per-jail configuration fields — DNS look-up mode (`usedns`), custom date pattern (`datepattern`), and prefix regex (`prefregex`) — in both the backend API response model and the Configuration → Jails UI, completing the editable jail config surface defined in [Features.md § 6](Features.md).
|
||||
|
||||
**Implementation summary:**
|
||||
|
||||
- **Backend model** (`app/models/config.py`):
|
||||
- Added `use_dns: str` (default `"warn"`) and `prefregex: str` (default `""`) to `JailConfig`.
|
||||
- Added `prefregex: str | None` to `JailConfigUpdate` (`None` = skip, `""` = clear, non-empty = set).
|
||||
- **Backend service** (`app/services/config_service.py`):
|
||||
- Added `get <jail> usedns` and `get <jail> prefregex` to the `asyncio.gather()` block in `get_jail_config()`.
|
||||
- Populated `use_dns` and `prefregex` on the returned `JailConfig`.
|
||||
- Added `prefregex` validation (regex compile-check) and `set <jail> prefregex` write in `update_jail_config()`.
|
||||
- **Frontend types** (`types/config.ts`):
|
||||
- Added `use_dns: string` and `prefregex: string` to `JailConfig`.
|
||||
- Added `prefregex?: string | null` to `JailConfigUpdate`.
|
||||
- **Frontend ConfigPage** (`ConfigPage.tsx` `JailAccordionPanel`):
|
||||
- Added state and editable `Input` for `date_pattern` (hints "Leave blank for auto-detect").
|
||||
- Added state and `Select` dropdown for `dns_mode` with options yes / warn / no / raw.
|
||||
- Added state and editable `Input` for `prefregex` (hints "Leave blank to disable").
|
||||
- All three included in `handleSave()` update payload.
|
||||
- **Tests**: 8 new service unit tests + 3 new router integration tests; `ConfigPageLogPath.test.tsx` mock updated; 628 tests pass; 85% coverage; ruff + mypy + tsc + eslint clean.
|
||||
|
||||
**Goal:** Surface the three remaining per-jail configuration fields — DNS look-up mode (`usedns`), custom date pattern (`datepattern`), and prefix regex (`prefregex`) — in both the backend API response model and the Configuration → Jails UI, completing the editable jail config surface defined in [Features.md § 6](Features.md).
|
||||
|
||||
**Background:** Task 4c audit found several options not yet exposed in the UI. Task 6 covered ban-time escalation. This task covers the three remaining fields that are most commonly changed through the fail2ban configuration:
|
||||
- `usedns` — controls whether fail2ban resolves hostnames ("yes" / "warn" / "no" / "raw").
|
||||
- `datepattern` — custom date format for log parsing; empty / unset means fail2ban auto-detects.
|
||||
- `prefregex` — a prefix regex prepended to every `failregex` for pre-filtering log lines; empty means disabled.
|
||||
|
||||
**Tasks:**
|
||||
|
||||
### 7a — Backend: Add `use_dns` and `prefregex` to `JailConfig` model
|
||||
|
||||
- Add `use_dns: str` field to `JailConfig` in `app/models/config.py` (default `"warn"`).
|
||||
- Add `prefregex: str` field to `JailConfig` (default `""`; empty string means not set).
|
||||
- Add `prefregex: str | None` to `JailConfigUpdate` (`None` = skip, `""` = clear, non-empty = set).
|
||||
|
||||
### 7b — Backend: Read `usedns` and `prefregex` from fail2ban socket
|
||||
|
||||
- In `config_service.get_jail_config()`: add `get <jail> usedns` and `get <jail> prefregex` to the existing `asyncio.gather()` block.
|
||||
- Populate `use_dns` and `prefregex` on the returned `JailConfig`.
|
||||
|
||||
### 7c — Backend: Write `prefregex` to fail2ban socket
|
||||
|
||||
- In `config_service.update_jail_config()`: validate `prefregex` with `_validate_regex` if non-empty, then `set <jail> prefregex <value>` when `JailConfigUpdate.prefregex is not None`.
|
||||
|
||||
### 7d — Frontend: Update types
|
||||
|
||||
- `types/config.ts`: add `use_dns: string` and `prefregex: string` to `JailConfig`.
|
||||
- `types/config.ts`: add `prefregex?: string | null` to `JailConfigUpdate`.
|
||||
|
||||
### 7e — Frontend: Edit `date_pattern`, `use_dns`, and `prefregex` in ConfigPage
|
||||
|
||||
- In `ConfigPage.tsx` `JailAccordionPanel`, add:
|
||||
- Text input for `date_pattern` (empty = auto-detect; non-empty value is sent as-is).
|
||||
- `Select` dropdown for `use_dns` with options "yes" / "warn" / "no" / "raw".
|
||||
- Text input for `prefregex` (empty = not set / cleared).
|
||||
- All three are included in the `handleSave()` update payload.
|
||||
|
||||
### 7f — Tests
|
||||
|
||||
- Backend: add `usedns` and `prefregex` entries to `_DEFAULT_JAIL_RESPONSES` in `test_config_service.py`.
|
||||
- Backend: add unit tests verifying new fields are fetched and `prefregex` is written via `update_jail_config()`.
|
||||
- Backend: update `_make_jail_config()` in `test_config.py` to include `use_dns` and `prefregex`.
|
||||
- Backend: add router integration tests for the new update fields.
|
||||
- Frontend: update `ConfigPageLogPath.test.tsx` mock `JailConfig` to include `use_dns` and `prefregex`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user