mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-20 05:14:36 +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
|
# mail: nishiki@yaegashi.fr
|
||||||
# info: a simple script who manage your passwords
|
# info: a simple script who manage your passwords
|
||||||
|
|
||||||
require 'net/ssh'
|
|
||||||
require "#{APP_ROOT}/Cli.rb"
|
require "#{APP_ROOT}/Cli.rb"
|
||||||
|
|
||||||
class CliSSH < Cli
|
class CliSSH < Cli
|
||||||
|
|
||||||
|
attr_accessor :server, :port, :login
|
||||||
|
|
||||||
def ssh(search)
|
def ssh(search)
|
||||||
result = @m.search(search, 'ssh')
|
result = @m.search(search, 'ssh')
|
||||||
|
|
||||||
if result.length > 0
|
if result.length > 0
|
||||||
result.each do |r|
|
result.each do |r|
|
||||||
server = r[MPW::SERVER]
|
@server.nil? ? (server = r[MPW::SERVER]) : (server = @server)
|
||||||
login = r[MPW::LOGIN]
|
@port.nil? ? (port = r[MPW::PORT]) : (port = @port)
|
||||||
port = r[MPW::PORT]
|
@login.nil? ? (login = r[MPW::LOGIN]) : (login = @login)
|
||||||
|
|
||||||
passwd = r[MPW::PASSWORD]
|
passwd = r[MPW::PASSWORD]
|
||||||
|
|
||||||
if port.empty?
|
if port.empty?
|
||||||
port = 22
|
port = 22
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts "ssh #{login}@#{server} -p #{port}"
|
||||||
if passwd.empty?
|
if passwd.empty?
|
||||||
system("#{passwd} ssh #{login}@#{server} -p #{port}")
|
system("ssh #{login}@#{server} -p #{port}")
|
||||||
else
|
else
|
||||||
system("sshpass -p #{passwd} ssh #{login}@#{server} -p #{port}")
|
system("sshpass -p #{passwd} ssh #{login}@#{server} -p #{port}")
|
||||||
end
|
end
|
||||||
|
|
33
mpw-ssh
33
mpw-ssh
|
@ -4,19 +4,42 @@
|
||||||
# info: a simple script who manage your passwords
|
# info: a simple script who manage your passwords
|
||||||
|
|
||||||
require 'rubygems'
|
require 'rubygems'
|
||||||
|
require 'optparse'
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
|
|
||||||
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
||||||
require "#{APP_ROOT}/CliSSH.rb"
|
require "#{APP_ROOT}/CliSSH.rb"
|
||||||
|
|
||||||
if ARGV.length != 1
|
cli = CliSSH.new()
|
||||||
puts "Usage: mpw-ssh search"
|
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
|
exit 2
|
||||||
end
|
end
|
||||||
|
|
||||||
search = ARGV[0]
|
|
||||||
|
|
||||||
cli = CliSSH.new()
|
|
||||||
cli.ssh(search)
|
cli.ssh(search)
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue