Add check for required commands

GSoC/Meterpreter_Web_Console
Matthew Kienow 2018-09-28 13:41:03 -04:00
parent 5d927399c7
commit 55cf17bf15
No known key found for this signature in database
GPG Key ID: 40787F8B1EAC6E41
1 changed files with 44 additions and 0 deletions

44
msfdb
View File

@ -906,6 +906,46 @@ def invoke_command(commands, component, command)
end
end
# Searches the user's path for the executable file that would be run had the
# command actually been invoked.
# @param cmd [String] command name
# @param return_all [Boolean] If true, returns a list of all instances of
# executable found (instead of just the first one). Default: false.
# @return [Array] instance or instances of executable found based on return_all, or nil.
def which(cmd, return_all: false)
return nil if cmd.empty?
found = []
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exe_file = File.join(path, cmd)
found << exe_file if !File.directory?(exe_file) && File.executable?(exe_file)
break if !return_all && found.size > 0
end
return found.empty? ? nil : found
end
def has_requirements
ret_val = true
postgresql_cmds = %w(psql pg_ctl initdb createdb)
other_cmds = %w(bundle thin)
missing_msg = 'Missing requirement: %<name>s does not appear to be installed or is not in the environment path'
unless postgresql_cmds.all? { |cmd| !which(cmd).nil? }
puts missing_msg % { name: 'PostgreSQL' }
ret_val = false
end
other_cmds.each do |cmd|
if which(cmd).nil?
puts missing_msg % { name: "'#{cmd}'" }
ret_val = false
end
end
ret_val
end
if $PROGRAM_NAME == __FILE__
@ -915,6 +955,10 @@ if $PROGRAM_NAME == __FILE__
abort
end
unless has_requirements
abort
end
# map component commands to methods
commands = {
database: {