Skip to content
Pak Cyberbot edited this page Jan 3, 2024 · 2 revisions

All the utility functions Need some improvements

reportme()

# FUNCTION DOCSTRING
"""
fill_template(tmpl_path, out_path, data_dict, img_list):
    Fills in the fields of the template document with data and generates a result document.

Args:
    tmpl_path (str): Path of the template document that contains the fields to be filled in.
    out_path (str): Path of the resulting document with placeholders replaced by data.
    data_dict (dict): A dictionary mapping placeholder names to their corresponding values for replacement.
    img_list (dict): A dictionary specifying the images to replace in the document. 
        Key: The position of the image, docx and odt have different positions arrangement.
        Value: The path to the image file.

Note:
- In ODT files: Position of Images depends on the order of adding them not the format of document.
    - if someone adds the image first but adds it to the last page still it will gonna have 0 position.
- In DOCX files: Position of Images depends on the format of document.
    - if someone adds the image first but adds it to the last page then it will gonna have last position.

Example:
    tmpl_path = 'template.odt'
    out_path = 'result.odt'
    data_dict = {'placeholder1': 'value1', 'placeholder2': 'value2'}
    img_list = {0: 'image1.png', 1: 'image2.png'}
    fill_template(tmpl_path, out_path, data_dict, img_list)
"""

pathme()

# FUNCTION DOCSTRING
"""
Returns the absolute path based on the operating system or the given relative path depends on the availability

If the script is compiled using PyInstaller, it retrieves the path from the temporary folder created by PyInstaller.
Otherwise, it checks if the relative path exists in the current directory. If it does, it returns the relative path.
If the relative path doesn't exist, it creates a better absolute path based on the operating system.

When you want to include the ICO/image in the executable bundle, provide 'True' as the 2nd argument.

Args:
    relative_path (str): The path relative to the current directory.

Returns:
    str: The absolute path based on the operating system and the given relative path.

Raises:
    Exception: If the operating system is not supported.
"""

CaseDirMe

"""
A class to dynamically retrieve the case directory.

Args:
    case_name (str, optional): The name of the specific case directory. Defaults to ''.
    create (bool, optional): Whether to create a new case directory. Defaults to False.
    config_file (str, optional): The path to the configuration file. Defaults to "agency_data.json".

Attributes:
    case_dir (str): The path to the case directory.
    cases_folder (str): The path to the cases folder.

Raises:
    Exception: If the operating system is not supported.

Methods:
    default_cases_dir(): Returns the default case directory location according to the operating system.
"""

get_current_timestamp()

self-explanatory

auditme()

Takes case dir path and the message to save in the audit log of that case.

get_random_useragent()

self-explanatory

Clone this wiki locally