mirror of https://github.com/MISP/PyMISP
fix: [reportlab] Clusters added. Still UX to perform
parent
79e66363d2
commit
24e1a1732c
|
@ -716,6 +716,34 @@ class Value_Formatter():
|
||||||
|
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
|
def get_galaxy_name_value(self, misp_galaxy):
|
||||||
|
item = ["Name", 'name', "None", "namespace", "type"]
|
||||||
|
if is_safe_dict_attribute(misp_galaxy, item[1]):
|
||||||
|
return self.get_unoverflowable_paragraph(safe_string(misp_galaxy[item[1]])
|
||||||
|
+ " <i>from</i> " + safe_string(misp_galaxy[item[3]]) + ":"
|
||||||
|
+ safe_string(misp_galaxy[item[4]]), do_escape_string=False)
|
||||||
|
return self.get_unoverflowable_paragraph(item[2])
|
||||||
|
|
||||||
|
def get_galaxy_cluster_name_value(self, misp_cluster):
|
||||||
|
item = ["Name", 'value', "None", "source", "meta", "synonyms"]
|
||||||
|
tmp_text = ""
|
||||||
|
|
||||||
|
if is_safe_dict_attribute(misp_cluster, item[1]):
|
||||||
|
print(misp_cluster[item[1]])
|
||||||
|
tmp_text += safe_string(misp_cluster[item[1]])
|
||||||
|
|
||||||
|
#if is_safe_dict_attribute(misp_cluster, item[3]) :
|
||||||
|
# tmp_text += "<br/><i>Source :</i> " + misp_cluster[item[3]]
|
||||||
|
|
||||||
|
if is_safe_dict_attribute(misp_cluster, item[4]) and is_safe_dict_attribute(misp_cluster[item[4]], item[5]):
|
||||||
|
tmp_text += " <br/><i>Synonyms :</i> "
|
||||||
|
for i, synonyme in enumerate(misp_cluster[item[4]][item[5]]) :
|
||||||
|
if i != 0 :
|
||||||
|
tmp_text += " / "
|
||||||
|
tmp_text += safe_string(synonyme)
|
||||||
|
|
||||||
|
return self.get_unoverflowable_paragraph(tmp_text, do_escape_string=False)
|
||||||
|
return self.get_unoverflowable_paragraph(item[2])
|
||||||
|
|
||||||
class Event_Metadata():
|
class Event_Metadata():
|
||||||
|
|
||||||
|
@ -801,11 +829,7 @@ class Event_Metadata():
|
||||||
# Galaxies
|
# Galaxies
|
||||||
item = ["Related Galaxies", 'Galaxy', "None"]
|
item = ["Related Galaxies", 'Galaxy', "None"]
|
||||||
curr_Galaxy = Galaxy(self.config, self.value_formatter)
|
curr_Galaxy = Galaxy(self.config, self.value_formatter)
|
||||||
if is_safe_attribute_table(misp_event, item[1]) and is_in_config(self.config, 3):
|
flowable_table += curr_Galaxy.get_galaxy_value(misp_event, item)
|
||||||
galaxy_title = Paragraph(item[0], self.sample_style_sheet['Heading5'])
|
|
||||||
|
|
||||||
flowable_table.append(galaxy_title)
|
|
||||||
flowable_table.append(curr_Galaxy.get_galaxy_value(misp_event, item))
|
|
||||||
|
|
||||||
return flowable_table
|
return flowable_table
|
||||||
|
|
||||||
|
@ -1013,11 +1037,7 @@ class Attributes():
|
||||||
# Galaxies
|
# Galaxies
|
||||||
item = ["Related Galaxies", 'Galaxy', "None"]
|
item = ["Related Galaxies", 'Galaxy', "None"]
|
||||||
curr_Galaxy = Galaxy(self.config, self.value_formatter)
|
curr_Galaxy = Galaxy(self.config, self.value_formatter)
|
||||||
if is_safe_attribute_table(misp_attribute, item[1]) and is_in_config(self.config, 3):
|
flowable_table += curr_Galaxy.get_galaxy_value(misp_attribute, item)
|
||||||
galaxy_title = Paragraph(item[0], self.sample_style_sheet['Heading5'])
|
|
||||||
|
|
||||||
flowable_table.append(galaxy_title)
|
|
||||||
flowable_table.append(curr_Galaxy.get_galaxy_value(misp_attribute, item))
|
|
||||||
|
|
||||||
return flowable_table
|
return flowable_table
|
||||||
|
|
||||||
|
@ -1219,6 +1239,7 @@ class Galaxy():
|
||||||
def __init__(self, config, value_formatter):
|
def __init__(self, config, value_formatter):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.value_formatter = value_formatter
|
self.value_formatter = value_formatter
|
||||||
|
self.sample_style_sheet = getSampleStyleSheet()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -1232,9 +1253,20 @@ class Galaxy():
|
||||||
:param col2_style: style to be applied on the returned paragraph
|
:param col2_style: style to be applied on the returned paragraph
|
||||||
:return: a Flowable to add in the pdf, regarding the values of "galaxies"
|
:return: a Flowable to add in the pdf, regarding the values of "galaxies"
|
||||||
'''
|
'''
|
||||||
if is_safe_attribute_table(misp_event, item[1]):
|
|
||||||
return self.create_flowable_table_from_galaxies(misp_event)
|
flowable_table = []
|
||||||
return self.value_formatter.get_unoverflowable_paragraph(item[2])
|
|
||||||
|
# Galaxies
|
||||||
|
# item = ["Related Galaxies", 'Galaxy', "None"]
|
||||||
|
if is_safe_attribute_table(misp_event, item[1]) and is_in_config(self.config, 3):
|
||||||
|
galaxy_title = Paragraph(item[0], self.sample_style_sheet['Heading5'])
|
||||||
|
|
||||||
|
flowable_table.append(galaxy_title)
|
||||||
|
flowable_table += self.create_flowable_table_from_galaxies(misp_event)
|
||||||
|
else :
|
||||||
|
flowable_table.append(self.value_formatter.get_unoverflowable_paragraph(item[2]))
|
||||||
|
|
||||||
|
return flowable_table
|
||||||
|
|
||||||
|
|
||||||
def create_flowable_table_from_galaxies(self, misp_event):
|
def create_flowable_table_from_galaxies(self, misp_event):
|
||||||
|
@ -1247,6 +1279,7 @@ class Galaxy():
|
||||||
flowable_table = []
|
flowable_table = []
|
||||||
scheme_alternation = []
|
scheme_alternation = []
|
||||||
curr_color = 0
|
curr_color = 0
|
||||||
|
i = 0
|
||||||
|
|
||||||
if is_safe_attribute_table(misp_event, "Galaxy"):
|
if is_safe_attribute_table(misp_event, "Galaxy"):
|
||||||
# There is some galaxies for this object
|
# There is some galaxies for this object
|
||||||
|
@ -1254,6 +1287,10 @@ class Galaxy():
|
||||||
for curr_galaxy in getattr(misp_event, "Galaxy"):
|
for curr_galaxy in getattr(misp_event, "Galaxy"):
|
||||||
# For each galaxy of the misp object
|
# For each galaxy of the misp object
|
||||||
|
|
||||||
|
galaxy_title = Paragraph("Galaxy # " + str(i), self.sample_style_sheet['Heading6'])
|
||||||
|
flowable_table.append(galaxy_title)
|
||||||
|
i += 1
|
||||||
|
|
||||||
# Add metadata about the Galaxy
|
# Add metadata about the Galaxy
|
||||||
galaxy_metadata, nb_added_item = self.create_flowable_table_from_one_galaxy(curr_galaxy)
|
galaxy_metadata, nb_added_item = self.create_flowable_table_from_one_galaxy(curr_galaxy)
|
||||||
flowable_table += galaxy_metadata
|
flowable_table += galaxy_metadata
|
||||||
|
@ -1261,22 +1298,27 @@ class Galaxy():
|
||||||
# Construct the line color scheme and line scheme
|
# Construct the line color scheme and line scheme
|
||||||
scheme_alternation += [curr_color] * nb_added_item
|
scheme_alternation += [curr_color] * nb_added_item
|
||||||
|
|
||||||
|
# Apply the scheme
|
||||||
|
# answer_tags = create_flowable_table_from_data(flowable_table)
|
||||||
|
|
||||||
# Add metadata about clusters
|
# Add metadata about clusters
|
||||||
curr_cluster = Galaxy_cluster(self.config, self.value_formatter)
|
curr_cluster = Galaxy_cluster(self.config, self.value_formatter)
|
||||||
clusters_metadata, nb_added_item = curr_cluster.create_flowable_table_from_galaxy_clusters(curr_galaxy)
|
clusters_metadata = curr_cluster.create_flowable_table_from_galaxy_clusters(curr_galaxy)
|
||||||
flowable_table += clusters_metadata
|
flowable_table += clusters_metadata
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
# Construct the line color scheme and line scheme
|
# Construct the line color scheme and line scheme
|
||||||
scheme_alternation += [curr_color] * nb_added_item
|
scheme_alternation += [curr_color] * nb_added_item
|
||||||
curr_color += 1 if curr_color == 0 else 0
|
curr_color += 1 if curr_color == 0 else 0
|
||||||
|
'''
|
||||||
|
|
||||||
# Apply the scheme
|
|
||||||
answer_tags = create_flowable_table_from_data(flowable_table, color_alternation=scheme_alternation , line_alternation=scheme_alternation)
|
|
||||||
else:
|
else:
|
||||||
# No galaxies for this object
|
# No galaxies for this object
|
||||||
answer_tags = [self.value_formatter.get_unoverflowable_paragraph("No galaxies")]
|
answer_tags = [self.value_formatter.get_unoverflowable_paragraph("No galaxies")]
|
||||||
|
flowable_table.append(create_flowable_table_from_data(answer_tags))
|
||||||
|
|
||||||
return answer_tags
|
return flowable_table
|
||||||
|
|
||||||
def create_flowable_table_from_one_galaxy(self, misp_galaxy):
|
def create_flowable_table_from_one_galaxy(self, misp_galaxy):
|
||||||
'''
|
'''
|
||||||
|
@ -1287,24 +1329,24 @@ class Galaxy():
|
||||||
data = []
|
data = []
|
||||||
nb_added_item = 0
|
nb_added_item = 0
|
||||||
|
|
||||||
# To reduce code size, and automate it a bit, triplet (Displayed Name, object_attribute_name,
|
# Name
|
||||||
# to_display_if_not_present) are store in the following list
|
item = ["Name", 'name', "None"]
|
||||||
list_attr_automated = [["Name", 'name', "None"],
|
if is_safe_dict_attribute(misp_galaxy, item[1]):
|
||||||
["Type", 'type', "None"],
|
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
||||||
["Description", 'description', "None"],
|
self.value_formatter.get_galaxy_name_value(misp_galaxy)])
|
||||||
["NameSpace", 'namespace', "None"]]
|
nb_added_item += 1
|
||||||
|
|
||||||
# Automated adding of standard (python) attributes of the misp object
|
# Description
|
||||||
for item in list_attr_automated:
|
item = ["Description", 'description', "None"]
|
||||||
if is_safe_dict_attribute(misp_galaxy, item[1]):
|
if is_safe_dict_attribute(misp_galaxy, item[1]):
|
||||||
# The attribute exists, we fetch it and create the row
|
|
||||||
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
||||||
self.value_formatter.get_unoverflowable_paragraph(misp_galaxy[item[1]])])
|
self.value_formatter.get_unoverflowable_paragraph(misp_galaxy[item[1]])])
|
||||||
nb_added_item += 1
|
nb_added_item += 1
|
||||||
|
|
||||||
# The attribute does not exist, you may want to print a default text on the row. Then use as a else case :
|
flowable_table = []
|
||||||
# data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)])
|
flowable_table.append(create_flowable_table_from_data(data))
|
||||||
return data, nb_added_item
|
|
||||||
|
return flowable_table, nb_added_item
|
||||||
|
|
||||||
|
|
||||||
class Galaxy_cluster():
|
class Galaxy_cluster():
|
||||||
|
@ -1313,6 +1355,7 @@ class Galaxy_cluster():
|
||||||
def __init__(self, config, value_formatter):
|
def __init__(self, config, value_formatter):
|
||||||
self.config = config
|
self.config = config
|
||||||
self.value_formatter = value_formatter
|
self.value_formatter = value_formatter
|
||||||
|
self.sample_style_sheet = getSampleStyleSheet()
|
||||||
|
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
def create_flowable_table_from_galaxy_clusters(self, misp_galaxy):
|
def create_flowable_table_from_galaxy_clusters(self, misp_galaxy):
|
||||||
|
@ -1323,23 +1366,39 @@ class Galaxy_cluster():
|
||||||
'''
|
'''
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
nb_added_item = 0
|
i = 0
|
||||||
|
|
||||||
|
item = ["Cluster #", 'name', "None"]
|
||||||
|
|
||||||
|
|
||||||
if is_safe_dict_attribute(misp_galaxy, "GalaxyCluster"):
|
if is_safe_dict_attribute(misp_galaxy, "GalaxyCluster"):
|
||||||
# There is some clusters for this object
|
# There is some clusters for this object
|
||||||
for curr_cluster in misp_galaxy["GalaxyCluster"]:
|
for curr_cluster in misp_galaxy["GalaxyCluster"]:
|
||||||
|
|
||||||
|
'''
|
||||||
|
galaxy_title = [Paragraph("Cluster #" + str(i), self.sample_style_sheet['Heading6'])]
|
||||||
|
data.append(galaxy_title)
|
||||||
|
i += 1
|
||||||
|
'''
|
||||||
|
|
||||||
# For each cluster
|
# For each cluster
|
||||||
tmp_data, curr_added_items = self.create_flowable_table_from_one_galaxy_cluster(curr_cluster)
|
tmp_data = self.create_flowable_table_from_one_galaxy_cluster(curr_cluster)
|
||||||
data += tmp_data
|
tmp_flowable_table = []
|
||||||
nb_added_item += curr_added_items
|
tmp_flowable_table.append(create_flowable_table_from_data(tmp_data, color_alternation = [0], line_alternation=[0]))
|
||||||
|
data.append([self.value_formatter.get_col1_paragraph(item[0]), tmp_flowable_table])
|
||||||
|
|
||||||
|
# data += tmp_data
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# No galaxies for this object
|
# No galaxies for this object
|
||||||
data = [self.value_formatter.get_unoverflowable_paragraph("No galaxy cluster")]
|
data = [self.value_formatter.get_unoverflowable_paragraph("No galaxy cluster")]
|
||||||
nb_added_item += 1
|
|
||||||
|
|
||||||
return data, nb_added_item
|
|
||||||
|
flowable_table = []
|
||||||
|
flowable_table.append(create_flowable_table_from_data(data))
|
||||||
|
|
||||||
|
|
||||||
|
return flowable_table
|
||||||
|
|
||||||
def create_flowable_table_from_one_galaxy_cluster(self, misp_cluster):
|
def create_flowable_table_from_one_galaxy_cluster(self, misp_cluster):
|
||||||
'''
|
'''
|
||||||
|
@ -1348,28 +1407,20 @@ class Galaxy_cluster():
|
||||||
:return: a table representing this misp's galaxy's cluster attributes, to add to the pdf as a flowable
|
:return: a table representing this misp's galaxy's cluster attributes, to add to the pdf as a flowable
|
||||||
'''
|
'''
|
||||||
data = []
|
data = []
|
||||||
nb_added_item = 0
|
|
||||||
|
|
||||||
# To reduce code size, and automate it a bit, triplet (Displayed Name, object_attribute_name,
|
# Name
|
||||||
# to_display_if_not_present) are store in the following list
|
item = ["Name", 'name', "None"]
|
||||||
list_attr_automated = [["Cluster #", 'tag_name', "None"],
|
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
||||||
["Type", 'type', "None"],
|
self.value_formatter.get_galaxy_cluster_name_value(misp_cluster)])
|
||||||
["Description", 'description', "None"],
|
|
||||||
["NameSpace", 'namespace', "None"]]
|
|
||||||
|
|
||||||
# Automated adding of standard (python) attributes of the misp object
|
# Description
|
||||||
for item in list_attr_automated:
|
item = ["Description", 'description', "None"]
|
||||||
if is_safe_dict_attribute(misp_cluster, item[1]):
|
|
||||||
# The attribute exists, we fetch it and create the row
|
|
||||||
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
data.append([self.value_formatter.get_col1_paragraph(item[0]),
|
||||||
self.value_formatter.get_unoverflowable_paragraph(misp_cluster[item[1]])])
|
self.value_formatter.get_unoverflowable_paragraph(misp_cluster[item[1]])])
|
||||||
nb_added_item += 1
|
|
||||||
|
|
||||||
# tmp_table = Table(data, ["25%", "75%"])
|
# Refs ?
|
||||||
# print(tmp_table)
|
|
||||||
# The attribute does not exist, you may want to print a default text on the row. Then use as a else case :
|
return data
|
||||||
# data.append([Paragraph(item[0], col1_style), Paragraph(item[2], col2_style)])
|
|
||||||
return data, nb_added_item
|
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
Loading…
Reference in New Issue