From e81f2e366c8d757ec0780f74dc1874b517f81baa Mon Sep 17 00:00:00 2001 From: William Vu Date: Tue, 10 Mar 2015 12:35:58 -0500 Subject: [PATCH] Refactor db_{status,connect} a bit Also allow for db_connect help. --- lib/msf/ui/console/command_dispatcher/db.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index 25016d904c..0ba92f5c4c 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -1688,11 +1688,11 @@ class Db if framework.db.connection_established? cdb = "" - ::ActiveRecord::Base.connection_pool.with_connection { |conn| - if conn.respond_to? :current_database + ::ActiveRecord::Base.connection_pool.with_connection do |conn| + if conn.respond_to?(:current_database) cdb = conn.current_database end - } + end print_status("#{framework.db.driver} connected to #{cdb}") else print_status("#{framework.db.driver} selected, no connection") @@ -1706,16 +1706,16 @@ class Db def cmd_db_connect(*args) return if not db_check_driver - if framework.db.connection_established? + if args[0] != '-h' && framework.db.connection_established? cdb = "" - ::ActiveRecord::Base.connection_pool.with_connection { |conn| - if conn.respond_to? :current_database + ::ActiveRecord::Base.connection_pool.with_connection do |conn| + if conn.respond_to?(:current_database) cdb = conn.current_database end - } - status = "#{framework.db.driver} already connected to #{cdb}. " - status += "Run db_disconnect first if you wish to connect to a different database." - return print_status(status) + end + print_status("#{framework.db.driver} already connected to #{cdb}. " + + "Run db_disconnect first if you wish to connect to a different database.") + return end if (args[0] == "-y") if (args[1] and not ::File.exists? ::File.expand_path(args[1]))