Further progress towards mobile sessions

git-svn-id: file:///home/svn/framework3/trunk@4425 4d416f70-5f16-0410-b530-b9f4589650da
unstable
HD Moore 2007-02-18 05:07:56 +00:00
parent 80c4bcd5ab
commit 075b3c1c82
4 changed files with 23 additions and 34 deletions

View File

@ -662,13 +662,9 @@ class Core
print_status("Starting interaction with #{session.name}...\n") if (quiet == false)
self.active_session = session
# Set the session's input and output handles
session.init_ui(driver.input.dup, driver.output)
# Interact
session.interact()
session.interact(driver.input.dup, driver.output)
self.active_session = nil
else

View File

@ -24,13 +24,10 @@ class Console < MyGlade
# Create the pipe interface
@pipe = Rex::IO::BidirectionalPipe.new
# Initialize the session
@session.init_ui(@pipe, @pipe)
# Start the session interaction
@t_run = Thread.new do
@session.interact()
@session.interact(@pipe, @pipe)
end
# Create a subscriber with a callback for the UI
@ -46,9 +43,6 @@ class Console < MyGlade
# Kill the interaction thread
@t_run.kill
# Reset the session UI handles
@session.reset_ui
# Close the pipes
@pipe.close

View File

@ -85,12 +85,14 @@ class Driver < Msf::Ui::Driver
def write_session(id, buf)
ses = self.framework.sessions[id]
return if not ses
return if not ses.user_input
ses.user_input.put(buf)
end
def read_session(id)
ses = self.framework.sessions[id]
return if not ses
return if not ses
return if not ses.user_output
ses.user_output.read_subscriber('session_reader')
end
@ -102,10 +104,9 @@ class Driver < Msf::Ui::Driver
return if not ses
# Has this session already been detached?
return if ses.user_output.has_subscriber?('session_reader')
# Detach session if necessary
ses.detach()
if (ses.user_output)
return if ses.user_output.has_subscriber?('session_reader')
end
# Create a new pipe
spipe = WebConsole::WebConsolePipe.new
@ -113,13 +114,9 @@ class Driver < Msf::Ui::Driver
# Create a read subscriber
spipe.create_subscriber('session_reader')
# Replace the input/output handles
ses.user_input = spipe.input
ses.user_output = spipe
Thread.new do
ses.interact
ses.interact(spipe.input, spipe)
end
end

View File

@ -20,13 +20,15 @@ module Interactive
# forwarding input from user_input to rstream and forwarding input from
# rstream to user_output.
#
def interact
def interact(user_input, user_output)
# Prevent two thread from interacting at once
# Detach from any existing console
if(self.interacting)
raise RuntimeError, "This session is already interacting with another console"
detach()
end
init_ui(user_input, user_output)
self.interacting = true
self.completed = false
@ -71,15 +73,16 @@ module Interactive
# Shutdown the readline thread
# XXX disabled
# user_input.readline_stop() if user_input.supports_readline
# Detach from the input/output handles
reset_ui()
ensure
# Mark this as completed
self.completed = true
end
# Return whether or not EOF was reached
return eof
end
@ -90,9 +93,8 @@ module Interactive
def detach
if (self.interacting)
self.interacting = false
stime = Time.now.to_f
while(Time.now.to_f > stime + 5 and not self.completed)
select(nil, nil, nil, 0.10)
while(not self.completed)
select(nil, nil, nil, 0.25)
end
end
end
@ -181,7 +183,7 @@ protected
while self.interacting
# Select input and rstream
sd = Rex::ThreadSafe.select([ _local_fd, _remote_fd(stream) ], nil, nil, 0.25)
sd = Rex::ThreadSafe.select([ _local_fd, _remote_fd(stream) ], nil, nil, 0.50)
# Cycle through the items that have data
# From the stream? Write to user_output.