Allow a database config file to be specified

git-svn-id: file:///home/svn/framework3/trunk@10743 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2010-10-19 07:51:58 +00:00
parent ff7162aa2e
commit f5f7f555b0
2 changed files with 24 additions and 0 deletions

View File

@ -147,6 +147,22 @@ class Driver < Msf::Ui::Driver
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 File

@ -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