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/require.rb
Views: 11779
# @note needs to use explicit nesting. so this file can be loaded directly without loading 'metasploit/framework', this1# file can be used prior to Bundler.require.2module Metasploit3module Framework4# Extension to `Kernel#require` behavior.5module Require6#7# Module Methods8#910# Tries to require `name`. If a `LoadError` occurs, then `without_warning` is printed to standard error using11# `Kernel#warn`, along with instructions for reinstalling the bundle. If a `LoadError` does not occur, then12# `with_block` is called.13#14# @param name [String] the name of the library to `Kernel#require`.15# @param without_warning [String] warning to print if `name` cannot be required.16# @yield block to run when `name` requires successfully17# @yieldreturn [void]18# @return [void]19def self.optionally(name, without_warning)20begin21require name22rescue LoadError23warn without_warning24warn "Bundle installed '--without #{Bundler.settings.without.join(' ')}'"25warn "To clear the without option do `bundle install --without ''` " \26"(the --without flag with an empty string) or " \27"`rm -rf .bundle` to remove the .bundle/config manually and " \28"then `bundle install`"29else30if block_given?31yield32end33end34end3536# Tries to `require 'active_record/railtie'` to define the activerecord Rails initializers and rake tasks.37#38# @example Optionally requiring 'active_record/railtie'39# require 'metasploit/framework/require'40#41# class MyClass42# def setup43# if database_enabled44# Metasploit::Framework::Require.optionally_active_record_railtie45# end46# end47# end48#49# @return [void]50def self.optionally_active_record_railtie51if ::Rails.application.config.paths['config/database'].any?52optionally(53'active_record/railtie',54'activerecord not in the bundle, so database support will be disabled.'55)56else57warn 'Could not find database.yml, so database support will be disabled.'58end59end6061# Tries to `require 'metasploit/credential'` and include `Metasploit::Credential::Creation` in the62# `including_module`.63#64# @param including_module [Module] `Class` or `Module` that wants to `include Metasploit::Credential::Creation`.65# @return [void]66def self.optionally_include_metasploit_credential_creation(including_module)67optionally(68'metasploit/credential',69"metasploit-credential not in the bundle, so Metasploit::Credential creation will fail for #{including_module.name}"70) do71including_module.send(:include, Metasploit::Credential::Creation)72end73end7475# Tries to require gems necessary for using a database with the framework.76#77# @example78# Metasploit::Framework::Require.optionally_require_metasploit_db_gems79#80# @return [void]81def self.optionally_require_metasploit_db_gem_engines82optionally(83'metasploit/credential',84'metasploit-credential not in the bundle',85) do86require 'metasploit/credential/engine'87end8889optionally(90'metasploit_data_models',91'metasploit_data_models not in the bundle'92) do93require 'metasploit_data_models/engine'94end95end9697#98# Instance Methods99#100101# Tries to `require 'metasploit/credential/creation'` and include it in this `Class` or `Module`.102#103# @example Using in a `Module`104# require 'metasploit/framework/require'105#106# module MyModule107# extend Metasploit::Framework::Require108#109# optionally_include_metasploit_credential_creation110# end111#112# @return [void]113def optionally_include_metasploit_credential_creation114Metasploit::Framework::Require.optionally_include_metasploit_credential_creation(self)115end116end117end118end119120121