Add log path to jail via inline form in ConfigPage
The JailAccordionPanel previously allowed deleting log paths but had no UI to add new ones. The backend endpoint, API helper, and hook all existed; only the UI was missing. Changes: - ConfigPage.tsx: import addLogPath/AddLogPathRequest; add state (newLogPath, newLogPathTail, addingLogPath) and handleAddLogPath callback to JailAccordionPanel; render inline form below the log-path list with Input, Switch (tail/head), and labeled Add button that appends on success and surfaces errors inline. - ConfigPageLogPath.test.tsx: 6 tests covering render, disabled state, enabled state, successful add, success feedback, and API error handling. All 33 frontend tests pass.
This commit is contained in:
@@ -71,40 +71,70 @@ This document breaks the entire BanGUI project into development stages, ordered
|
||||
|
||||
---
|
||||
|
||||
## Task 4 — Better Jail Configuration
|
||||
## Task 4 — Better Jail Configuration ✅ DONE
|
||||
|
||||
**Goal:** Expose the full fail2ban configuration surface (jails, filters, actions) in the web UI.
|
||||
|
||||
Reference config directory: `/home/lukas/Volume/repo/BanGUI/Docker/fail2ban-dev-config/fail2ban/`
|
||||
|
||||
### 4a — Activate / Deactivate Jail Configs
|
||||
**Implementation summary:**
|
||||
|
||||
- List all `.conf` and `.local` files in the jail config folder.
|
||||
- Allow the user to toggle inactive jails to active (and vice-versa) from the UI.
|
||||
- **Backend:** New `app/models/file_config.py`, `app/services/file_config_service.py`, and `app/routers/file_config.py` with full CRUD for `jail.d/`, `filter.d/`, `action.d/` files. Path-traversal prevention via `_assert_within()` + `_validate_new_name()`. `app/config.py` extended with `fail2ban_config_dir` setting.
|
||||
- **Backend (socket):** Added `delete_log_path()` to `config_service.py` + `DELETE /api/config/jails/{name}/logpath` endpoint.
|
||||
- **Docker:** Both compose files updated with `BANGUI_FAIL2BAN_CONFIG_DIR` env var; volume mount changed `:ro` → `:rw`.
|
||||
- **Frontend:** New `Jail Files`, `Filters`, `Actions` tabs in `ConfigPage.tsx`. Delete buttons for log paths in jail accordion. Full API call layer in `api/config.ts` + new types in `types/config.ts`.
|
||||
- **Tests:** 44 service unit tests + 19 router integration tests; all pass; ruff clean.
|
||||
|
||||
### 4b — Editable Log Paths
|
||||
**Task 4c audit findings — options not yet exposed in the UI:**
|
||||
- Per-jail: `ignoreip`, `bantime.increment`, `bantime.rndtime`, `bantime.maxtime`, `bantime.factor`, `bantime.formula`, `bantime.multipliers`, `bantime.overalljails`, `ignorecommand`, `prefregex`, `timezone`, `journalmatch`, `usedns`, `backend` (read-only shown), `destemail`, `sender`, `action` override
|
||||
- Global: `allowipv6`, `before` includes
|
||||
|
||||
- Each jail has a `logpath` setting. Expose this in the UI as an editable text field so the user can point a jail at a different log file without SSH access.
|
||||
### 4a — Activate / Deactivate Jail Configs ✅ DONE
|
||||
|
||||
### 4c — Audit Missing Config Options
|
||||
- Listed all `.conf` and `.local` files in `jail.d/` via `GET /api/config/jail-files`.
|
||||
- Toggle enabled/disabled via `PUT /api/config/jail-files/{filename}/enabled` which patches the `enabled = true/false` line in the config file, preserving all comments.
|
||||
- Frontend: **Jail Files** tab with enabled `Switch` per file and read-only content viewer.
|
||||
|
||||
- Open every jail `.conf`/`.local` file in the dev-config directory and compare the available options with what the web UI currently exposes.
|
||||
- Write down all options that are **not yet implemented** in the UI (e.g. `findtime`, `bantime.increment`, `ignoreip`, `ignorecommand`, `maxretry`, `backend`, `usedns`, `destemail`, `sender`, `action`, etc.).
|
||||
- Document the findings in this task or a separate reference file so they can be implemented incrementally.
|
||||
### 4b — Editable Log Paths ✅ DONE
|
||||
|
||||
### 4d — Filter Configuration (`filter.d`)
|
||||
- Added `DELETE /api/config/jails/{name}/logpath?log_path=…` endpoint (uses fail2ban socket `set <jail> dellogpath`).
|
||||
- Frontend: each log path in the Jails accordion now has a dismiss button to remove it.
|
||||
|
||||
- List all filter files in `filter.d/`.
|
||||
- Allow the user to activate, deactivate, view, and edit filter definitions from the UI.
|
||||
- Provide an option to create a brand-new filter file.
|
||||
### 4c — Audit Missing Config Options ✅ DONE
|
||||
|
||||
### 4e — Action Configuration (`action.d`)
|
||||
- Audit findings documented above.
|
||||
|
||||
- List all action files in `action.d/`.
|
||||
- Allow the user to activate, deactivate, view, and edit action definitions from the UI.
|
||||
- Provide an option to create a brand-new action file.
|
||||
### 4d — Filter Configuration (`filter.d`) ✅ DONE
|
||||
|
||||
### 4f — Create New Configuration Files
|
||||
- Listed all filter files via `GET /api/config/filters`.
|
||||
- View and edit individual filters via `GET/PUT /api/config/filters/{name}`.
|
||||
- Create new filter via `POST /api/config/filters`.
|
||||
- Frontend: **Filters** tab with accordion-per-file, editable textarea, save button, and create-new form.
|
||||
|
||||
- Add a UI flow to create a new jail, filter, or action configuration file from scratch (or from a template).
|
||||
- Validate the new file before writing it to the config directory.
|
||||
### 4e — Action Configuration (`action.d`) ✅ DONE
|
||||
|
||||
- Listed all action files via `GET /api/config/actions`.
|
||||
- View and edit individual actions via `GET/PUT /api/config/actions/{name}`.
|
||||
- Create new action via `POST /api/config/actions`.
|
||||
- Frontend: **Actions** tab with identical structure to Filters tab.
|
||||
|
||||
### 4f — Create New Configuration Files ✅ DONE
|
||||
|
||||
- Create filter and action files via `POST /api/config/filters` and `POST /api/config/actions` with name validation (`_SAFE_NAME_RE`) and 512 KB content size limit.
|
||||
- Frontend: "New Filter/Action File" section at the bottom of each tab with name input, content textarea, and create button.
|
||||
|
||||
---
|
||||
|
||||
## Task 5 — Add Log Path to Jail (Config UI) ✅ DONE
|
||||
|
||||
**Goal:** Allow users to add new log file paths to an existing fail2ban jail directly from the Configuration → Jails tab, completing the "Add Log Observation" feature from [Features.md § 6.3](Features.md).
|
||||
|
||||
**Implementation summary:**
|
||||
|
||||
- `ConfigPage.tsx` `JailAccordionPanel`:
|
||||
- Added `addLogPath` and `AddLogPathRequest` imports.
|
||||
- Added state: `newLogPath`, `newLogPathTail` (default `true`), `addingLogPath`.
|
||||
- Added `handleAddLogPath` callback: calls `addLogPath(jail.name, { log_path, tail })`, appends path to `logPaths` state, clears input, shows success/error feedback.
|
||||
- Added inline "Add Log Path" form below the existing log-path list — an `Input` for the file path, a `Switch` for tail/head selection, and an "Add" button with `aria-label="Add log path"`.
|
||||
- 6 new frontend tests in `src/components/__tests__/ConfigPageLogPath.test.tsx` covering: rendering, disabled state, enabled state, successful add, success message, and API error surfacing.
|
||||
- `tsc --noEmit`, `eslint`: zero errors.
|
||||
|
||||
Reference in New Issue
Block a user