From 72a4fb26446f74903e69b75a69c45d58500d6d19 Mon Sep 17 00:00:00 2001 From: ja-frog <31773963+ja-frog@users.noreply.github.com> Date: Mon, 9 Apr 2018 15:40:16 -0500 Subject: Add handling for devices that only prompt for a password via SSH An approach to handling devices that do not prompt for a username, only a password when connecting via ssh. The Calix B6 inspired this. --- lib/oxidized/input/ssh.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/oxidized/input/ssh.rb') diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 27e81e0..d84b349 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -123,6 +123,11 @@ module Oxidized cmd @node.auth[:username], password cmd @node.auth[:password] end + elsif @password + match = expect password, @node.prompt + if match == password + cmd @node.auth[:password] + end else expect @node.prompt end -- cgit v1.2.1 From 0fa29774f677fbfba532703d1947fcf018ef3705 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 27 Apr 2018 22:11:43 +0200 Subject: refactor login in ssh.rb --- lib/oxidized/input/ssh.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'lib/oxidized/input/ssh.rb') diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index d84b349..4b4d87c 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -117,19 +117,13 @@ module Oxidized # some models have SSH auth or terminal auth based on version of code # if SSH is configured for terminal auth, we'll still try to detect prompt def login - if @username - match = expect username, @node.prompt - if match == username - cmd @node.auth[:username], password - cmd @node.auth[:password] - end - elsif @password - match = expect password, @node.prompt - if match == password - cmd @node.auth[:password] - end - else - expect @node.prompt + match_re = [ @node.prompt ] + match_re << @username if @username + match_re << @password if @password + until (match=expect(match_re)) == @node.prompt + cmd(@node.auth[:username], nil) if match == @username + cmd(@node.auth[:password], nil) if match == @password + match_re.delete match end end -- cgit v1.2.1