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
+9
-10
@@ -13,17 +13,17 @@ import os
|
||||
import re
|
||||
|
||||
from .analyzer import Analyzer
|
||||
from .constants import (
|
||||
COPYPARTY_LOG_PATH,
|
||||
COPYPARTY_REPORT_DIR,
|
||||
DEFAULT_MIN_DENIED,
|
||||
)
|
||||
from .ip_utils import split_versions
|
||||
from .files import write_json, write_lines
|
||||
from .flags import flag_denied_only
|
||||
from .models import IPStats, Request
|
||||
from .utils import arg_parser
|
||||
|
||||
|
||||
DEFAULT_LOG_PATH = os.environ.get("COPYPARTY_LOG_PATH", r"P:\copyparty")
|
||||
DEFAULT_REPORT_DIR = os.path.join(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "reports", "copyparty")
|
||||
|
||||
# "HH:MM:SS.mmm <ip> <port> LEVEL: message"
|
||||
# System lines ("hsrv", "root", ...) have no port and are skipped.
|
||||
LINE_RE = re.compile(
|
||||
@@ -76,7 +76,7 @@ class CopypartyAnalyzer(Analyzer):
|
||||
("ban_secs", lambda r: r.extra.get("ban_secs")),
|
||||
)
|
||||
|
||||
def __init__(self, *args, min_denied: int = 1, **kwargs):
|
||||
def __init__(self, *args, min_denied: int = DEFAULT_MIN_DENIED, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.min_denied = min_denied
|
||||
|
||||
@@ -161,9 +161,9 @@ class CopypartyAnalyzer(Analyzer):
|
||||
def main() -> None:
|
||||
parser = arg_parser(
|
||||
"analyze copyparty logs, flag denied-only IPs, export MikroTik rules",
|
||||
DEFAULT_LOG_PATH, DEFAULT_REPORT_DIR)
|
||||
parser.add_argument("--min-denied", type=int, default=1,
|
||||
help="minimum denied hits before flagging (default: 1)")
|
||||
COPYPARTY_LOG_PATH, COPYPARTY_REPORT_DIR)
|
||||
parser.add_argument("--min-denied", type=int, default=DEFAULT_MIN_DENIED,
|
||||
help=f"minimum denied hits before flagging (default: {DEFAULT_MIN_DENIED})")
|
||||
args = parser.parse_args()
|
||||
|
||||
CopypartyAnalyzer(
|
||||
@@ -171,7 +171,6 @@ def main() -> None:
|
||||
report_dir=args.report_dir,
|
||||
top=args.top,
|
||||
quiet=args.quiet,
|
||||
write_rsc=not args.no_rsc,
|
||||
min_denied=args.min_denied,
|
||||
).run()
|
||||
|
||||
|
||||
Reference in new issue
Block a user