Skip to content
This repository was archived by the owner on May 14, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions nexpose/nexpose_site.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Future Imports for py2/3 backwards compat.
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import datetime
from builtins import object
from nexpose_tag import DEFAULT_TAGCOLOR
from xml_utils import get_attribute, get_content_of, get_children_of, create_element, as_string, as_xml, get_element
from future import standard_library
standard_library.install_aliases()
Expand Down Expand Up @@ -86,6 +88,7 @@ def CreateFromXML(xml_data):
config.alerting = [alert for alert in get_children_of(xml_data, 'Alerting')]
config.credentials = [credential for credential in get_children_of(xml_data, 'Credentials')]
config.users = [user for user in get_children_of(xml_data, 'Users')]
config.tags = [tag for tag in get_children_of(xml_data, 'Tags')]

# Use scanconfig elements for the SiteConfiguration
scanconfig = get_element(xml_data, "ScanConfig")
Expand Down Expand Up @@ -125,6 +128,7 @@ def __init__(self):
self.configengineid = 3
self.users = []
self.schedules = []
self.tags = []

def AsXML(self, exclude_id):
attributes = {}
Expand Down Expand Up @@ -176,6 +180,38 @@ def AsXML(self, exclude_id):
xml_scanconfig.append(xml_scheduling)
xml_data.append(xml_scanconfig)

xml_tags = create_element('Tags')
for tag in self.tags:
for tag_data in tag:
tag_data_name = get_attribute(tag_data, 'name')
tag_data_value = get_attribute(tag_data, 'value')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per flake8 output, tag_data_value is never used. Should probably be used in place of the calls to get_attribute(tag_data, 'value') in the below if blocks since the value shouldn't change until the name matches a condition.


# CREATION_DATE must be in epoch time.
if tag_data_name == 'CREATION_DATE':
creation_date_value = get_attribute(tag_data, 'value')
creation_date_as_datetime = datetime.datetime.strptime(creation_date_value, '%a %b %d %H:%M:%S %Z %Y')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date format string could be extracted to a constant, but I don't think it's a big deal.

creation_date_as_epoch = creation_date_as_datetime.strftime('%s')
tag_data.attrib['value'] = creation_date_as_epoch

# The "Built-in" tags do not return the HTML color code.
if tag_data_name == 'COLOR':
color_value = get_attribute(tag_data, 'value')
# Throws an exception: "param must have a value"
if not color_value:
tag_data.attrib['value'] = str(DEFAULT_TAGCOLOR)

# A creator user ID of 0 cannot be submitted.
if tag_data_name == 'CREATOR_USER_ID':
creator_user_id_value = get_attribute(tag_data, 'value')
# Throws an exception: "The value '0' must be a positive integer."
# This is for the "Built-in" tags like "Low", "Medium", "High"
# Does not permanently save "1" to the tag.
if creator_user_id_value == "0":
tag_data.attrib['value'] = "1"

xml_tags.append(tag)
xml_data.append(xml_tags)

# TODO: implement the xxxPrivileges
# print(as_string(as_xml(as_string(xml_data))))
return xml_data