Class: Ronin::UI::CLI::Commands::Campaigns

Inherits:
ResourcesCommand show all
Defined in:
lib/ronin/ui/cli/commands/campaigns.rb

Overview

The ronin-campaigns command.

Instance Method Summary collapse

Methods inherited from ResourcesCommand

model, #print_resources

Methods inherited from ModelCommand

each_query_option, model, #query, query_option, query_options, #setup

Methods inherited from Ronin::UI::CLI::Command

banner, command_name, #indent, inherited, #initialize, #print_array, #print_exception, #print_hash, #print_section, #print_title, #puts, run, #setup

Constructor Details

This class inherits a constructor from Ronin::UI::CLI::Command

Instance Method Details

#add(name) ⇒ Object (protected)

Adds a new campaign.

Parameters:

  • name (String)

    The name of the new campaign.

Since:

  • 1.0.0



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ronin/ui/cli/commands/campaigns.rb', line 81

def add(name)
  campaign = Campaign.new(:name => name)

  # add targets to the campaign
  options[:targets].each { |target| campaign.target!(target) }

  if campaign.save
    print_info "Added campaign #{campaign}"
  else
    print_error "Could not add campaign #{name.dump}."
  end
end

#executeObject

Queries the Campaign model.

Since:

  • 1.0.0



63
64
65
66
67
68
69
# File 'lib/ronin/ui/cli/commands/campaigns.rb', line 63

def execute
  if options[:add]
    add options[:add]
  elsif options.list?
    super
  end
end

Prints a campaign.

Parameters:

  • campaign (Campaign)

    The campaign to print.

Since:

  • 1.0.0



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/ronin/ui/cli/commands/campaigns.rb', line 102

def print_resource(campaign)
  return super(campaign) unless options.verbose?

  print_title campaign.name

  indent do
    if campaign.description
      print_section 'Description' do
        campaign.description.each_line do |line|
          puts line
        end
      end
    end

    unless campaign.organizations.empty?
      print_array campaign.organizations, :title => 'Targeted Organizations'
    end

    unless campaign.targets.empty?
      print_array campaign.targets, :title => 'Targets'
    end
  end
end