Class: Nexpose::ReportTemplate

Inherits:
Object
  • Object
show all
Includes:
Sanitize
Defined in:
lib/nexpose/report.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.



652
653
654
655
656
657
658
659
660
661
662
663
# File 'lib/nexpose/report.rb', line 652

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.



648
649
650
# File 'lib/nexpose/report.rb', line 648

def attributes
  @attributes
end

#built_inObject

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



639
640
641
# File 'lib/nexpose/report.rb', line 639

def built_in
  @built_in
end

#descriptionObject

Description of this report template.



641
642
643
# File 'lib/nexpose/report.rb', line 641

def description
  @description
end

#idObject

The ID of the report template.



624
625
626
# File 'lib/nexpose/report.rb', line 624

def id
  @id
end

#nameObject

The name of the report template.



626
627
628
# File 'lib/nexpose/report.rb', line 626

def name
  @name
end

#propertiesObject

Map of report properties.



646
647
648
# File 'lib/nexpose/report.rb', line 646

def properties
  @properties
end

#scopeObject

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



637
638
639
# File 'lib/nexpose/report.rb', line 637

def scope
  @scope
end

#sectionsObject

Array of report sections.



644
645
646
# File 'lib/nexpose/report.rb', line 644

def sections
  @sections
end

#show_device_namesObject

Display asset names with IPs.



650
651
652
# File 'lib/nexpose/report.rb', line 650

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.



634
635
636
# File 'lib/nexpose/report.rb', line 634

def type
  @type
end

Class Method Details

.get(connection, template_id) ⇒ Object

Retrieve the configuration for a report template.



686
687
688
# File 'lib/nexpose/report.rb', line 686

def self.get(connection, template_id)
  connection.get_report_template(template_id)
end

.parse(xml) ⇒ Object



720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
# File 'lib/nexpose/report.rb', line 720

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



676
677
678
679
680
681
682
683
# File 'lib/nexpose/report.rb', line 676

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

#save(connection) ⇒ Object

Save the configuration for a report template.



666
667
668
669
670
671
672
673
674
# File 'lib/nexpose/report.rb', line 666

def save(connection)
  xml = %Q{<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



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File 'lib/nexpose/report.rb', line 692

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

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

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

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