Class: Nexpose::ReportTemplate

Inherits:
Object
  • Object
show all
Includes:
Sanitize
Defined in:
lib/nexpose/report_template.rb

Overview

Definition object for a report template.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sanitize

#replace_entities

Constructor Details

#initialize(name, type = 'document', id = -1,, scope = 'silo', built_in = false) ⇒ ReportTemplate

Returns a new instance of ReportTemplate.



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/nexpose/report_template.rb', line 115

def initialize(name, type = 'document', id = -1, scope = 'silo', built_in = false)
  @name             = name
  @type             = type
  @id               = id
  @scope            = scope
  @built_in         = built_in
  @sections         = []
  @properties       = {}
  @attributes       = []
  @show_asset_names = false
end

Instance Attribute Details

#attributesObject

Array of report attributes, in the order they will be present in a report.



109
110
111
# File 'lib/nexpose/report_template.rb', line 109

def attributes
  @attributes
end

#built_inObject

The report template is built-in, and cannot be modified.



100
101
102
# File 'lib/nexpose/report_template.rb', line 100

def built_in
  @built_in
end

#descriptionObject

Description of this report template.



102
103
104
# File 'lib/nexpose/report_template.rb', line 102

def description
  @description
end

#idObject

The ID of the report template.



85
86
87
# File 'lib/nexpose/report_template.rb', line 85

def id
  @id
end

#nameObject

The name of the report template.



87
88
89
# File 'lib/nexpose/report_template.rb', line 87

def name
  @name
end

#propertiesObject

Map of report properties.



107
108
109
# File 'lib/nexpose/report_template.rb', line 107

def properties
  @properties
end

#scopeObject

The visibility (scope) of the report template. One of: global|silo



98
99
100
# File 'lib/nexpose/report_template.rb', line 98

def scope
  @scope
end

#sectionsObject

Array of report sections.



105
106
107
# File 'lib/nexpose/report_template.rb', line 105

def sections
  @sections
end

#show_asset_namesObject Also known as: show_device_names

Display asset names with IPs.



111
112
113
# File 'lib/nexpose/report_template.rb', line 111

def show_asset_names
  @show_asset_names
end

#typeObject

With a data template, you can export comma-separated value (CSV) files with vulnerability-based data. With a document template, you can create PDF, RTF, HTML, or XML reports with asset-based information. When you retrieve a report template, the type will always be visible even though type is implied. When ReportTemplate is sent as a request, and the type attribute is not provided, the type attribute defaults to document, allowing for backward compatibility with existing API clients.



95
96
97
# File 'lib/nexpose/report_template.rb', line 95

def type
  @type
end

Class Method Details

.load(connection, template_id) ⇒ Object

Retrieve the configuration for a report template.



139
140
141
142
# File 'lib/nexpose/report_template.rb', line 139

def self.load(connection, template_id)
  xml = %(<ReportTemplateConfigRequest session-id='#{connection.session_id}' template-id='#{template_id}'/>)
  ReportTemplate.parse(connection.execute(xml))
end

.parse(xml) ⇒ Object



178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/nexpose/report_template.rb', line 178

def self.parse(xml)
  xml.res.elements.each('//ReportTemplate') do |tmp|
    template = ReportTemplate.new(tmp.attributes['name'],
                                  tmp.attributes['type'],
                                  tmp.attributes['id'],
                                  tmp.attributes['scope'] || 'silo',
                                  tmp.attributes['builtin'])
    tmp.elements.each('//description') do |desc|
      template.description = desc.text
    end

    tmp.elements.each('//ReportAttributes/ReportAttribute') do |attr|
      template.attributes << attr.attributes['name']
    end

    tmp.elements.each('//ReportSections/property') do |property|
      template.properties[property.attributes['name']] = property.text
    end

    tmp.elements.each('//ReportSection') do |section|
      template.sections << Section.parse(section)
    end

    tmp.elements.each('//showDeviceNames') do |show|
      template.show_asset_names = show.attributes['enabled'] == '1'
    end

    return template
  end
  nil
end

Instance Method Details

#delete(connection) ⇒ Object



144
145
146
# File 'lib/nexpose/report_template.rb', line 144

def delete(connection)
  connection.delete_report_template(@id)
end

#save(connection) ⇒ Object

Save the configuration for a report template.



128
129
130
131
132
133
134
135
136
# File 'lib/nexpose/report_template.rb', line 128

def save(connection)
  xml = %(<ReportTemplateSaveRequest session-id='#{connection.session_id}' scope='#{@scope}'>)
  xml << to_xml
  xml << '</ReportTemplateSaveRequest>'
  response = connection.execute(xml)
  if response.success
    @id = response.attributes['template-id']
  end
end

#to_xmlObject



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/nexpose/report_template.rb', line 150

def to_xml
  xml = %(<ReportTemplate id='#{@id}' name='#{@name}' type='#{@type}')
  xml << %( scope='#{@scope}') if @scope
  xml << %( builtin='#{@built_in}') if @built_in
  xml << '>'
  xml << %(<description>#{@description}</description>) if @description

  unless @attributes.empty?
    xml << '<ReportAttributes>'
    @attributes.each do |attr|
      xml << %(<ReportAttribute name='#{attr}'/>)
    end
    xml << '</ReportAttributes>'
  end

  unless @sections.empty?
    xml << '<ReportSections>'
    properties.each_pair do |name, value|
      xml << %(<property name='#{name}'>#{replace_entities(value)}</property>)
    end
    @sections.each { |section| xml << section.to_xml }
    xml << '</ReportSections>'
  end

  xml << %(<Settings><showDeviceNames enabled='#{@show_asset_names ? 1 : 0}' /></Settings>)
  xml << '</ReportTemplate>'
end