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.



648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/nexpose/report.rb', line 648

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.



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

def attributes
  @attributes
end

#built_inObject

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



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

def built_in
  @built_in
end

#descriptionObject

Description of this report template.



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

def description
  @description
end

#idObject

The ID of the report template.



620
621
622
# File 'lib/nexpose/report.rb', line 620

def id
  @id
end

#nameObject

The name of the report template.



622
623
624
# File 'lib/nexpose/report.rb', line 622

def name
  @name
end

#propertiesObject

Map of report properties.



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

def properties
  @properties
end

#scopeObject

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



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

def scope
  @scope
end

#sectionsObject

Array of report sections.



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

def sections
  @sections
end

#show_device_namesObject

Display asset names with IPs.



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

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.



630
631
632
# File 'lib/nexpose/report.rb', line 630

def type
  @type
end

Class Method Details

.get(connection, template_id) ⇒ Object

Retrieve the configuration for a report template.



682
683
684
# File 'lib/nexpose/report.rb', line 682

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

.parse(xml) ⇒ Object



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

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



672
673
674
675
676
677
678
679
# File 'lib/nexpose/report.rb', line 672

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.



662
663
664
665
666
667
668
669
670
# File 'lib/nexpose/report.rb', line 662

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



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

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