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.



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

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.



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

def attributes
  @attributes
end

#built_inObject

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



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

def built_in
  @built_in
end

#descriptionObject

Description of this report template.



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

def description
  @description
end

#idObject

The ID of the report template.



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

def id
  @id
end

#nameObject

The name of the report template.



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

def name
  @name
end

#propertiesObject

Map of report properties.



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

def properties
  @properties
end

#scopeObject

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



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

def scope
  @scope
end

#sectionsObject

Array of report sections.



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

def sections
  @sections
end

#show_device_namesObject

Display asset names with IPs.



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

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.



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

def type
  @type
end

Class Method Details

.get(connection, template_id) ⇒ Object

Retrieve the configuration for a report template.



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

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

.parse(xml) ⇒ Object



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
751
# File 'lib/nexpose/report.rb', line 721

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



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

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.



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

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



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
719
# File 'lib/nexpose/report.rb', line 693

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