mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-31 01:35:36 +02:00
describe functions
This commit is contained in:
parent
1aa2453528
commit
b70be8b4e6
@ -17,6 +17,13 @@ def set_global_variable(
|
|||||||
variable_name,
|
variable_name,
|
||||||
value
|
value
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Sets the value of a global variable in the 'global_variables' dictionary.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
variable_name (str): Name of the variable to set.
|
||||||
|
value (any): Value to assign to the variable.
|
||||||
|
"""
|
||||||
|
|
||||||
global_variables[variable_name] = value
|
global_variables[variable_name] = value
|
||||||
|
|
||||||
@ -90,6 +97,12 @@ def write_xml(
|
|||||||
# Init agent template
|
# Init agent template
|
||||||
###########################################
|
###########################################
|
||||||
def init_agent() :
|
def init_agent() :
|
||||||
|
"""
|
||||||
|
Initializes an agent template with default values.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
dict: Dictionary representing the agent template with default values.
|
||||||
|
"""
|
||||||
agent = {
|
agent = {
|
||||||
"agent_name" : "",
|
"agent_name" : "",
|
||||||
"agent_alias" : "",
|
"agent_alias" : "",
|
||||||
|
@ -8,6 +8,13 @@ def set_summary_value(
|
|||||||
key="",
|
key="",
|
||||||
value=""
|
value=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Sets a fixed value for a key in the 'summary' dictionary.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (str): Key to set the value for.
|
||||||
|
value (any): Value to assign to the key.
|
||||||
|
"""
|
||||||
global summary
|
global summary
|
||||||
|
|
||||||
summary[key] = value
|
summary[key] = value
|
||||||
@ -19,6 +26,15 @@ def add_summary_value(
|
|||||||
key="",
|
key="",
|
||||||
value=""
|
value=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Adds a value to a key in the 'summary' dictionary.
|
||||||
|
|
||||||
|
If the key already exists, the value will be incremented. Otherwise, a new key will be created.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
key (str): Key to add the value to.
|
||||||
|
value (any): Value to add to the key.
|
||||||
|
"""
|
||||||
global summary
|
global summary
|
||||||
|
|
||||||
if key in summary:
|
if key in summary:
|
||||||
@ -32,6 +48,12 @@ def add_summary_value(
|
|||||||
def set_error_level(
|
def set_error_level(
|
||||||
value=0
|
value=0
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Sets the error level to the specified value.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
value (int, optional): The error level value. Default is 0.
|
||||||
|
"""
|
||||||
global error_level
|
global error_level
|
||||||
|
|
||||||
error_level = value
|
error_level = value
|
||||||
@ -42,6 +64,12 @@ def set_error_level(
|
|||||||
def add_info_value(
|
def add_info_value(
|
||||||
data=""
|
data=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Adds data to the 'info' variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data (str, optional): The data to add to the 'info' variable. Default is an empty string.
|
||||||
|
"""
|
||||||
global info
|
global info
|
||||||
|
|
||||||
info += data
|
info += data
|
||||||
@ -52,6 +80,12 @@ def add_info_value(
|
|||||||
def set_info_value(
|
def set_info_value(
|
||||||
data=""
|
data=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Sets a fixed value to the 'info' variable.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
data (str, optional): The value to set in the 'info' variable. Default is an empty string.
|
||||||
|
"""
|
||||||
global info
|
global info
|
||||||
|
|
||||||
info = data
|
info = data
|
||||||
@ -64,6 +98,17 @@ def parse_parameter(
|
|||||||
default="",
|
default="",
|
||||||
key=""
|
key=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Parses a parameter from the configuration file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
config (ConfigParser, optional): The ConfigParser object representing the configuration file. Default is None.
|
||||||
|
default (any, optional): The default value to return if the parameter is not found. Default is an empty string.
|
||||||
|
key (str): The key of the parameter to parse.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
any: The parsed value of the parameter, or the default value if the parameter is not found.
|
||||||
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return config.get("CONF", key)
|
return config.get("CONF", key)
|
||||||
@ -76,6 +121,15 @@ def parse_parameter(
|
|||||||
def parse_conf_entities(
|
def parse_conf_entities(
|
||||||
entities=""
|
entities=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Parses the configuration file credentials.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
entities (str): A JSON string representing the entities.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: A list of entities parsed from the JSON string. If parsing fails, an empty list is returned.
|
||||||
|
"""
|
||||||
entities_list = []
|
entities_list = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -96,6 +150,15 @@ def parse_conf_entities(
|
|||||||
def param_int(
|
def param_int(
|
||||||
param=""
|
param=""
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Parses a parameter as an integer.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
param (any): The parameter to be parsed as an integer.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: The parsed integer value. If parsing fails, returns 0.
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
return int(param)
|
return int(param)
|
||||||
except:
|
except:
|
||||||
@ -105,6 +168,13 @@ def param_int(
|
|||||||
# Print JSON output and exit script
|
# Print JSON output and exit script
|
||||||
###########################################
|
###########################################
|
||||||
def print_output():
|
def print_output():
|
||||||
|
"""
|
||||||
|
Prints the JSON output and exits the script.
|
||||||
|
|
||||||
|
The function uses the global variables 'output', 'error_level', 'summary', and 'info'
|
||||||
|
to create the JSON output. It then prints the JSON string and exits the script with
|
||||||
|
the 'error_level' as the exit code.
|
||||||
|
"""
|
||||||
|
|
||||||
global output
|
global output
|
||||||
global error_level
|
global error_level
|
||||||
|
@ -22,6 +22,13 @@ def set_global_variable(
|
|||||||
variable_name,
|
variable_name,
|
||||||
value
|
value
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Sets the value of a global variable in the 'global_variables' dictionary.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
variable_name (str): Name of the variable to set.
|
||||||
|
value (any): Value to assign to the variable.
|
||||||
|
"""
|
||||||
|
|
||||||
global_variables[variable_name] = value
|
global_variables[variable_name] = value
|
||||||
|
|
||||||
@ -95,6 +102,16 @@ def agentplugin(
|
|||||||
tentacle=False,
|
tentacle=False,
|
||||||
tentacle_conf=None
|
tentacle_conf=None
|
||||||
):
|
):
|
||||||
|
"""
|
||||||
|
Detects the transfer mode and executes the corresponding action.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
modules (list): List of modules.
|
||||||
|
agent (dict): Dictionary with agent configuration.
|
||||||
|
temp_dir (str, optional): Temporary directory. Default is global_variables['temporal'].
|
||||||
|
tentacle (bool, optional): Indicates whether to use the Tentacle protocol. Default is False.
|
||||||
|
tentacle_conf (dict, optional): Dictionary with Tentacle protocol configuration. Default is None.
|
||||||
|
"""
|
||||||
agent_file=print_agent(agent,modules,temp_dir)
|
agent_file=print_agent(agent,modules,temp_dir)
|
||||||
|
|
||||||
if agent_file[1] is not None:
|
if agent_file[1] is not None:
|
||||||
@ -114,6 +131,18 @@ def transfer_xml(
|
|||||||
tentacle_port=global_variables['tentacle_port'],
|
tentacle_port=global_variables['tentacle_port'],
|
||||||
temporal=global_variables['temporal']
|
temporal=global_variables['temporal']
|
||||||
):
|
):
|
||||||
|
|
||||||
|
"""
|
||||||
|
Detects the transfer mode and calls the agentplugin() function to perform the transfer.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
agent (dict): Dictionary with agent configuration.
|
||||||
|
modules (list): List of modules.
|
||||||
|
transfer_mode (str, optional): Transfer mode. Default is global_variables['transfer_mode'].
|
||||||
|
tentacle_ip (str, optional): IP address for Tentacle. Default is global_variables['tentacle_ip'].
|
||||||
|
tentacle_port (str, optional): Port for Tentacle. Default is global_variables['tentacle_port'].
|
||||||
|
temporal (str, optional): Temporary directory. Default is global_variables['temporal'].
|
||||||
|
"""
|
||||||
|
|
||||||
if transfer_mode != "local" and tentacle_ip is not None:
|
if transfer_mode != "local" and tentacle_ip is not None:
|
||||||
tentacle_conf={"address":tentacle_ip,"port":tentacle_port}
|
tentacle_conf={"address":tentacle_ip,"port":tentacle_port}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user