Class: Dradis::Plugins::Coreimpact::Importer

Inherits:
Upload::Importer
  • Object
show all
Defined in:
lib/dradis/plugins/coreimpact/importer.rb

Instance Method Summary collapse

Instance Method Details

#import(params = {}) ⇒ Object

The framework will call this function if the user selects this plugin from the dropdown list and uploads a file.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dradis/plugins/coreimpact/importer.rb', line 6

def import(params={})

  file_content = File.read( params[:file] )

  # Parse the uploaded file XML
  logger.info { "Parsing CORE Impact output file... #{params[:file]}" }
  @doc = Nokogiri::XML( file_content )
  logger.info { 'Done.' }

  if @doc.xpath('/entities').empty?
    logger.error "ERROR: no '<entities>' root element present in the provided "\
                 "data. Are you sure you uploaded a CORE Impact file?"
    return false
  end

  @doc.xpath('/entities/entity[@class="host"]').each do |xml_entity|
    add_host(xml_entity)
  end
end