Module: Msf::DBManager::HostTag

Included in:
Msf::DBManager
Defined in:
lib/msf/core/db_manager/host_tag.rb

Instance Method Summary collapse

Instance Method Details

#report_host_tag(opts) ⇒ Object

This is only exercised by MSF3 XML importing for now. Needs the wait conditions and return hash as well.

Raises:


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/msf/core/db_manager/host_tag.rb', line 4

def report_host_tag(opts)
  name = opts.delete(:name)
  raise Msf::DBImportError.new("Missing required option :name") unless name
  addr = opts.delete(:addr)
  raise Msf::DBImportError.new("Missing required option :addr") unless addr
::ApplicationRecord.connection_pool.with_connection {
  wspace = Msf::Util::DBManager.process_opts_workspace(opts, framework)
  raise Msf::DBImportError.new("Missing required option :workspace") unless wspace
  host = nil
  report_host(:workspace => wspace, :address => addr)


  host = get_host(:workspace => wspace, :address => addr)
  desc = opts[:desc]
  summary = opts[:summary]
  detail = opts[:detail]
  crit = opts[:crit]
  possible_tags = Mdm::Tag.includes(:hosts).where("hosts.workspace_id = ? and tags.name = ?", wspace.id, name).order("tags.id DESC").limit(1)
  tag = (possible_tags.blank? ? Mdm::Tag.new : possible_tags.first)
  tag.name = name
  tag.desc = desc
  tag.report_summary = !!summary
  tag.report_detail = !!detail
  tag.critical = !!crit
  tag.hosts = tag.hosts | [host]
  tag.save! if tag.changed?
}
end