|
|
|
|
@@ -31,9 +31,9 @@ from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Annotated
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, HTTPException, Path, Request, status
|
|
|
|
|
from fastapi import APIRouter, HTTPException, Path, status
|
|
|
|
|
|
|
|
|
|
from app.dependencies import AuthDep
|
|
|
|
|
from app.dependencies import AuthDep, Fail2BanConfigDirDep
|
|
|
|
|
from app.models.config import (
|
|
|
|
|
ActionConfig,
|
|
|
|
|
ActionConfigUpdate,
|
|
|
|
|
@@ -117,7 +117,7 @@ def _service_unavailable(message: str) -> HTTPException:
|
|
|
|
|
summary="List all jail config files",
|
|
|
|
|
)
|
|
|
|
|
async def list_jail_config_files(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
) -> JailConfigFilesResponse:
|
|
|
|
|
"""Return metadata for every ``.conf`` and ``.local`` file in ``jail.d/``.
|
|
|
|
|
@@ -126,13 +126,12 @@ async def list_jail_config_files(
|
|
|
|
|
file (defaulting to ``true`` when the key is absent).
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
request: Incoming request (used for ``app.state.settings``).
|
|
|
|
|
config_dir: Config directory path injected from application settings.
|
|
|
|
|
_auth: Validated session — enforces authentication.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:class:`~app.models.file_config.JailConfigFilesResponse`.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.list_jail_config_files(config_dir)
|
|
|
|
|
except ConfigDirError as exc:
|
|
|
|
|
@@ -145,7 +144,7 @@ async def list_jail_config_files(
|
|
|
|
|
summary="Return a single jail config file with its content",
|
|
|
|
|
)
|
|
|
|
|
async def get_jail_config_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
filename: _FilenamePath,
|
|
|
|
|
) -> JailConfigFileContent:
|
|
|
|
|
@@ -164,7 +163,6 @@ async def get_jail_config_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_jail_config_file(config_dir, filename)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -181,7 +179,7 @@ async def get_jail_config_file(
|
|
|
|
|
summary="Overwrite a jail.d config file with new raw content",
|
|
|
|
|
)
|
|
|
|
|
async def write_jail_config_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
filename: _FilenamePath,
|
|
|
|
|
body: ConfFileUpdateRequest,
|
|
|
|
|
@@ -202,7 +200,6 @@ async def write_jail_config_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.write_jail_config_file(config_dir, filename, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -221,7 +218,7 @@ async def write_jail_config_file(
|
|
|
|
|
summary="Enable or disable a jail configuration file",
|
|
|
|
|
)
|
|
|
|
|
async def set_jail_config_file_enabled(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
filename: _FilenamePath,
|
|
|
|
|
body: JailConfigFileEnabledUpdate,
|
|
|
|
|
@@ -242,7 +239,6 @@ async def set_jail_config_file_enabled(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.set_jail_config_enabled(
|
|
|
|
|
config_dir, filename, body.enabled
|
|
|
|
|
@@ -264,7 +260,7 @@ async def set_jail_config_file_enabled(
|
|
|
|
|
summary="Create a new jail.d config file",
|
|
|
|
|
)
|
|
|
|
|
async def create_jail_config_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
body: ConfFileCreateRequest,
|
|
|
|
|
) -> ConfFileContent:
|
|
|
|
|
@@ -283,7 +279,6 @@ async def create_jail_config_file(
|
|
|
|
|
HTTPException: 409 if a file with that name already exists.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
filename = await raw_config_io_service.create_jail_config_file(config_dir, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -313,7 +308,7 @@ async def create_jail_config_file(
|
|
|
|
|
summary="Return a filter definition file's raw content",
|
|
|
|
|
)
|
|
|
|
|
async def get_filter_file_raw(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
) -> ConfFileContent:
|
|
|
|
|
@@ -336,7 +331,6 @@ async def get_filter_file_raw(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_filter_file(config_dir, name)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -353,7 +347,7 @@ async def get_filter_file_raw(
|
|
|
|
|
summary="Update a filter definition file (raw content)",
|
|
|
|
|
)
|
|
|
|
|
async def write_filter_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
body: ConfFileUpdateRequest,
|
|
|
|
|
@@ -371,7 +365,6 @@ async def write_filter_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.write_filter_file(config_dir, name, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -391,7 +384,7 @@ async def write_filter_file(
|
|
|
|
|
summary="Create a new filter definition file (raw content)",
|
|
|
|
|
)
|
|
|
|
|
async def create_filter_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
body: ConfFileCreateRequest,
|
|
|
|
|
) -> ConfFileContent:
|
|
|
|
|
@@ -410,7 +403,6 @@ async def create_filter_file(
|
|
|
|
|
HTTPException: 409 if a file with that name already exists.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
filename = await raw_config_io_service.create_filter_file(config_dir, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -440,7 +432,7 @@ async def create_filter_file(
|
|
|
|
|
summary="List all action definition files",
|
|
|
|
|
)
|
|
|
|
|
async def list_action_files(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
) -> ConfFilesResponse:
|
|
|
|
|
"""Return a list of every ``.conf`` and ``.local`` file in ``action.d/``.
|
|
|
|
|
@@ -452,7 +444,6 @@ async def list_action_files(
|
|
|
|
|
Returns:
|
|
|
|
|
:class:`~app.models.file_config.ConfFilesResponse`.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.list_action_files(config_dir)
|
|
|
|
|
except ConfigDirError as exc:
|
|
|
|
|
@@ -465,7 +456,7 @@ async def list_action_files(
|
|
|
|
|
summary="Return an action definition file with its content",
|
|
|
|
|
)
|
|
|
|
|
async def get_action_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
) -> ConfFileContent:
|
|
|
|
|
@@ -484,7 +475,6 @@ async def get_action_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_action_file(config_dir, name)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -501,7 +491,7 @@ async def get_action_file(
|
|
|
|
|
summary="Update an action definition file",
|
|
|
|
|
)
|
|
|
|
|
async def write_action_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
body: ConfFileUpdateRequest,
|
|
|
|
|
@@ -519,7 +509,6 @@ async def write_action_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.write_action_file(config_dir, name, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -539,7 +528,7 @@ async def write_action_file(
|
|
|
|
|
summary="Create a new action definition file",
|
|
|
|
|
)
|
|
|
|
|
async def create_action_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
body: ConfFileCreateRequest,
|
|
|
|
|
) -> ConfFileContent:
|
|
|
|
|
@@ -558,7 +547,6 @@ async def create_action_file(
|
|
|
|
|
HTTPException: 409 if a file with that name already exists.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
filename = await raw_config_io_service.create_action_file(config_dir, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -588,7 +576,7 @@ async def create_action_file(
|
|
|
|
|
summary="Return a filter file parsed into a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def get_parsed_filter(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
) -> FilterConfig:
|
|
|
|
|
@@ -611,7 +599,6 @@ async def get_parsed_filter(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_parsed_filter_file(config_dir, name)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -628,7 +615,7 @@ async def get_parsed_filter(
|
|
|
|
|
summary="Update a filter file from a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def update_parsed_filter(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
body: FilterConfigUpdate,
|
|
|
|
|
@@ -649,7 +636,6 @@ async def update_parsed_filter(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.update_parsed_filter_file(config_dir, name, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -673,7 +659,7 @@ async def update_parsed_filter(
|
|
|
|
|
summary="Return an action file parsed into a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def get_parsed_action(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
) -> ActionConfig:
|
|
|
|
|
@@ -696,7 +682,6 @@ async def get_parsed_action(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_parsed_action_file(config_dir, name)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -713,7 +698,7 @@ async def get_parsed_action(
|
|
|
|
|
summary="Update an action file from a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def update_parsed_action(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
name: _NamePath,
|
|
|
|
|
body: ActionConfigUpdate,
|
|
|
|
|
@@ -734,7 +719,6 @@ async def update_parsed_action(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.update_parsed_action_file(config_dir, name, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -758,7 +742,7 @@ async def update_parsed_action(
|
|
|
|
|
summary="Return a jail.d file parsed into a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def get_parsed_jail_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
filename: _NamePath,
|
|
|
|
|
) -> JailFileConfig:
|
|
|
|
|
@@ -781,7 +765,6 @@ async def get_parsed_jail_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
return await raw_config_io_service.get_parsed_jail_file(config_dir, filename)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
@@ -798,7 +781,7 @@ async def get_parsed_jail_file(
|
|
|
|
|
summary="Update a jail.d file from a structured model",
|
|
|
|
|
)
|
|
|
|
|
async def update_parsed_jail_file(
|
|
|
|
|
request: Request,
|
|
|
|
|
config_dir: Fail2BanConfigDirDep,
|
|
|
|
|
_auth: AuthDep,
|
|
|
|
|
filename: _NamePath,
|
|
|
|
|
body: JailFileConfigUpdate,
|
|
|
|
|
@@ -819,7 +802,6 @@ async def update_parsed_jail_file(
|
|
|
|
|
HTTPException: 404 if the file does not exist.
|
|
|
|
|
HTTPException: 503 if the config directory is unavailable.
|
|
|
|
|
"""
|
|
|
|
|
config_dir: str = request.app.state.settings.fail2ban_config_dir
|
|
|
|
|
try:
|
|
|
|
|
await raw_config_io_service.update_parsed_jail_file(config_dir, filename, body)
|
|
|
|
|
except ConfigFileNameError as exc:
|
|
|
|
|
|