Module: Rex::Ui::Text::DispatcherShell::CommandDispatcher

Included in:
Post::Meterpreter::Ui::Console::CommandDispatcher
Defined in:
lib/rex/ui/text/dispatcher_shell.rb

Overview

Empty template base class for command dispatchers.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#shellObject

No tab completion items by default



134
135
136
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 134

def shell
  @shell
end

#tab_complete_itemsObject

No tab completion items by default



134
135
136
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 134

def tab_complete_items
  @tab_complete_items
end

Instance Method Details

#cmd_help(cmd = nil, *ignored) ⇒ Object Also known as: cmd_?

Displays the help banner. With no arguments, this is just a list of all commands grouped by dispatcher. Otherwise, tries to use a method named cmd_#<code>cmd</code>_help for the first dispatcher that has a command named cmd.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 89

def cmd_help(cmd=nil, *ignored)
	if cmd
		help_found = false
		cmd_found = false
		shell.dispatcher_stack.each do |dispatcher|
			next unless dispatcher.respond_to?(:commands)
			next if (dispatcher.commands.nil?)
			next if (dispatcher.commands.length == 0)

			if dispatcher.respond_to?("cmd_#{cmd}")
				cmd_found = true
				break unless dispatcher.respond_to? "cmd_#{cmd}_help"
				dispatcher.send("cmd_#{cmd}_help")
				help_found = true
				break
			end
		end
		print_error("No help for #{cmd}, try -h") if cmd_found and not help_found
		print_error("No such command") if not cmd_found
	else
		print(shell.help_to_s)
	end
end

#cmd_help_tabs(str, words) ⇒ Object

Tab completion for the help command

By default just returns a list of all commands in all dispatchers.



118
119
120
121
122
123
124
125
126
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 118

def cmd_help_tabs(str, words)
	return [] if words.length > 1

	tabs = []
	shell.dispatcher_stack.each { |dispatcher|
		tabs += dispatcher.commands.keys
	}
	return tabs
end

#commandsObject

Returns nil for an empty set of commands.



38
39
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 38

def commands
end

#initialize(shell) ⇒ Object

Initializes the command dispatcher mixin.



30
31
32
33
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 30

def initialize(shell)
	self.shell = shell
	self.tab_complete_items = []
end

Wraps shell.print



72
73
74
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 72

def print(msg = '')
	shell.print(msg)
end

Wraps shell.print_error



44
45
46
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 44

def print_error(msg = '')
	shell.print_error(msg)
end

Wraps shell.print_good



65
66
67
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 65

def print_good(msg = '')
	shell.print_good(msg)
end

Wraps shell.print_line



58
59
60
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 58

def print_line(msg = '')
	shell.print_line(msg)
end

Wraps shell.print_status



51
52
53
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 51

def print_status(msg = '')
	shell.print_status(msg)
end

#tab_complete_filenames(str, words) ⇒ Object

Provide a generic tab completion for file names.

If the only completion is a directory, this descends into that directory and continues completions with filenames contained within.



142
143
144
145
146
147
148
149
150
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 142

def tab_complete_filenames(str, words)
	matches = ::Readline::FILENAME_COMPLETION_PROC.call(str)
	if matches and matches.length == 1 and File.directory?(matches[0])
		dir = matches[0]
		dir += File::SEPARATOR if dir[-1,1] != File::SEPARATOR
		matches = ::Readline::FILENAME_COMPLETION_PROC.call(dir) 
	end
	matches
end

#update_prompt(prompt = nil) ⇒ Object

Wraps shell.update_prompt



79
80
81
# File 'lib/rex/ui/text/dispatcher_shell.rb', line 79

def update_prompt(prompt=nil)
	shell.update_prompt(prompt)
end