Clear the default database connection if using database only

This commit is contained in:
dwelch-r7
2021-05-20 01:08:47 +01:00
parent 2c94c7cd85
commit 962dcf1ae7
2 changed files with 43 additions and 6 deletions
+27 -5
View File
@@ -32,11 +32,12 @@ class Db
#
def commands
base = {
"db_connect" => "Connect to an existing data service",
"db_disconnect" => "Disconnect from the current data service",
"db_status" => "Show the current data service status",
"db_save" => "Save the current data service connection as the default to reconnect on startup",
"db_remove" => "Remove the saved data service entry"
"db_connect" => "Connect to an existing data service",
"db_disconnect" => "Disconnect from the current data service",
"db_status" => "Show the current data service status",
"db_save" => "Save the current data service connection as the default to reconnect on startup",
"db_remove" => "Remove the saved data service entry",
"db_clear_default" => "Clears the default data service connection used on startup"
}
more = {
@@ -1890,6 +1891,27 @@ class Db
end
end
def cmd_db_clear_default_help(*args)
print_line "Usage: db_clear_default"
print_line
print_line "Clears the default data service connection used on startup."
print_line
end
def cmd_db_clear_default(*args)
while (arg = args.shift)
case arg
when '-h', '--help'
cmd_db_clear_default_help
return
end
end
clear_default_db
end
def save_db_to_config(database, database_name)
if database_name =~ /\/|\[|\]/
raise ArgumentError, 'Data service name contains an invalid character.'
+16 -1
View File
@@ -640,6 +640,17 @@ def persist_data_service
end
end
def clear_default_data_service
# execute msfconsole commands to add and persist the data service connection
cmd = "./msfconsole -qx db_clear_default; exit\""
if @db_driver.run_cmd(cmd) != 0
# attempt to execute msfconsole in the current working directory
if @db_driver.run_cmd(cmd, env: {'PATH' => ".:#{ENV["PATH"]}"}) != 0
puts 'Failed to run msfconsole and clear the default data service connection'
end
end
end
def get_db_connect_command
data_service_name = "local-#{@options[:ssl] ? 'https' : 'http'}-data-service"
if !@options[:data_service_name].nil?
@@ -1001,11 +1012,15 @@ if $PROGRAM_NAME == __FILE__
parse_args(ARGV)
unless @component_provided
if ask_yn_default('Would you also like to start up the webservice?', false)
if ask_yn_default('Would you also like this operation to affect the webservice?', false)
@options[:component] = :all
end
end
if @options[:database]
clear_default_data_service
end
update_db_port
if @connection_string