Record command history

pull/530/head
ibuler 8 years ago
parent aa02c211fe
commit 0cda4e0905

@ -209,28 +209,53 @@ class Navigation:
class ProxyChannel: class ProxyChannel:
ENTER_CHAR = ['\r', '\n', '\r\n'] ENTER_CHAR = ['\r', '\n', '\r\n']
input_data = []
output_data = [] output_data = []
command = []
output = []
def __init__(self, client_channel, backend_channel, client_addr): def __init__(self, client_channel, backend_channel, client_addr):
self.client_channel = client_channel self.client_channel = client_channel
self.backend_channel = backend_channel self.backend_channel = backend_channel
self.client_addr = client_addr self.client_addr = client_addr
self.in_input_mode = True self.in_input_mode = True
self.is_first_input = True
def stream_flow(self, input_=None, output_=None): self.id = 0
if input_:
self.in_input_mode = True # def stream_flow(self, input_=None, output_=None):
if input_ in ['\r', '\n', '\r\n']: # if input_:
self.in_input_mode = False # self.in_input_mode = True
# if input_ in ['\r', '\n', '\r\n']:
if output_: # self.in_input_mode = False
print(''.join(self.__class__.output_data)) #
if not self.in_input_mode: # if output_:
command = ''.join(self.__class__.output_data) # print(''.join(self.__class__.output_data))
del self.__class__.output_data # if not self.in_input_mode:
self.__class__.output_data = [] # command = ''.join(self.__class__.output_data)
self.__class__.output_data.append(output_) # del self.__class__.output_data
# self.__class__.output_data = []
# self.__class__.output_data.append(output_)
def get_output(self):
if self.in_input_mode is False:
self.__class__.output_data.pop()
result = ''.join(self.__class__.output_data)
self.__class__.output.append(result)
print('>>>>>>>>>>> output <<<<<<<<<<')
print(result)
print('>>>>>>>>>>> end output <<<<<<<<<<')
del self.__class__.output_data
self.__class__.output_data = []
def get_command(self, client_data):
if client_data in self.__class__.ENTER_CHAR:
self.in_input_mode = False
command = ''.join(self.__class__.output_data)
print('########### command ##########')
self.__class__.command.append(command)
print(command)
print('########### end command ##########')
del self.__class__.output_data
self.__class__.output_data = []
def proxy(self): def proxy(self):
client_channel = self.client_channel client_channel = self.client_channel
@ -243,24 +268,17 @@ class ProxyChannel:
if client_channel.change_window_size_event.is_set(): if client_channel.change_window_size_event.is_set():
backend_channel.resize_pty(width=client_channel.width, height=client_channel.height) backend_channel.resize_pty(width=client_channel.width, height=client_channel.height)
# print(self.__class__.output)
if client_channel in r: if client_channel in r:
self.in_input_mode = True # Get output of the command
self.get_output()
client_data = client_channel.recv(1024) client_data = client_channel.recv(1024)
self.in_input_mode = True
self.is_first_input = False
if client_data in self.__class__.ENTER_CHAR: # Get command input
self.in_input_mode = False self.get_command(client_data)
command = ''.join(self.__class__.output_data)
print('########### command ##########')
print(command)
print('########### end command ##########')
del self.__class__.output_data
self.__class__.output_data = []
backend_channel.send(client_data)
output = ''.join(self.__class__.output_data)
print('>>>>>>>>>>> output <<<<<<<<<<')
print(output)
print('>>>>>>>>>>> end output <<<<<<<<<<')
continue
if len(client_data) == 0: if len(client_data) == 0:
logger.info('Logout from ssh server %(host)s: %(username)s' % { logger.info('Logout from ssh server %(host)s: %(username)s' % {
@ -280,7 +298,8 @@ class ProxyChannel:
'username': backend_channel.username, 'username': backend_channel.username,
}) })
break break
self.__class__.output_data.append(backend_data) if not self.is_first_input:
self.__class__.output_data.append(backend_data)
client_channel.send(backend_data) client_channel.send(backend_data)
@ -346,9 +365,6 @@ class JumpServer:
return backend_channel return backend_channel
def command_flow(self, input_=None, output_=None):
pass
def handle_ssh_request(self, client, addr): def handle_ssh_request(self, client, addr):
logger.info("Get ssh request from %(host)s:%(port)s" % { logger.info("Get ssh request from %(host)s:%(port)s" % {
'host': addr[0], 'host': addr[0],

Loading…
Cancel
Save