class SSHKit::Sudo::DefaultInteractionHandler

Public Class Methods

password_prompt() click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 36
def password_prompt
  @password_prompt ||= /[Pp]assword.*:/
end
password_prompt_regexp(regexp) click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 44
def password_prompt_regexp(regexp)
  @password_prompt = regexp
end
use_same_password!() click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 48
        def use_same_password!
          class_eval <<-METHOD, __FILE__, __LINE__ + 1
          def password_cache_key(host)
            '0'
          end
          METHOD
        end
wrong_password() click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 32
def wrong_password
  @wrong_password ||= /Sorry.*\stry\sagain/
end
wrong_password_regexp(regexp) click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 40
def wrong_password_regexp(regexp)
  @wrong_password = regexp
end

Public Instance Methods

on_data(command, stream_name, data, channel) click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 7
def on_data(command, stream_name, data, channel)
  if data =~ wrong_password
    puts data if defined?(Airbrussh) and
                 Airbrussh.configuration.command_output != :stdout and
                 data !~ password_prompt
    SSHKit::Sudo.password_cache[password_cache_key(command.host)] = nil
  end
  if data =~ password_prompt
    key = password_cache_key(command.host)
    pass = SSHKit::Sudo.password_cache[key]
    unless pass
      print data
      pass = $stdin.noecho(&:gets)
      puts ''
      SSHKit::Sudo.password_cache[key] = pass
    end
    channel.send_data(pass)
  end
end
password_cache_key(host) click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 27
def password_cache_key(host)
  "#{host.user}@#{host.hostname}"
end
password_prompt() click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 5
def password_prompt; self.class.password_prompt; end
wrong_password() click to toggle source
# File lib/sshkit/sudo/interaction_handler.rb, line 4
def wrong_password; self.class.wrong_password; end