Skip to content

Commit

Permalink
rename shell to query_interactive for sql session types, add -i flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zgoldman-r7 committed Feb 26, 2024
1 parent b91430c commit 5534b44
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
36 changes: 29 additions & 7 deletions lib/rex/post/sql/ui/console/command_dispatcher/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize(console)
def commands
cmds = {
'query' => 'Run a raw SQL query',
'shell' => 'Enter a raw shell where SQL queries can be executed',
'query_interactive' => 'Enter an interactive prompt for running multiple SQL queries',
}

reqs = {}
Expand All @@ -54,17 +54,25 @@ def help_args?(args)
args.include?('-h') || args.include?('--help')
end

def cmd_shell_help
print_line 'Usage: shell'
# @param [Array] args An array of arguments passed in to a command
# @return [TrueClass, FalseClass] True if the array contains '-i', else false.
def interactive_args?(args)
return false unless args.instance_of?(::Array)

args.include?('-i')
end

def cmd_query_interactive_help
print_line 'Usage: query_interactive, query -i'
print_line
print_line 'Go into a raw SQL shell where SQL queries can be executed.'
print_line "To exit, type 'exit', 'quit', 'end' or 'stop'."
print_line
end

def cmd_shell(*args)
def cmd_query_interactive(*args)
if help_args?(args)
cmd_shell_help
cmd_query_interactive_help
return
end

Expand Down Expand Up @@ -119,9 +127,23 @@ def run_query(query)
{ status: :success, result: result }
end

def cmd_query(*args)
if help_args?(args)
def parse_args(args)
if help_args?(args) && interactive_args?(args)
cmd_query_interactive_help
return true
elsif help_args?(args)
cmd_query_help
return true
elsif interactive_args?(args)
cmd_query_interactive
return true
else
return false
end
end

def cmd_query(*args)
if parse_args(args)
return
end

Expand Down
4 changes: 2 additions & 2 deletions lib/rex/post/sql/ui/console/interactive_sql_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _multiline

if finished
self.interacting = false
print_status 'Exiting Shell mode.'
print_status 'Exiting Interactive mode.'
return { status: :exit, result: nil }
end

Expand All @@ -116,7 +116,7 @@ def _fallback

if stop_words.include? line.chomp.downcase
self.interacting = false
print_status 'Exiting Shell mode.'
print_status 'Exiting Interactive mode.'
return { status: :exit, result: nil }
end

Expand Down

0 comments on commit 5534b44

Please sign in to comment.