Add centralized constants module and .env configuration support
This commit is contained in:
1 parent
94be1da199
commit
eea5ef6885
14 files changed
+334
-126
No files matched your search
+4
-3
@@ -7,11 +7,12 @@ Detection functions that identify hostile IPs based on aggregated stats.
|
||||
from __future__ import annotations
|
||||
|
||||
from . import bad_patterns
|
||||
from .constants import DEFAULT_ERROR_RATIO, DEFAULT_MIN_DENIED, DEFAULT_MIN_ERRORS
|
||||
from .models import IPStats
|
||||
|
||||
|
||||
def flag_scanners(stats: dict[str, IPStats], min_errors: int = 5,
|
||||
min_ratio: float = 0.5) -> dict[str, IPStats]:
|
||||
def flag_scanners(stats: dict[str, IPStats], min_errors: int = DEFAULT_MIN_ERRORS,
|
||||
min_ratio: float = DEFAULT_ERROR_RATIO) -> dict[str, IPStats]:
|
||||
"""IPs with many errors AND a high error ratio."""
|
||||
return {
|
||||
ip: s for ip, s in stats.items()
|
||||
@@ -20,7 +21,7 @@ def flag_scanners(stats: dict[str, IPStats], min_errors: int = 5,
|
||||
|
||||
|
||||
def flag_denied_only(stats: dict[str, IPStats],
|
||||
min_denied: int = 1) -> dict[str, IPStats]:
|
||||
min_denied: int = DEFAULT_MIN_DENIED) -> dict[str, IPStats]:
|
||||
"""IPs that only ever hit denied paths and never authenticated."""
|
||||
return {
|
||||
ip: s for ip, s in stats.items()
|
||||
|
||||
Reference in new issue
Block a user