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.



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

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_device_names = false
end

Instance Attribute Details

#attributesObject

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



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

def attributes
  @attributes
end

#built_inObject

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



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

def built_in
  @built_in
end

#descriptionObject

Description of this report template.



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

def description
  @description
end

#idObject

The ID of the report template.



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

def id
  @id
end

#nameObject

The name of the report template.



90
91
92
# File 'lib/nexpose/report_template.rb', line 90

def name
  @name
end

#propertiesObject

Map of report properties.



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

def properties
  @properties
end

#scopeObject

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



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

def scope
  @scope
end

#sectionsObject

Array of report sections.



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

def sections
  @sections
end

#show_device_namesObject

Display asset names with IPs.



114
115
116
# File 'lib/nexpose/report_template.rb', line 114

def show_device_names
  @show_device_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.



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

def type
  @type
end

Class Method Details

.load(connection, template_id) ⇒ Object

Retrieve the configuration for a report template.



141
142
143
144
# File 'lib/nexpose/report_template.rb', line 141

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



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
209
210
# File 'lib/nexpose/report_template.rb', line 180

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_device_names = show.attributes['enabled'] == '1'
    end

    return template
  end
  nil
end

Instance Method Details

#delete(connection) ⇒ Object



146
147
148
# File 'lib/nexpose/report_template.rb', line 146

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

#save(connection) ⇒ Object

Save the configuration for a report template.



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

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



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
177
178
# File 'lib/nexpose/report_template.rb', line 152

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_device_names ? 1 : 0}' /></Settings>)
  xml << '</ReportTemplate>'
end