Skip to content

Commit bb0b360

Browse files
committed
updated the pdoc documentation
1 parent 721a89e commit bb0b360

35 files changed

Lines changed: 1684 additions & 2 deletions

docs/pdoc/html/ctfsolver/forensics/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<main>
3434
<article id="content">
3535
<header>
36-
<h1 class="title">Namespace <code>ctfsolver.forensics</code></h1>
36+
<h1 class="title">Module <code>ctfsolver.forensics</code></h1>
3737
</header>
3838
<section id="section-intro">
3939
</section>

docs/pdoc/html/ctfsolver/src/data/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<main>
3434
<article id="content">
3535
<header>
36-
<h1 class="title">Namespace <code>ctfsolver.src.data</code></h1>
36+
<h1 class="title">Module <code>ctfsolver.src.data</code></h1>
3737
</header>
3838
<section id="section-intro">
3939
</section>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
Module ctfsolver.config.global_config
2+
=====================================
3+
Global configuration management for the CTFSolverScript package.
4+
5+
This module provides the `GlobalConfig` class, which handles the creation, initialization,
6+
and access of a global configuration file stored in the user's home directory. The configuration
7+
file is used to store persistent settings required by the CTFSolverScript inline tool.
8+
9+
Classes:
10+
GlobalConfig: Manages the global configuration file, including creation, initialization,
11+
reading, and attribute/dictionary-style access to configuration values.
12+
13+
Attributes:
14+
CONFIG (GlobalConfig): Singleton instance of the GlobalConfig class for global access.
15+
16+
Example:
17+
>>> from ctfsolver.config.global_config import CONFIG
18+
>>> from ctfsolver.config import CONFIG
19+
>>> CONFIG.initializing() # Initializes the global configuration
20+
21+
Typical usage involves initializing the configuration (creating the file and writing initial
22+
content if necessary) and accessing configuration values via attribute or dictionary-style access.
23+
24+
Raises:
25+
AttributeError: If an attribute is accessed that does not exist in the configuration.
26+
KeyError: If a key is accessed that does not exist in the configuration.
27+
28+
Classes
29+
-------
30+
31+
`GlobalConfig(*args, **kwargs)`
32+
: Initializes the global configuration for the CTF solver application.
33+
This constructor sets the path to the global configuration file and loads its content.
34+
35+
Attributes:
36+
global_config_file_path (Path): Path to the global configuration JSON file.
37+
38+
Raises:
39+
Any exceptions raised by `get_content()` will propagate.
40+
41+
### Methods
42+
43+
`creating(self)`
44+
: Creates a global configuration file in the user's home directory.
45+
46+
This method ensures that the required directories and configuration file exist,
47+
creating them if necessary. It is typically called during the initial run of the
48+
inline tool or when global configuration setup is required.
49+
50+
Args:
51+
None
52+
53+
Returns:
54+
None
55+
56+
Raises:
57+
OSError: If the directory or file cannot be created due to permission issues.
58+
59+
`get_content(self)`
60+
: Get the content of the global configuration file.
61+
This method reads the global configuration file and returns its content
62+
as a dictionary.
63+
If the file does not exist or is empty, it returns an empty dictionary.
64+
It is intended to be used to retrieve the current global configuration
65+
settings for use in the inline tool or other parts of the application.
66+
67+
68+
Returns:
69+
dict: The content of the global configuration file as a dictionary.
70+
71+
`initial_content(self)`
72+
: Sets the initial content of the global configuration file.
73+
74+
This method loads a configuration template from 'config_template.json' and writes it to the global
75+
configuration file if the file is empty or does not exist. If the template file is missing, a default
76+
initial content is used instead.
77+
78+
Args:
79+
None
80+
81+
Returns:
82+
None
83+
84+
Raises:
85+
FileNotFoundError: If the template file or global configuration file path does not exist.
86+
json.JSONDecodeError: If the template file contains invalid JSON.
87+
88+
Side Effects:
89+
Writes initial configuration content to the global configuration file if it is empty.
90+
Prints status messages to the console.
91+
92+
`initializing(self)`
93+
: Initialize global configuration settings.
94+
This method can be used to set up any necessary global configurations
95+
required by the inline tool.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Module ctfsolver.config
2+
=======================
3+
4+
Sub-modules
5+
-----------
6+
* ctfsolver.config.global_config
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Module ctfsolver.error
2+
======================
3+
4+
Sub-modules
5+
-----------
6+
* ctfsolver.error.manager_error
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Module ctfsolver.error.manager_error
2+
====================================
3+
manager_error.py
4+
5+
Provides the ManagerError class for handling exceptions with colored output and optional verbose tracebacks.
6+
7+
Classes:
8+
ManagerError: Handles exceptions by printing colored error messages or full tracebacks, and provides a utility to wrap function execution with error handling.
9+
10+
Usage:
11+
Use ManagerError to manage error reporting in CLI applications, with support for verbose output and graceful handling of unexpected exceptions and keyboard interrupts.
12+
13+
Example:
14+
error_manager = ManagerError(verbose=True)
15+
error_manager.try_function(main_function)
16+
17+
Classes
18+
-------
19+
20+
`ManagerError(*args, **kwargs)`
21+
: Handles exceptions with colored output and optional verbose tracebacks for CLI applications.
22+
23+
This class provides methods to manage error reporting, including printing colored error messages,
24+
displaying full tracebacks when verbose mode is enabled, and gracefully handling unexpected exceptions
25+
and keyboard interrupts.
26+
27+
Attributes:
28+
verbose (bool): If True, displays full traceback on error; otherwise, shows a colored error message.
29+
30+
Methods:
31+
handle(exception: Exception, exit_code: int = 1):
32+
Handles an exception by printing a colored error message or full traceback, then exits with the given code.
33+
34+
try_function(function: callable, *args, **kwargs):
35+
Executes a function, catching and handling exceptions and keyboard interrupts gracefully.
36+
37+
Args:
38+
verbose (bool): If True, show full traceback, otherwise show a colored error.
39+
40+
### Descendants
41+
42+
* ctfsolver.src.ctfsolver.CTFSolver
43+
44+
### Methods
45+
46+
`handle(self, exception: Exception, exit_code: int = 1)`
47+
: Handles exceptions by printing error information in color and exiting the program.
48+
49+
exception (Exception): The exception instance to handle.
50+
exit_code (int, optional): The exit code to use when exiting the program. Defaults to 1.
51+
52+
Returns:
53+
None
54+
55+
Raises:
56+
SystemExit: Exits the program with the specified exit code.
57+
58+
`try_function(self, function: <built-in function callable>, *args, **kwargs)`
59+
: Executes a given function with provided arguments, handling exceptions.
60+
Args:
61+
function (callable): The function to execute.
62+
*args: Variable length argument list to pass to the function.
63+
**kwargs: Arbitrary keyword arguments to pass to the function.
64+
Returns:
65+
None
66+
Raises:
67+
Handles all exceptions using the `handle` method.
68+
Prints a message if interrupted by the user (KeyboardInterrupt).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Module ctfsolver.find_usage
2+
===========================
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Module ctfsolver.folders
2+
========================
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Module ctfsolver.forensics
2+
==========================
3+
4+
Sub-modules
5+
-----------
6+
* ctfsolver.forensics.manager_dash
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
Module ctfsolver.forensics.manager_dash
2+
=======================================
3+
manager_dash.py
4+
5+
Dash-based visualization manager for network packet flows.
6+
7+
This module provides the ManagerDash class, which facilitates the conversion of network packet data (such as from pcap files using scapy)
8+
into a format suitable for interactive graph visualization using Dash and Cytoscape. It includes utilities for converting packets to graph elements,
9+
validating element structure, generating example graphs, and running a Dash web application for visual exploration of network flows.
10+
11+
Classes:
12+
ManagerDash: Manages the conversion of packet data to Cytoscape elements and sets up the Dash visualization interface.
13+
14+
Typical Usage Example:
15+
manager.elements = manager.example_element_creator()
16+
17+
Dependencies:
18+
- dash
19+
- dash_cytoscape
20+
- scapy
21+
22+
Classes
23+
-------
24+
25+
`ManagerDash(*args, **kwargs)`
26+
: ManagerDash provides functionality for converting network packet data into elements suitable for graph visualization,
27+
validating element structure, and displaying interactive network graphs using Dash and Cytoscape.
28+
29+
Attributes:
30+
elements (list[dict]): List of elements representing nodes and edges for visualization.
31+
title (str): Title of the Dash application.
32+
app: dash.Dash | None # Dash application instance
33+
34+
35+
Methods:
36+
pcap_to_element_converter(packets, save=False):
37+
Converts a list of scapy Packet objects into visualization elements (nodes and edges) based on IP layer data.
38+
39+
pcap_to_element_converter_timestamp(packets, save=False):
40+
Converts packets into elements including timestamp nodes, representing temporal flow in the network graph.
41+
42+
elements_checker(elements):
43+
Validates the structure and content of a list of element dictionaries for compatibility with Cytoscape.
44+
45+
example_element_creator():
46+
Generates a sample list of elements representing a simple network graph for demonstration purposes.
47+
48+
setup_dash():
49+
Initializes and configures the Dash application layout and callbacks.
50+
51+
setup_dash_layout():
52+
Defines the layout of the Dash application, including the Cytoscape graph and output display.
53+
54+
setup_dash_functions():
55+
Sets up Dash callback functions for interactive node information display.
56+
57+
run_dash():
58+
Validates elements and runs the Dash application for interactive network graph visualization.
59+
60+
Initializes the manager_dash instance.
61+
62+
Args:
63+
*args: Variable length argument list.
64+
**kwargs: Arbitrary keyword arguments.
65+
title (str, optional): The title for the network graph. Defaults to "Interactive Network Graph".
66+
67+
Attributes:
68+
elements (list): Stores elements related to the manager dashboard.
69+
title (str): Title of the interactive network graph.
70+
71+
### Methods
72+
73+
`elements_checker(self, elements: list[dict]) ‑> bool`
74+
: Description:
75+
Validates a list of dictionaries to ensure they meet specific structural and content requirements.
76+
Each dictionary in the list must contain a "data" key with a dictionary value, and the keys within
77+
the "data" dictionary must adhere to a predefined set of allowed keys. Additionally, certain key
78+
combinations are required to be present together.
79+
Args:
80+
elements (list[dict]): A list of dictionaries to validate. Each dictionary is expected to have
81+
a "data" key containing another dictionary.
82+
Returns:
83+
bool: Returns True if all dictionaries in the list meet the validation criteria, otherwise False.
84+
85+
`example_element_creator(self)`
86+
: Generates a list of elements representing a network graph in a format compatible with Cytoscape.
87+
Description:
88+
This method creates a representation of a network graph based on predefined data.
89+
Each node (IP address) and edge (connection between IPs) is converted into a dictionary
90+
format suitable for use with Cytoscape visualizations.
91+
Args:
92+
None
93+
Returns:
94+
list: A list of dictionaries where each dictionary represents a node or an edge in the graph.
95+
Example output:
96+
[
97+
{"data": {"id": "192.168.0.2", "label": "192.168.0.2"}},
98+
{"data": {"id": "8.8.8.8", "label": "8.8.8.8"}},
99+
{"data": {"source": "192.168.0.2", "target": "8.8.8.8"}},
100+
{"data": {"id": "192.168.0.3", "label": "192.168.0.3"}},
101+
{"data": {"source": "192.168.0.2", "target": "192.168.0.3"}},
102+
{"data": {"id": "10.0.0.1", "label": "10.0.0.1"}},
103+
{"data": {"source": "192.168.0.3", "target": "10.0.0.1"}}
104+
]
105+
106+
`pcap_to_element_converter(self, packets: list[scapy.packet.Packet], save: bool = False) ‑> list[dict]`
107+
: Converts a list of scapy Packet objects into a list of elements suitable for visualization,
108+
extracting source and destination IPs and protocol information.
109+
110+
Each packet with an IP layer contributes:
111+
- Two node elements (for source and destination IPs)
112+
- One edge element (representing the connection and protocol between source and destination)
113+
114+
Args:
115+
packets (list[scapy.packet.Packet]): List of scapy Packet objects to process.
116+
save (bool, optional): If True, returns the generated elements list. If False, assigns it to self.elements.
117+
118+
Returns:
119+
list[dict]: List of elements representing nodes and edges if save is True; otherwise, None.
120+
121+
`pcap_to_element_converter_timestamp(self, packets: list[scapy.packet.Packet], save: bool = False) ‑> list[dict]`
122+
: Description:
123+
Converts a list of scapy Packet objects from a pcap file into a list of elements suitable for graph visualization.
124+
Each packet's timestamp, source IP, destination IP, and protocol are extracted and represented as nodes and edges.
125+
Optionally saves the generated elements to the instance.
126+
127+
Args:
128+
packets (list[scapy.packet.Packet]): List of scapy Packet objects to convert.
129+
save (bool, optional): If True, returns the elements list; otherwise, assigns it to self.elements. Defaults to False.
130+
131+
Raises:
132+
AttributeError: If a packet does not have the expected IP layer attributes.
133+
134+
Returns:
135+
list[dict]: List of dictionaries representing nodes and edges for visualization (only if save=True).
136+
137+
Example:
138+
elements = pcap_to_element_converter_timestamp(packets, save=True)
139+
140+
`run_dash(self)`
141+
: Runs the Dash application after validating and setting up required elements.
142+
This method performs the following steps:
143+
1. Checks if `self.elements` is not None or empty.
144+
2. Validates the format of `self.elements` using `self.elements_checker`.
145+
3. Sets up the Dash application by calling `self.setup_dash`.
146+
4. Runs the Dash app with debugging enabled.
147+
Raises:
148+
ValueError: If `self.elements` is None or empty.
149+
ValueError: If `self.elements` does not pass the format check.
150+
151+
`setup_dash(self)`
152+
: Initializes and configures the Dash application.
153+
154+
This method creates a Dash app instance, sets its title,
155+
and sets up the layout and callback functions required for the dashboard.
156+
157+
Args:
158+
None
159+
160+
Returns:
161+
None
162+
163+
`setup_dash_functions(self)`
164+
: Sets up Dash callback functions for interactive components in the dashboard.
165+
This method registers a callback for the Cytoscape graph component to handle node click events.
166+
When a node is clicked, its information is displayed in the designated output component.
167+
Callback:
168+
- Output: Updates the "node-click-output" component's children with node information.
169+
- Input: Listens for "tapNodeData" events from the "cytoscape-graph" component.
170+
Returns:
171+
None
172+
173+
`setup_dash_layout(self)`
174+
: Sets up the Dash application layout for packet flow visualization.
175+
This method configures the main layout of the Dash app, including:
176+
- A header displaying "Packet Flow Visualization".
177+
- A Cytoscape graph for visualizing packet flows, with nodes and edges styled for clarity.
178+
- An output div for displaying information when a node is clicked.
179+
The layout uses a force-directed graph ("cose" layout) and applies custom styles for nodes, edges, and background.
180+
Returns:
181+
None

0 commit comments

Comments
 (0)