Files
metasploit-gs/lib/msfdb_helpers/db_interface.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.0 KiB
Ruby
Raw Normal View History

2021-04-30 14:24:56 +01:00
module MsfdbHelpers
class DbInterface
2021-04-30 14:24:56 +01:00
def initialize(options)
@options = options
end
2021-04-26 02:24:11 +01:00
2021-04-30 14:24:56 +01:00
def init
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def delete
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def start
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def stop
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def restart
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def status
raise NotImplementedError
end
2021-04-30 14:24:56 +01:00
def write_db_client_auth_config(client_auth_config)
puts "Writing client authentication configuration file #{client_auth_config}"
File.open(client_auth_config, 'w') do |f|
f.puts "host \"#{@options[:msf_db_name]}\" \"#{@options[:msf_db_user]}\" 127.0.0.1/32 md5"
f.puts "host \"#{@options[:msftest_db_name]}\" \"#{@options[:msftest_db_user]}\" 127.0.0.1/32 md5"
f.puts "host \"postgres\" \"#{@options[:msftest_db_user]}\" 127.0.0.1/32 md5"
f.puts 'host "template1" all 127.0.0.1/32 trust'
if Gem.win_platform?
f.puts 'host all all 127.0.0.1/32 trust'
f.puts 'host all all ::1/128 trust'
else
f.puts 'local all all trust'
end
2021-04-26 02:24:11 +01:00
end
end
2021-04-30 14:24:56 +01:00
def self.requirements
2021-05-05 14:43:12 +01:00
[]
2021-04-30 14:24:56 +01:00
end
2021-04-20 13:47:47 +01:00
2021-04-30 14:24:56 +01:00
def run_cmd(cmd, input: nil, env: {})
puts "run_cmd: cmd=#{cmd}, input=#{input}, env=#{env}" if @options[:debug]
2021-04-26 02:24:11 +01:00
2021-04-30 14:24:56 +01:00
output, status = Open3.capture2e(env, cmd)
if @options[:debug]
puts "'#{cmd}' returned #{status.exitstatus}"
puts output
end
status.exitstatus
2021-04-26 02:24:11 +01:00
end
def run_psql(cmd, socket_directory= "#{Dir.tmpdir}", db_name: 'postgres')
2021-04-30 14:24:56 +01:00
if @options[:debug]
puts "psql -h #{socket_directory} -p #{@options[:db_port]} -c \"#{cmd};\" #{db_name}"
end
2022-01-25 20:24:14 +05:30
run_cmd("psql -h #{socket_directory} -p #{@options[:db_port]} -c \"#{cmd};\" #{db_name}")
2021-04-26 02:24:11 +01:00
end
2022-01-25 20:24:14 +05:30
2021-04-26 02:24:11 +01:00
end
end