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
|
end
|
||||||
|
|
||||||
# get the output that we have ready
|
# get the output that we have ready
|
||||||
rstream.get_once(-1, 1)
|
shell_read(-1, 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ class CommandShell
|
||||||
# Read until we get the token or timeout.
|
# Read until we get the token or timeout.
|
||||||
buf = ''
|
buf = ''
|
||||||
idx = nil
|
idx = nil
|
||||||
while (tmp = rstream.get_once(-1, 1))
|
while (tmp = shell_read(-1, 1))
|
||||||
buf << tmp
|
buf << tmp
|
||||||
|
|
||||||
# see if we have the wanted idx
|
# see if we have the wanted idx
|
||||||
|
@ -163,7 +163,7 @@ class CommandShell
|
||||||
#
|
#
|
||||||
def shell_command_token_unix(cmd)
|
def shell_command_token_unix(cmd)
|
||||||
# read any pending data
|
# read any pending data
|
||||||
buf = rstream.get_once(-1, 0.01)
|
buf = shell_read(-1, 0.01)
|
||||||
token = ::Rex::Text.rand_text_alpha(32)
|
token = ::Rex::Text.rand_text_alpha(32)
|
||||||
|
|
||||||
# Send the command to the session's stdin.
|
# Send the command to the session's stdin.
|
||||||
|
@ -177,7 +177,7 @@ class CommandShell
|
||||||
#
|
#
|
||||||
def shell_command_token_win32(cmd)
|
def shell_command_token_win32(cmd)
|
||||||
# read any pending data
|
# read any pending data
|
||||||
buf = rstream.get_once(-1, 0.01)
|
buf = shell_read(-1, 0.01)
|
||||||
token = ::Rex::Text.rand_text_alpha(32)
|
token = ::Rex::Text.rand_text_alpha(32)
|
||||||
|
|
||||||
# Send the command to the session's stdin.
|
# Send the command to the session's stdin.
|
||||||
|
@ -189,11 +189,10 @@ class CommandShell
|
||||||
#
|
#
|
||||||
# Read from the command shell.
|
# Read from the command shell.
|
||||||
#
|
#
|
||||||
def shell_read(length = nil)
|
def shell_read(length=-1, timeout=1)
|
||||||
if length.nil?
|
rv = rstream.get_once(length, timeout)
|
||||||
rv = rstream.get_once(-1, 0)
|
if rv
|
||||||
else
|
framework.events.on_session_output(self, rv)
|
||||||
rv = rstream.read(length)
|
|
||||||
end
|
end
|
||||||
return rv
|
return rv
|
||||||
end
|
end
|
||||||
|
@ -202,6 +201,7 @@ class CommandShell
|
||||||
# Writes to the command shell.
|
# Writes to the command shell.
|
||||||
#
|
#
|
||||||
def shell_write(buf)
|
def shell_write(buf)
|
||||||
|
framework.events.on_session_command(self, buf.strip)
|
||||||
rstream.write(buf)
|
rstream.write(buf)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -43,9 +43,6 @@ class Session < Base
|
||||||
{ "data" => "", "encoding" => "base64" }
|
{ "data" => "", "encoding" => "base64" }
|
||||||
else
|
else
|
||||||
data = s.shell_read
|
data = s.shell_read
|
||||||
if data.length > 0
|
|
||||||
@framework.events.on_session_output(s, data)
|
|
||||||
end
|
|
||||||
{ "data" => Rex::Text.encode_base64(data), "encoding" => "base64" }
|
{ "data" => Rex::Text.encode_base64(data), "encoding" => "base64" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -57,7 +54,6 @@ class Session < Base
|
||||||
raise ::XMLRPC::FaultException.new(403, "session is not a shell")
|
raise ::XMLRPC::FaultException.new(403, "session is not a shell")
|
||||||
end
|
end
|
||||||
buff = Rex::Text.decode_base64(data)
|
buff = Rex::Text.decode_base64(data)
|
||||||
@framework.events.on_session_command(s, buff)
|
|
||||||
|
|
||||||
{ "write_count" => s.shell_write(buff) }
|
{ "write_count" => s.shell_write(buff) }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue