add requirements check

This commit is contained in:
dwelch-r7
2021-04-20 13:47:47 +01:00
parent f11129349b
commit ee7ad8cef3
4 changed files with 15 additions and 5 deletions
+4
View File
@@ -32,4 +32,8 @@ class DbInterface
raise NotImplementedError
end
def self.requirements
Array.new
end
end
+4
View File
@@ -102,4 +102,8 @@ class PgCtl < DbInterface
end
end
end
def self.requirements
%w(psql pg_ctl initdb createdb)
end
end
+4
View File
@@ -97,6 +97,10 @@ class PgCtlcluster < DbInterface
end
end
def self.requirements
%w(psql pg_ctlcluster pg_dropcluster pg_createcluster pg_config)
end
private
def get_postgres_version
+3 -5
View File
@@ -956,9 +956,8 @@ def installed?(cmd)
!Msf::Util::Helper.which(cmd).nil?
end
def has_requirements
def has_requirements(postgresql_cmds)
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 '%<prog>s' is not in the environment path"
@@ -1019,10 +1018,9 @@ if $PROGRAM_NAME == __FILE__
abort
end
if installed?("pg_ctl")
abort unless has_requirements
if installed?("pg_ctl") && has_requirements(PgCtl.requirements)
@db_driver = PgCtl.new(db_path: @db, options: @options, localconf: @localconf, db_conf: @db_conf)
elsif installed?("pg_ctlcluster")
elsif installed?("pg_ctlcluster") && has_requirements(PgCtlcluster.requirements)
@db_driver = PgCtlcluster.new(db_path: @db, options: @options, localconf: @localconf, db_conf: @db_conf)
else
abort