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
|
|
|
|
|
|
|
|
require "#{APP_ROOT}/Cli.rb"
|
|
|
|
|
|
|
|
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)
|
|
|
|
result = @m.search(search, 'ssh')
|
|
|
|
|
|
|
|
if result.length > 0
|
|
|
|
result.each do |r|
|
2013-08-24 22:55:11 +00:00
|
|
|
@server.nil? ? (server = r[MPW::SERVER]) : (server = @server)
|
|
|
|
@port.nil? ? (port = r[MPW::PORT]) : (port = @port)
|
|
|
|
@login.nil? ? (login = r[MPW::LOGIN]) : (login = @login)
|
|
|
|
|
2013-08-06 20:24:09 +00:00
|
|
|
passwd = r[MPW::PASSWORD]
|
|
|
|
|
|
|
|
if port.empty?
|
|
|
|
port = 22
|
|
|
|
end
|
|
|
|
|
2013-08-25 08:07:39 +00:00
|
|
|
puts "Connect to: 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
|
|
|
|
system("sshpass -p #{passwd} ssh #{login}@#{server} -p #{port}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
puts "Nothing result!"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|