Class: Shaddox::Server::SSHActor
Instance Method Summary collapse
- #exec(command, opts = {:verbose => true}) ⇒ Object
-
#initialize(host, user, ssh_opts, &block) ⇒ SSHActor
constructor
A new instance of SSHActor.
- #write_file(content, dest_path) ⇒ Object
Constructor Details
#initialize(host, user, ssh_opts, &block) ⇒ SSHActor
Returns a new instance of SSHActor.
117 118 119 120 121 122 |
# File 'lib/shaddox/target.rb', line 117 def initialize(host, user, ssh_opts, &block) Net::SSH.start(host, user, ssh_opts) do |ssh| @ssh = ssh super(&block) end end |
Instance Method Details
#exec(command, opts = {:verbose => true}) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/shaddox/target.rb', line 123 def exec(command, opts = {:verbose => true}) require 'highline/import' exit_code = nil @ssh.open_channel do |channel| channel.request_pty do |c, success| raise "SSH could not obtain a pty." unless success channel.exec(command) channel.on_data do |c_, data| if data =~ /\[sudo\]/ || data =~ /Password/i warn "Target is asking for password: ", 1 $stdout.print data pass = ask("") { |q| q.echo = false } channel.send_data "#{pass}\n" else $stdout.print data if opts[:verbose] end end channel.on_request('exit-status') do |ch, data| exit_code = data.read_long end end end @ssh.loop exit_code == 0 ? true : false end |
#write_file(content, dest_path) ⇒ Object
148 149 150 151 |
# File 'lib/shaddox/target.rb', line 148 def write_file(content, dest_path) require 'shellwords' exec "echo #{Shellwords.shellescape(content)} > #{dest_path}" end |