mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-19 21:04:35 +00:00
mpw-ssh: add options to force login, server and port
This commit is contained in:
parent
24d4a27a07
commit
f9980b75b6
2 changed files with 36 additions and 10 deletions
13
CliSSH.rb
13
CliSSH.rb
|
@ -3,27 +3,30 @@
|
|||
# mail: nishiki@yaegashi.fr
|
||||
# info: a simple script who manage your passwords
|
||||
|
||||
require 'net/ssh'
|
||||
require "#{APP_ROOT}/Cli.rb"
|
||||
|
||||
class CliSSH < Cli
|
||||
|
||||
attr_accessor :server, :port, :login
|
||||
|
||||
def ssh(search)
|
||||
result = @m.search(search, 'ssh')
|
||||
|
||||
if result.length > 0
|
||||
result.each do |r|
|
||||
server = r[MPW::SERVER]
|
||||
login = r[MPW::LOGIN]
|
||||
port = r[MPW::PORT]
|
||||
@server.nil? ? (server = r[MPW::SERVER]) : (server = @server)
|
||||
@port.nil? ? (port = r[MPW::PORT]) : (port = @port)
|
||||
@login.nil? ? (login = r[MPW::LOGIN]) : (login = @login)
|
||||
|
||||
passwd = r[MPW::PASSWORD]
|
||||
|
||||
if port.empty?
|
||||
port = 22
|
||||
end
|
||||
|
||||
puts "ssh #{login}@#{server} -p #{port}"
|
||||
if passwd.empty?
|
||||
system("#{passwd} ssh #{login}@#{server} -p #{port}")
|
||||
system("ssh #{login}@#{server} -p #{port}")
|
||||
else
|
||||
system("sshpass -p #{passwd} ssh #{login}@#{server} -p #{port}")
|
||||
end
|
||||
|
|
33
mpw-ssh
33
mpw-ssh
|
@ -4,19 +4,42 @@
|
|||
# info: a simple script who manage your passwords
|
||||
|
||||
require 'rubygems'
|
||||
require 'optparse'
|
||||
require 'pathname'
|
||||
|
||||
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
||||
require "#{APP_ROOT}/CliSSH.rb"
|
||||
|
||||
if ARGV.length != 1
|
||||
puts "Usage: mpw-ssh search"
|
||||
cli = CliSSH.new()
|
||||
search = ARGV[0]
|
||||
|
||||
options = {}
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "Usage: mpw-ssh SEARCH [options]"
|
||||
|
||||
opts.on("-l", "--login LOGIN", "Force a login") do |login|
|
||||
cli.login = login
|
||||
end
|
||||
|
||||
opts.on("-p", "--port PORT", "Force a port") do |port|
|
||||
cli.port = port
|
||||
end
|
||||
|
||||
opts.on("-s", "--server SERVER", "Force a server") do |server|
|
||||
cli.server = server
|
||||
end
|
||||
|
||||
opts.on("-h", "--help", "Show this message") do |b|
|
||||
puts opts
|
||||
exit 0
|
||||
end
|
||||
end.parse!
|
||||
|
||||
if ARGV.length < 1
|
||||
puts "Usage: mpw-ssh SEARCH [options]"
|
||||
exit 2
|
||||
end
|
||||
|
||||
search = ARGV[0]
|
||||
|
||||
cli = CliSSH.new()
|
||||
cli.ssh(search)
|
||||
|
||||
exit 0
|
||||
|
|
Loading…
Add table
Reference in a new issue