move session_output events to the session where they belong (instead of in rpc). add a timeout arg to shell_read
git-svn-id: file:///home/svn/framework3/trunk@8797 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
7f1e5fd475
commit
646044f631
|
@ -119,7 +119,7 @@ class CommandShell
|
|||
end
|
||||
|
||||
# get the output that we have ready
|
||||
rstream.get_once(-1, 1)
|
||||
shell_read(-1, 1)
|
||||
end
|
||||
|
||||
|
||||
|
@ -141,7 +141,7 @@ class CommandShell
|
|||
# Read until we get the token or timeout.
|
||||
buf = ''
|
||||
idx = nil
|
||||
while (tmp = rstream.get_once(-1, 1))
|
||||
while (tmp = shell_read(-1, 1))
|
||||
buf << tmp
|
||||
|
||||
# see if we have the wanted idx
|
||||
|
@ -163,7 +163,7 @@ class CommandShell
|
|||
#
|
||||
def shell_command_token_unix(cmd)
|
||||
# read any pending data
|
||||
buf = rstream.get_once(-1, 0.01)
|
||||
buf = shell_read(-1, 0.01)
|
||||
token = ::Rex::Text.rand_text_alpha(32)
|
||||
|
||||
# Send the command to the session's stdin.
|
||||
|
@ -177,7 +177,7 @@ class CommandShell
|
|||
#
|
||||
def shell_command_token_win32(cmd)
|
||||
# read any pending data
|
||||
buf = rstream.get_once(-1, 0.01)
|
||||
buf = shell_read(-1, 0.01)
|
||||
token = ::Rex::Text.rand_text_alpha(32)
|
||||
|
||||
# Send the command to the session's stdin.
|
||||
|
@ -189,11 +189,10 @@ class CommandShell
|
|||
#
|
||||
# Read from the command shell.
|
||||
#
|
||||
def shell_read(length = nil)
|
||||
if length.nil?
|
||||
rv = rstream.get_once(-1, 0)
|
||||
else
|
||||
rv = rstream.read(length)
|
||||
def shell_read(length=-1, timeout=1)
|
||||
rv = rstream.get_once(length, timeout)
|
||||
if rv
|
||||
framework.events.on_session_output(self, rv)
|
||||
end
|
||||
return rv
|
||||
end
|
||||
|
@ -202,6 +201,7 @@ class CommandShell
|
|||
# Writes to the command shell.
|
||||
#
|
||||
def shell_write(buf)
|
||||
framework.events.on_session_command(self, buf.strip)
|
||||
rstream.write(buf)
|
||||
end
|
||||
|
||||
|
|
|
@ -43,9 +43,6 @@ class Session < Base
|
|||
{ "data" => "", "encoding" => "base64" }
|
||||
else
|
||||
data = s.shell_read
|
||||
if data.length > 0
|
||||
@framework.events.on_session_output(s, data)
|
||||
end
|
||||
{ "data" => Rex::Text.encode_base64(data), "encoding" => "base64" }
|
||||
end
|
||||
end
|
||||
|
@ -57,7 +54,6 @@ class Session < Base
|
|||
raise ::XMLRPC::FaultException.new(403, "session is not a shell")
|
||||
end
|
||||
buff = Rex::Text.decode_base64(data)
|
||||
@framework.events.on_session_command(s, buff)
|
||||
|
||||
{ "write_count" => s.shell_write(buff) }
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue