Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow a database config file to be specified

git-svn-id: file:///home/svn/framework3/trunk@10743 4d416f70-5f16-0410-b530-b9f4589650da
  • Loading branch information...
commit f5f7f555b063ee1f6afbd01813d357be1a71cd80 1 parent ff7162a
@hmoore-r7 hmoore-r7 authored
Showing with 24 additions and 0 deletions.
  1. +16 −0 lib/msf/ui/console/driver.rb
  2. +8 −0 msfconsole
View
16 lib/msf/ui/console/driver.rb
@@ -147,6 +147,22 @@ def initialize(prompt = DefaultPrompt, prompt_char = DefaultPromptChar, opts = {
if @defanged
self.command_passthru = false
end
+
+ # Parse any specified database.yml file
+ if framework.db.usable and opts['DatabaseYAML']
+ dbinfo = YAML.load(File.read(opts['DatabaseYAML']))
+ dbenv = opts['DatabaseEnv'] || "production"
+ db = dbinfo[dbenv]
+
+ if not db
+ print_error("No database definition for environment #{dbenv}")
+ else
+ if not framework.db.connect(db)
+ print_error("Failed to connect to the database: #{framework.db.error} #{db.inspect} #{framework.db.error.backtrace}")
+ end
+ end
+ end
+
# Process things before we actually display the prompt and get rocking
on_startup
View
8 msfconsole
@@ -54,6 +54,14 @@ class OptsConsole
options['ModulePath'] = m
end
+ opts.on("-y", "--yaml <database.yml>", "Specify a YAML file containing database settings") do |m|
+ options['DatabaseYAML'] = m
+ end
+
+ opts.on("-e", "--environment <production|development>", "Specify the database environment to load from the YAML") do |m|
+ options['DatabaseEnv'] = m
+ end
+
# Boolean switch.
opts.on("-v", "--version", "Show version") do |v|
options['Version'] = true
Please sign in to comment.
Something went wrong with that request. Please try again.