Module: Dradis::Plugins::ContentService::Nodes

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/dradis/plugins/content_service/nodes.rb

Instance Method Summary collapse

Instance Method Details

#create_node(args = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dradis/plugins/content_service/nodes.rb', line 20

def create_node(args={})
  label  = args[:label]  || default_node_label
  parent = args[:parent] || default_node_parent

  type_id = begin
    if args[:type]
      tmp_type = args[:type].to_s.upcase
      if Node::Types::const_defined?(tmp_type)
        "Node::Types::#{tmp_type}".constantize
      else
        default_node_type
      end
    else
      default_node_type
    end
  end

  new_node = parent.children.find_or_initialize_by(
    label: label,
    type_id: type_id
  )
  # `Node#project_id` method does not exist in CE. We set the project for
  # `new_node` once it is initialized using `Node#project=`
  new_node.project = parent.project
  new_node.save
  new_node
end

#reporting_nodesObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/dradis/plugins/content_service/nodes.rb', line 5

def reporting_nodes
  nodes = []

  nodes |= nodes_from_evidence
  nodes |= nodes_from_properties

  # Note that the below sorting would the non-IP nodes first, then the IP
  # nodes, and will sort them by each octet.
  #
  # See:
  #  http://stackoverflow.com/questions/13996033/sorting-an-array-in-ruby-special-case
  #  http://tech.maynurd.com/archives/124
  nodes.sort_by! { |node| node.label.split('.').map(&:to_i) }
end