Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/hwbridge/ui/console/interactive_channel.rb
Views: 11789
# -*- coding: binary -*-1module Rex2module Post3module HWBridge4module Ui56###7#8# Mixin that is meant to extend the base channel class from hwbridge in a9# manner that adds interactive capabilities.10#11###12module Console::InteractiveChannel1314include Rex::Ui::Interactive1516#17# Interacts with self.18#19def _interact20# If the channel has a left-side socket, then we can interact with it.21if (self.lsock)22self.interactive(true)2324interact_stream(self)2526self.interactive(false)27else28print_error("Channel #{self.cid} does not support interaction.")2930self.interacting = false31end32end3334#35# Called when an interrupt is sent.36#37def _interrupt38prompt_yesno("Terminate channel #{self.cid}?")39end4041#42# Suspends interaction with the channel.43#44def _suspend45# Ask the user if they would like to background the session46if (prompt_yesno("Background channel #{self.cid}?") == true)47self.interactive(false)4849self.interacting = false50end51end5253#54# Closes the channel like it aint no thang.55#56def _interact_complete57begin58self.interactive(false)5960self.close61rescue IOError62end63end6465#66# Reads data from local input and writes it remotely.67#68def _stream_read_local_write_remote(channel)69data = user_input.gets70return if not data7172self.on_command_proc.call(data.strip) if self.on_command_proc73self.write(data)74end7576#77# Reads from the channel and writes locally.78#79def _stream_read_remote_write_local(channel)80data = self.lsock.sysread(16384)8182self.on_print_proc.call(data.strip) if self.on_print_proc83self.on_log_proc.call(data.strip) if self.on_log_proc84user_output.print(data)85end8687#88# Returns the remote file descriptor to select on89#90def _remote_fd(stream)91self.lsock92end9394attr_accessor :on_log_proc9596end9798end99end100end101end102103104