Skip to content

Refactor: Fix bugs, improve path handling and UI consistency#2

Open
MohakGrover wants to merge 1 commit intoCodingRanjith:mainfrom
MohakGrover:refactor-improvements
Open

Refactor: Fix bugs, improve path handling and UI consistency#2
MohakGrover wants to merge 1 commit intoCodingRanjith:mainfrom
MohakGrover:refactor-improvements

Conversation

@MohakGrover
Copy link
Copy Markdown

Overview
This PR introduces a significant refactor to the core logic and entry point of the cybersec tool. The primary goals were to resolve permission issues caused by hardcoded paths, fix UI inconsistencies, prevent potential crashes in long sessions, and improve cross-platform compatibility.

Key Changes & Improvements

  1. Reliable Path Management (Infrastructure)

Old Behavior: Hardcoded to /home/cybersec.txt and /home/cybersec. This restricted the tool to Linux systems and required root/sudo permissions for basic setup.
New Behavior: Now uses os.path.expanduser("~") to dynamically locate the user's home directory. This allows the tool to run on any OS and avoids permission errors by storing configurations in ~/.cybersec_path.txt and tools in ~/cybersec (by default).
2. Iterative Navigation System (Core Logic)

Old Behavior: The menu system used recursion (show_options calling itself). In deep or long-running navigation, this could lead to a RecursionError (Stack Overflow).
New Behavior: Rewrote the menu system using while True loops. This ensures the tool remains stable regardless of how long the user stays in the menus and simplifies the flow of "Back" navigation.
3. Graceful Dependency Handling

Issue: The tool relied heavily on external binaries like figlet, lolcat, and boxes. If these were missing, the tool would either crash, show command not found errors, or look broken.
Solution: Added a check_dependency utility using shutil.which. The tool now checks for these utilities before attempting to use them and automatically falls back to clean, standard text if they aren't available.
4. UI Bug Fixes & Consistency

Fixed Formatting: Resolved a missing closing bracket ] in the tool collection listing that caused misaligned displays.
Unified Indexing: Previously, some menus used 0-based indexing while others used 1-based. All menus have been unified to 1-based indexing for a consistent user experience.
5. Enhanced Cross-Platform Support

Old Behavior: Immediately quit and opened a browser tab if run on Windows.
New Behavior: Now detects Windows and provides a clear warning that some tools are Linux-specific, but allows the user to explore the menu system and use any platform-agnostic collection tools.
6. Repository Cleanliness

Renamed requirement.txt to requirements.txt to comply with standard Python packaging practices.
Technical Notes
Files touched: core.py, cybersec.py, requirements.txt.
Logic in cybersec.py was reorganized to be more linear and easier to maintain.
Used os.path.join and os.path.abspath for robust file handling across different environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant