Skip to content

Commit

Permalink
Add PostgreSQL current database to client params and prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanusz-r7 committed Jan 9, 2024
1 parent d01587f commit ea873b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/postgres/postgres-pr/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def initialize(database, user, password=nil, uri = nil)
uri ||= DEFAULT_URI

@transaction_status = nil
@params = {}
@params = { 'username' => user, 'database' => database }
establish_connection(uri)

# Check if the password supplied is a Postgres-style md5 hash
Expand Down
15 changes: 6 additions & 9 deletions lib/rex/post/postgresql/ui/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def initialize(session)
self.session = session
self.client = session.client
prompt = "%undPostgreSQL @ #{self.client.conn.peerinfo}%clr"
history_manager = self.session.framework&.history_manager&.with_context(name: :postgresql)
super(prompt, '>', history_manager, self.session&.framework, :postgresql)
history_manager = Msf::Config.postgresql_session_history
super(prompt, '>', history_manager, nil, :postgresql)

# Queued commands array
self.commands = []
Expand Down Expand Up @@ -112,23 +112,20 @@ def log_error(msg)
# @return [PostgreSQL::Client]
attr_reader :client # :nodoc:

# TODO Should this belong elsewhere - it's required for prompt details
# @return [String]
attr_accessor :cwd

def format_prompt(val)
# TODO: How can the currently selected DB/Table/Module impact the prompt?
super
cwd = client.params['database']
prompt = "%undPostgreSQL @ #{client.conn.peerinfo} (#{cwd})%clr > "
substitute_colors(prompt, true)
end

protected

attr_writer :session # :nodoc:
attr_writer :client # :nodoc:
attr_writer :session, :client # :nodoc:
attr_accessor :commands # :nodoc:

end

end
end
end
Expand Down

0 comments on commit ea873b3

Please sign in to comment.