Class: Expect4r::BaseLoginObject
Class Attribute Summary collapse
-
.routers ⇒ Object
readonly
Returns the value of attribute routers.
Instance Attribute Summary collapse
-
#host ⇒ Object
(also: #hostname)
Returns the value of attribute host.
-
#method ⇒ Object
Returns the value of attribute method.
-
#port ⇒ Object
Returns the value of attribute port.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
-
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
-
#user ⇒ Object
(also: #username)
Returns the value of attribute user.
Class Method Summary collapse
- .add(r) ⇒ Object
-
.new_ssh(*args) ⇒ Object
Examples: my_mac = RShell.new_ssh ‘1.1.1.1’, ‘me’, ‘secret’ iox = Ios.new_ssh ‘1.1.1.1’, ‘lab’, ‘lab’ ios = Iosx.new_ssh ‘1.1.1.1’, ‘username’, ‘pwd’.
-
.new_telnet(*args) ⇒ Object
Examples: my_mac = RShell.new_telnet ‘1.1.1.1’, ‘me’, ‘secret’ ios = Ios.new_telnet ‘1.1.1.1’, ‘lab’, ‘lab’ iox = Iox.new_telnet ‘1.1.1.1’, ‘username’, ‘pwd’.
Instance Method Summary collapse
- #cmp(o) ⇒ Object
- #connect_retry ⇒ Object
- #connect_retry=(arg) ⇒ Object
- #dup ⇒ Object
- #enable_password ⇒ Object
-
#initialize(*args) ⇒ BaseLoginObject
constructor
@method, host, @user, pwd, enable_pwd, port = args @method, host, @user, pwd, enable_pwd = args @method, host, @user, pwd, port = args @method, host, @user, pwd = args.
- #password ⇒ Object
- #spawnee ⇒ Object
- #spawnee_prompt ⇒ Object
- #spawnee_username ⇒ Object
Methods inherited from Base
Methods included from Expect4r
#_login, #child_exit, #connected?, #exp_print, #exp_puts, #exp_send, #expect, #get_prompt, #getc, #interact, #login_by_proxy, #logout, #putc, #putcr, #read_until, #readline, #spawn
Constructor Details
#initialize(*args) ⇒ BaseLoginObject
@method, host, @user, pwd, enable_pwd, port = args @method, host, @user, pwd, enable_pwd = args @method, host, @user, pwd, port = args @method, host, @user, pwd = args
@method, host+port, @user, pwd, enable_pwd = args @method, host+port, @user, pwd = args
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/misc/base.rb', line 91 def initialize(*args) host, _pwd, _enable_pwd, ciphered_password=[nil]*5 if args.size>2 and args[1].is_a?(String) case args.size when 6 @method, host, @user, _pwd, _enable_pwd, port = args when 5 if args.last.is_a?(Fixnum) @method, host, @user, _pwd, port = args else @method, host, @user, _pwd, _enable_pwd = args end else @method, host, @user, _pwd, port = args end raise ArgumentError if host.split.size>1 and port @host, _port = host.split @port = port || (_port || 0).to_i elsif args.size == 2 and args[1].is_a?(Hash) and args[0].is_a?(Symbol) @method = args[0] @host = args[1][:host] || args[1][:hostname] port = args[1][:port] @port = (port || 0).to_i @user = args[1][:user]|| args[1][:username] _pwd = args[1][:pwd] || args[1][:password] ciphered_password = args[1][:ciphered_password] _enable_pwd = args[1][:enable_password] ciphered_enable_password = args[1][:ciphered_enable_password] else raise end @pwd = if ciphered_password ciphered_password else Expect4r.cipher(_pwd) if _pwd end @enable_pwd = if ciphered_enable_password ciphered_enable_password else Expect4r.cipher(_enable_pwd || _pwd) if _enable_pwd || _pwd end @ps1 = /(.*)(>|#|\$)\s*$/ @more = / --More-- / @matches=Set.new Base.add(self) self end |
Class Attribute Details
.routers ⇒ Object (readonly)
Returns the value of attribute routers.
40 41 42 |
# File 'lib/misc/base.rb', line 40 def routers @routers end |
Instance Attribute Details
#host ⇒ Object Also known as: hostname
Returns the value of attribute host.
46 47 48 |
# File 'lib/misc/base.rb', line 46 def host @host end |
#method ⇒ Object
Returns the value of attribute method.
46 47 48 |
# File 'lib/misc/base.rb', line 46 def method @method end |
#port ⇒ Object
Returns the value of attribute port.
46 47 48 |
# File 'lib/misc/base.rb', line 46 def port @port end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
46 47 48 |
# File 'lib/misc/base.rb', line 46 def proxy @proxy end |
#ssh_options ⇒ Object
Returns the value of attribute ssh_options.
152 153 154 |
# File 'lib/misc/base.rb', line 152 def @ssh_options end |
#user ⇒ Object Also known as: username
Returns the value of attribute user.
46 47 48 |
# File 'lib/misc/base.rb', line 46 def user @user end |
Class Method Details
.add(r) ⇒ Object
41 42 43 44 |
# File 'lib/misc/base.rb', line 41 def add(r) @routers ||=[] @routers << r end |
.new_ssh(*args) ⇒ Object
37 38 39 |
# File 'lib/misc/base.rb', line 37 def new_ssh(*args) new :ssh, *args end |
Instance Method Details
#cmp(o) ⇒ Object
210 211 212 |
# File 'lib/misc/base.rb', line 210 def cmp(o) o.spawnee == spawnee and o.password == password and o.enable_password == enable_password end |
#connect_retry ⇒ Object
185 186 187 |
# File 'lib/misc/base.rb', line 185 def connect_retry @connect_retry ||= 0 end |
#connect_retry=(arg) ⇒ Object
189 190 191 192 |
# File 'lib/misc/base.rb', line 189 def connect_retry=(arg) raise ArgumentError unless (0 .. 100_000) === arg @connect_retry = arg end |
#dup ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/misc/base.rb', line 194 def dup if @pwd self.class.new @method, @host, @user, Expect4r.decipher(@pwd) else self.class.new @method, @host, @user end end |
#enable_password ⇒ Object
206 207 208 |
# File 'lib/misc/base.rb', line 206 def enable_password @enable_pwd end |
#password ⇒ Object
202 203 204 |
# File 'lib/misc/base.rb', line 202 def password @pwd end |
#spawnee ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/misc/base.rb', line 163 def spawnee case method when :telnet ; "telnet #{host} #{port if port>0}" when :ssh cmd ="ssh #{host}" cmd +=" -oPort=#{port}" if port>0 cmd +=" -oUser=#{spawnee_username}" if spawnee_username cmd += [" ", []].flatten.join(" ") if cmd else raise RuntimeError end end |
#spawnee_prompt ⇒ Object
181 182 183 |
# File 'lib/misc/base.rb', line 181 def spawnee_prompt @ps1 end |
#spawnee_username ⇒ Object
177 178 179 |
# File 'lib/misc/base.rb', line 177 def spawnee_username @user end |