2013-08-06 20:24:09 +00:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
# author: nishiki
|
|
|
|
# mail: nishiki@yaegashi.fr
|
|
|
|
# info: a simple script who manage your passwords
|
|
|
|
|
2014-01-29 19:49:39 +00:00
|
|
|
require "#{APP_ROOT}/MPW/UI/Cli"
|
2013-08-06 20:24:09 +00:00
|
|
|
|
|
|
|
class CliSSH < Cli
|
|
|
|
|
2013-08-24 22:55:11 +00:00
|
|
|
attr_accessor :server, :port, :login
|
|
|
|
|
2013-08-25 08:07:39 +00:00
|
|
|
# Connect to SSH
|
|
|
|
# args: search -> string to search
|
2013-08-06 20:24:09 +00:00
|
|
|
def ssh(search)
|
2014-01-23 21:32:48 +00:00
|
|
|
result = @mpw.search(search, nil, 'ssh')
|
2013-08-06 20:24:09 +00:00
|
|
|
|
|
|
|
if result.length > 0
|
|
|
|
result.each do |r|
|
2014-01-29 19:49:39 +00:00
|
|
|
server = @server.nil? ? r[MPW::MPW::SERVER] : @server
|
|
|
|
port = @port.nil? ? r[MPW::MPW::PORT] : @port
|
|
|
|
login = @login.nil? ? r[MPW::MPW::LOGIN] : @login
|
2013-08-24 22:55:11 +00:00
|
|
|
|
2014-01-29 19:49:39 +00:00
|
|
|
passwd = r[MPW::MPW::PASSWORD]
|
2013-08-06 20:24:09 +00:00
|
|
|
|
2013-09-20 10:27:08 +00:00
|
|
|
if port.nil? || port.empty?
|
2013-08-06 20:24:09 +00:00
|
|
|
port = 22
|
|
|
|
end
|
|
|
|
|
2013-12-26 17:18:10 +00:00
|
|
|
puts "#{I18n.t('ssh.display.connect')} ssh #{login}@#{server} -p #{port}"
|
2013-08-06 20:24:09 +00:00
|
|
|
if passwd.empty?
|
2013-08-24 22:55:11 +00:00
|
|
|
system("ssh #{login}@#{server} -p #{port}")
|
2013-08-06 20:24:09 +00:00
|
|
|
else
|
2013-09-20 10:27:08 +00:00
|
|
|
system("sshpass -p '#{passwd}' ssh #{login}@#{server} -p #{port}")
|
2013-08-06 20:24:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
2013-12-26 17:18:10 +00:00
|
|
|
puts I18n.t('ssh.display.nothing')
|
2013-08-06 20:24:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|