2015-10-08 21:23:17 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Dominik Richter
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
module Vulcano
|
|
|
|
class Shell
|
|
|
|
def initialize(runner)
|
|
|
|
@runner = runner
|
|
|
|
# load and configure pry
|
|
|
|
require 'pry'
|
|
|
|
configure_pry
|
|
|
|
end
|
2015-10-08 21:23:17 +00:00
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
def start
|
|
|
|
# store context to run commands in this context
|
|
|
|
@runner.add_content('binding.pry', __FILE__, __LINE__)
|
|
|
|
@runner.run
|
2015-10-08 21:23:17 +00:00
|
|
|
end
|
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
def configure_pry
|
|
|
|
# Remove all hooks and checks
|
|
|
|
Pry.hooks.clear_all
|
|
|
|
that = self
|
|
|
|
|
|
|
|
# Add the help command
|
|
|
|
Pry::Commands.block_command 'usage', 'Show examples' do
|
|
|
|
that.usage
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add a help menu as the default intro
|
|
|
|
Pry.hooks.add_hook(:before_session, :intro) do
|
|
|
|
intro
|
|
|
|
end
|
2015-10-08 21:23:17 +00:00
|
|
|
end
|
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
def mark(x)
|
|
|
|
"\033[1m#{x}\033[0m"
|
|
|
|
end
|
2015-10-08 21:23:17 +00:00
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
def intro
|
|
|
|
puts 'Welcome to the interactive Vulcano Shell'
|
|
|
|
puts "To find out how to use it, type: #{mark 'usage'}"
|
|
|
|
puts
|
|
|
|
end
|
2015-10-08 21:23:17 +00:00
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
def usage
|
|
|
|
ctx = @runner.backend
|
|
|
|
puts <<EOF
|
2015-10-08 21:23:17 +00:00
|
|
|
|
|
|
|
Welcome to the interactive Vulcano Shell.
|
|
|
|
|
|
|
|
You can use resources in this environment to test the target machine.
|
|
|
|
For example:
|
|
|
|
|
|
|
|
command('uname -a').stdout
|
|
|
|
file('/proc/cpuinfo').content
|
|
|
|
|
|
|
|
You are currently running on:
|
|
|
|
|
2015-10-10 21:15:05 +00:00
|
|
|
OS family: #{mark ctx.os[:family] || 'unknown'}
|
|
|
|
OS release: #{mark ctx.os[:release] || 'unknown'}
|
2015-10-08 21:23:17 +00:00
|
|
|
|
|
|
|
EOF
|
2015-10-10 21:15:05 +00:00
|
|
|
end
|
2015-10-08 21:23:17 +00:00
|
|
|
end
|
|
|
|
end
|