cleans up logging for multiple component commands

This commit is contained in:
A Galway 2020-11-05 16:02:48 +00:00
parent 5fbe243662
commit 0aead044e3
No known key found for this signature in database
GPG Key ID: EC5AF4B99AB94D70
1 changed files with 27 additions and 12 deletions

39
msfdb Executable file → Normal file
View File

@ -187,7 +187,8 @@ end
def start_db def start_db
if !Dir.exist?(@db) if !Dir.exist?(@db)
puts "No database found at #{@db}, not starting" print_error "No database found at #{@db}."
print_error "Has the database been initialized with \"msfdb init\" or \"msfdb init --component database\"?"
return return
end end
@ -517,6 +518,14 @@ def start_web_service(expect_auth: true)
# daemonize MSF web service # daemonize MSF web service
print 'Attempting to start MSF web service...' print 'Attempting to start MSF web service...'
unless File.file?(@ws_ssl_key_default)
puts "#{'failed'.red.bold}"
print_error "The SSL Key needed for the webservice to connect to the database could not be found at #{@ws_ssl_key_default}."
print_error 'Has the webservice been initialized with "msfdb init" or "msfdb init --component webservice"?'
return false
end
if run_cmd("#{thin_cmd} start") == 0 if run_cmd("#{thin_cmd} start") == 0
# wait until web service is online # wait until web service is online
retry_count = 0 retry_count = 0
@ -533,18 +542,19 @@ def start_web_service(expect_auth: true)
end end
if response_data[:state] == :online if response_data[:state] == :online
puts "#{'success'.green.bold}" puts "#{'success'.green.bold}"
puts 'MSF web service started and online' puts 'MSF web service started and online'
return true return true
elsif response_data[:state] == :error elsif response_data[:state] == :error
puts "#{'failed'.red.bold}" puts "#{'failed'.red.bold}"
print_error 'MSF web service appears to be started, but may not operate as expected.' print_error 'MSF web service failed and returned the following message:'
puts "#{response_data[:message]}" puts "#{response_data[:message].nil? || response_data[:message].empty? ? "No message returned." : response_data[:message]}"
else elsif response_data[:state] == :offline
puts "#{'failed'.red.bold}" puts "#{'failed'.red.bold}"
print_error 'MSF web service does not appear to be started.' print_error 'A connection with the web service was refused.'
end end
puts "Please see #{@ws_log} for additional details."
puts "Please see #{@ws_log} for additional webservice details."
return false return false
else else
puts "#{'failed'.red.bold}" puts "#{'failed'.red.bold}"
@ -1082,9 +1092,14 @@ if $PROGRAM_NAME == __FILE__
prompt_for_deletion(command) prompt_for_deletion(command)
if @options[:component] == :all if @options[:component] == :all
@components.each { |component| @components.each { |component|
puts '===================================================================='
puts "Running the '#{command}' command for the #{component}:"
invoke_command(commands, component.to_sym, command) invoke_command(commands, component.to_sym, command)
puts '===================================================================='
puts
} }
else else
puts "Running the '#{command}' command for the #{@options[:component].to_s}:"
invoke_command(commands, @options[:component], command) invoke_command(commands, @options[:component], command)
end end
end end