Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/parsed_options/base.rb
Views: 11784
#1# Standard Library2#34require 'optparse'56#7# Gems8#910require 'active_support/ordered_options'1112#13# Project14#1516require 'metasploit/framework/database'17require 'metasploit/framework/parsed_options'1819# Options parsed from the command line that can be used to change the20# `Metasploit::Framework::Application.config` and `Rails.env`21class Metasploit::Framework::ParsedOptions::Base22#23# CONSTANTS24#2526# msfconsole boots in production mode instead of the normal rails default of27# development.28DEFAULT_ENVIRONMENT = 'production'2930#31# Attributes32#3334attr_reader :positional3536#37# Instance Methods38#3940def initialize(arguments=ARGV)41begin42@positional = option_parser.parse(arguments)43rescue OptionParser::InvalidOption44puts "ERROR: Invalid command line option provided."45puts option_parser46exit(1)47end48end4950# Translates {#options} to the `application`'s config51#52# @param application [Rails::Application]53# @return [void]54def configure(application)55application.config['config/database'] = options.database.config56end5758# Sets the `RAILS_ENV` environment variable.59#60# 1. If the -E/--environment option is given, then its value is used.61# 2. The default value, 'production', is used.62#63# @return [void]64def environment!65if defined?(Rails) && Rails.instance_variable_defined?(:@_env) && Rails.env != options.environment66raise "#{self.class}##{__method__} called too late to set RAILS_ENV: Rails.env already memoized"67end6869ENV['RAILS_ENV'] = options.environment70end7172# Options parsed from73#74# @return [ActiveSupport::OrderedOptions]75def options76unless @options77options = ActiveSupport::OrderedOptions.new7879options.database = ActiveSupport::OrderedOptions.new8081options.database.config = Metasploit::Framework::Database.configurations_pathname.try(:to_path)82options.database.disable = false83options.database.migrations_paths = []8485# If RAILS_ENV is set, then it will be used, but if RAILS_ENV is set and the --environment option is given, then86# --environment value will be used to reset ENV[RAILS_ENV].87options.environment = ENV['RAILS_ENV'] || DEFAULT_ENVIRONMENT8889options.framework = ActiveSupport::OrderedOptions.new90options.framework.config = nil9192options.modules = ActiveSupport::OrderedOptions.new93options.modules.defer_loads = nil94options.modules.path = nil9596@options = options97end9899@options100end101102private103104# Parses arguments into {#options}.105#106# @return [OptionParser]107def option_parser108@option_parser ||= OptionParser.new { |option_parser|109option_parser.separator ''110option_parser.separator 'Common options:'111112option_parser.on(113'-E',114'--environment ENVIRONMENT',115%w{development production test},116"Set Rails environment, defaults to RAIL_ENV environment variable or 'production'"117) do |environment|118options.environment = environment119end120121option_parser.separator ''122option_parser.separator 'Database options:'123124option_parser.on(125'-M',126'--migration-path DIRECTORY',127'Specify a directory containing additional DB migrations'128) do |directory|129options.database.migrations_paths << directory130end131132option_parser.on('-n', '--no-database', 'Disable database support') do133options.database.disable = true134end135136option_parser.on(137'-y',138'--yaml PATH',139'Specify a YAML file containing database settings'140) do |path|141options.database.config = path142end143144option_parser.separator ''145option_parser.separator 'Framework options:'146147148option_parser.on('-c', '-c FILE', 'Load the specified configuration file') do |file|149options.framework.config = file150end151152option_parser.on(153'-v','-V',154'--version',155'Show version'156) do157options.subcommand = :version158end159160option_parser.separator ''161option_parser.separator 'Module options:'162163option_parser.on(164'--[no-]defer-module-loads',165'Defer module loading unless explicitly asked'166) do |value|167options.modules.defer_loads = value168end169170option_parser.on(171'-m',172'--module-path DIRECTORY',173'Load an additional module path'174) do |directory|175options.modules.path = directory176end177178#179# Tail180#181182option_parser.separator ''183option_parser.on_tail('-h', '--help', 'Show this message') do184puts option_parser185exit186end187}188end189end190191192