Class: Msf::OptionGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/option_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, option_names: [], required_options: []) ⇒ OptionGroup

Returns a new instance of OptionGroup.

Parameters:

  • name (String)

    Name for the group

  • description (String)

    Description to be displayed to the user

  • option_names (Array<String>) (defaults to: [])

    List of datastore option names

  • required_options (Array<String>) (defaults to: [])

    List of options that if present must have a value set



19
20
21
22
23
24
# File 'lib/msf/core/option_group.rb', line 19

def initialize(name:, description:, option_names: [], required_options: [])
  self.name = name
  self.description = description
  self.option_names = option_names
  self.required_options = required_options
end

Instance Attribute Details

#descriptionString

Returns Description to be displayed to the user.

Returns:

  • (String)

    Description to be displayed to the user



9
10
11
# File 'lib/msf/core/option_group.rb', line 9

def description
  @description
end

#nameString

Returns Name for the group.

Returns:

  • (String)

    Name for the group



7
8
9
# File 'lib/msf/core/option_group.rb', line 7

def name
  @name
end

#option_namesArray<String>

Returns List of datastore option names.

Returns:

  • (Array<String>)

    List of datastore option names



11
12
13
# File 'lib/msf/core/option_group.rb', line 11

def option_names
  @option_names
end

#required_optionsArray<String>

Returns List of options that if present must have a value set.

Returns:

  • (Array<String>)

    List of options that if present must have a value set



13
14
15
# File 'lib/msf/core/option_group.rb', line 13

def required_options
  @required_options
end

Instance Method Details

#add_option(option_name) ⇒ Object

Parameters:

  • option_name (String)

    Name of the datastore option to be added to the group



27
28
29
# File 'lib/msf/core/option_group.rb', line 27

def add_option(option_name)
  @option_names << option_name
end

#add_options(option_names) ⇒ Object

Parameters:

  • option_names (Array<String>)

    List of datastore option names to be added to the group



32
33
34
# File 'lib/msf/core/option_group.rb', line 32

def add_options(option_names)
  @option_names.concat(option_names)
end

#validate(options, datastore) ⇒ Object

Validates that any registered and required options are set

Parameters:

Raises:



40
41
42
43
44
45
46
47
48
# File 'lib/msf/core/option_group.rb', line 40

def validate(options, datastore)
  issues = {}
  required_options.each do |option_name|
    if options[option_name] && !datastore[option_name]
      issues[option_name] = "#{option_name} must be specified"
    end
  end
  raise Msf::OptionValidateError.new(issues.keys.to_a, reasons: issues) unless issues.empty?
end