Class: CliSSH

Inherits:
Cli
  • Object
show all
Defined in:
lib/mpw/ui/clissh.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Cli

#add, #decrypt, #delete, #display, #display_item, #export, #import, #initialize, #setup, #setup_gpg_key, #sync, #update

Constructor Details

This class inherits a constructor from Cli

Instance Attribute Details

#loginObject

Returns the value of attribute login.



10
11
12
# File 'lib/mpw/ui/clissh.rb', line 10

def 
  @login
end

#portObject

Returns the value of attribute port.



10
11
12
# File 'lib/mpw/ui/clissh.rb', line 10

def port
  @port
end

#serverObject

Returns the value of attribute server.



10
11
12
# File 'lib/mpw/ui/clissh.rb', line 10

def server
  @server
end

Instance Method Details

#ssh(search) ⇒ Object

Connect to SSH args: search -> string to search



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mpw/ui/clissh.rb', line 14

def ssh(search)
  result = @mpw.search(search, nil, 'ssh')

  if result.length > 0
    result.each do |r|
      server = @server.nil? ? r[:host]  : @server
      port   = @port.nil?   ? r[:port]  : @port
        = @login.nil?  ? r[:login] : @login

      passwd = r[:password]

      if port.nil? and port.empty?
        port = 22
      end

      puts "#{I18n.t('ssh.display.connect')} ssh #{login}@#{server} -p #{port}"
      if passwd.empty?
        system("ssh #{login}@#{server} -p #{port}")
      else
        system("sshpass -p '#{passwd}' ssh #{login}@#{server} -p #{port}")
      end
    end

  else
    puts I18n.t('ssh.display.nothing')
  end
end