Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions nettacker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

CWD = Path.cwd()
PACKAGE_PATH = Path(__file__).parent
ROOT_PATH = Path(__file__).parent.parent


@lru_cache(maxsize=128)
Expand Down Expand Up @@ -114,19 +115,19 @@ class PathConfig:
a JSON contain the working, tmp and results path
"""

data_dir = CWD / ".nettacker/data"
new_database_file = CWD / ".nettacker/data/nettacker.db"
old_database_file = CWD / ".data/nettacker.db"
data_dir = ROOT_PATH / ".nettacker/data"
new_database_file = ROOT_PATH / ".nettacker/data/nettacker.db"
old_database_file = ROOT_PATH / ".data/nettacker.db"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Base-path drift: PathConfig moved to ROOT_PATH, but DbConfig and ApiConfig still use CWD — likely producing multiple DB/log locations.

  • Line 102 still points DB to CWD/.nettacker/data/nettacker.db while Lines 118–120 point “new_database_file” to ROOT_PATH/.... You can end up creating/migrating to one path and reading from another.
  • Line 66 keeps logs under CWD/.nettacker, while Lines 129–131 relocate results/tmp under ROOT_PATH/....
  • Migration path (Line 120 “old_database_file”) won’t find legacy DBs if they were previously under CWD.

Action: unify all runtime paths through one base (the fixed ROOT_PATH above or revert these changes). For example:

# outside-diff illustration:
ApiConfig.api_access_log = str(PathConfig.data_dir / "nettacker.log")
DbConfig.name = str(PathConfig.new_database_file)

Also ensure directories exist before use:

# outside-diff illustration:
for d in (PathConfig.data_dir, PathConfig.results_dir, PathConfig.tmp_dir):
    d.mkdir(parents=True, exist_ok=True)

To locate other hard-coded CWD usages:

Also applies to: 122-122, 129-131


🏁 Script executed:

#!/bin/bash
rg -nP 'Path\.cwd\(\)|\bCWD\b|\.nettacker\/data' -g '!**/tests/**'

Length of output: 3471


Unify all Nettacker runtime paths to ROOT_PATH
Replace every CWD / ".nettacker/data/…" usage in nettacker/config.py (lines 66 & 102) with the corresponding PathConfig.* under ROOT_PATH. Ensure the following are consistent:

  • api_access_log → PathConfig.data_dir / "nettacker.log"
  • name (DB) → PathConfig.new_database_file
  • old_database_file (if migrating legacy DBs) points to the previous CWD location (CWD / ".nettacker/data/nettacker.db")
  • results_dir → PathConfig.results_dir
  • tmp_dir → PathConfig.tmp_dir

Also ensure all target directories exist before use:

for d in (PathConfig.data_dir, PathConfig.results_dir, PathConfig.tmp_dir):
    d.mkdir(parents=True, exist_ok=True)
🤖 Prompt for AI Agents
In nettacker/config.py around lines 66, 102 and 118-120, replace any use of CWD
/ ".nettacker/data/…" with the corresponding PathConfig properties under
ROOT_PATH: set api_access_log to PathConfig.data_dir / "nettacker.log", set the
DB name to PathConfig.new_database_file, set old_database_file to the legacy CWD
/ ".nettacker/data/nettacker.db" for migration, and point results_dir and
tmp_dir to PathConfig.results_dir and PathConfig.tmp_dir respectively; finally
ensure the three runtime directories exist by creating PathConfig.data_dir,
PathConfig.results_dir and PathConfig.tmp_dir with mkdir(parents=True,
exist_ok=True) before they are used.

graph_dir = PACKAGE_PATH / "lib/graph"
home_dir = CWD
home_dir = ROOT_PATH
locale_dir = PACKAGE_PATH / "locale"
logo_file = PACKAGE_PATH / "logo.txt"
module_protocols_dir = PACKAGE_PATH / "core/lib"
modules_dir = PACKAGE_PATH / "modules"
payloads_dir = PACKAGE_PATH / "lib/payloads"
release_name_file = PACKAGE_PATH / "release_name.txt"
results_dir = CWD / ".nettacker/data/results"
tmp_dir = CWD / ".nettacker/data/tmp"
results_dir = ROOT_PATH / ".nettacker/data/results"
tmp_dir = ROOT_PATH / ".nettacker/data/tmp"
web_static_dir = PACKAGE_PATH / "web/static"
user_agents_file = PACKAGE_PATH / "lib/payloads/User-Agents/web_browsers_user_agents.txt"

Expand Down
Loading
Loading