mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 22:03:05 +00:00
42 lines
936 B
Ruby
42 lines
936 B
Ruby
#!/usr/bin/ruby
|
|
# author: nishiki
|
|
# mail: nishiki@yaegashi.fr
|
|
# info: a simple script who manage your passwords
|
|
|
|
require "#{APP_ROOT}/MPW/UI/Cli"
|
|
|
|
class CliSSH < Cli
|
|
|
|
attr_accessor :server, :port, :login
|
|
|
|
# Connect to SSH
|
|
# args: search -> string to search
|
|
def ssh(search)
|
|
result = @mpw.search(search, nil, 'ssh')
|
|
|
|
if result.length > 0
|
|
result.each do |r|
|
|
server = @server.nil? ? r[MPW::MPW::SERVER] : @server
|
|
port = @port.nil? ? r[MPW::MPW::PORT] : @port
|
|
login = @login.nil? ? r[MPW::MPW::LOGIN] : @login
|
|
|
|
passwd = r[MPW::MPW::PASSWORD]
|
|
|
|
if port.nil? || 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
|
|
end
|
|
|