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/database.rb
Views: 11779
require 'metasploit/framework'12module Metasploit3module Framework4module Database5#6# CONSTANTS7#89CONFIGURATIONS_PATHNAME_PRECEDENCE = [10:environment_configurations_pathname,11:user_configurations_pathname,12:project_configurations_pathname13]1415#16# Module Methods17#1819# Returns first configuration pathname from configuration_pathnames or the overriding `:path`.20#21# @param options [Hash{Symbol=>String}]22# @option options [String] :path Path to use instead of first element of configurations_pathnames23# @return [Pathname] if configuration pathname exists.24# @return [nil] if configuration pathname does not exist.25def self.configurations_pathname(options={})26options.assert_valid_keys(:path)2728path = options[:path]2930if path.present?31pathname = Pathname.new(path)32else33pathname = configurations_pathnames.first34end3536if !pathname.nil? && pathname.exist?37pathname38else39nil40end41end4243# Return configuration pathnames that exist.44#45# Returns `Pathnames` in order of precedence46#47# 1. {environment_configurations_pathname}48# 2. {user_configurations_pathname}49# 3. {project_configurations_pathname}50#51# @return [Array<Pathname>]52def self.configurations_pathnames53configurations_pathnames = []5455CONFIGURATIONS_PATHNAME_PRECEDENCE.each do |configurations_pathname_message|56configurations_pathname = public_send(configurations_pathname_message)5758if !configurations_pathname.nil? && configurations_pathname.exist?59configurations_pathnames << configurations_pathname60end61end6263configurations_pathnames64end6566# Pathname to `database.yml` pointed to by `MSF_DATABASE_CONFIG` environment variable.67#68# @return [Pathname] if `MSF_DATABASE_CONFIG` is not blank.69# @return [nil] otherwise70def self.environment_configurations_pathname71msf_database_config = ENV['MSF_DATABASE_CONFIG']7273if msf_database_config.blank?74msf_database_config = nil75else76msf_database_config = Pathname.new(msf_database_config)77end7879msf_database_config80end8182# Pathname to `database.yml` for the metasploit-framework project in `config/database.yml`.83#84# @return [Pathname]85def self.project_configurations_pathname86root = Pathname.new(__FILE__).realpath.parent.parent.parent.parent87root.join('config', 'database.yml')88end8990# Pathname to `database.yml` in the user's config directory.91#92# @return [Pathname] if the user has a `database.yml` in their config directory (`~/.msf4` by default).93# @return [nil] if the user does not have a `database.yml` in their config directory.94def self.user_configurations_pathname95Pathname.new(Msf::Config.config_directory).join('database.yml')96end97end98end99end100101102