CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/post/postgresql/ui/console.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
require 'rex/post/sql/ui/console'
4
5
module Rex
6
module Post
7
module PostgreSQL
8
module Ui
9
###
10
#
11
# This class provides a shell driven interface to the PostgreSQL client API.
12
#
13
###
14
class Console
15
include Rex::Post::Sql::Ui::Console
16
include Rex::Ui::Text::DispatcherShell
17
18
# Dispatchers
19
require 'rex/post/postgresql/ui/console/command_dispatcher'
20
require 'rex/post/postgresql/ui/console/command_dispatcher/core'
21
require 'rex/post/postgresql/ui/console/command_dispatcher/client'
22
23
#
24
# Initialize the PostgreSQL console.
25
#
26
# @param [Msf::Sessions::PostgreSQL] session
27
def initialize(session)
28
# The postgresql client context
29
self.session = session
30
self.client = session.client
31
prompt = "%undPostgreSQL @ #{client.peerinfo} (#{current_database})%clr"
32
history_file = Msf::Config.history_file_for_session_type(session_type: session.type, interactive: false)
33
super(prompt, '>', history_file, nil, :postgresql)
34
35
# Queued commands array
36
self.commands = []
37
38
# Point the input/output handles elsewhere
39
reset_ui
40
41
enstack_dispatcher(::Rex::Post::PostgreSQL::Ui::Console::CommandDispatcher::Core)
42
enstack_dispatcher(::Rex::Post::PostgreSQL::Ui::Console::CommandDispatcher::Client)
43
enstack_dispatcher(Msf::Ui::Console::CommandDispatcher::LocalFileSystem)
44
45
# Set up logging to whatever logsink 'core' is using
46
if ! $dispatcher['postgresql']
47
$dispatcher['postgresql'] = $dispatcher['core']
48
end
49
end
50
51
# @return [Msf::Sessions::PostgreSQL]
52
attr_reader :session
53
54
# @return [PostgreSQL::Client]
55
attr_reader :client # :nodoc:
56
57
protected
58
59
attr_writer :session, :client # :nodoc:
60
attr_accessor :commands # :nodoc:
61
end
62
end
63
end
64
end
65
end
66
67