Esempio n. 1
0
 def get_output(self):
     width = self.client_channel.win_width
     height = self.client_channel.win_height
     parser = TtyIOParser(width=width, height=height)
     self.output = parser.parse_output(b''.join(self.output_data))
     if self.input:
         data = {
             'proxy_log_id': self.proxy_log_id,
             'user': self.user.username,
             'asset': self.asset.ip,
             'system_user': self.system_user.username,
             'command_no': self.command_no,
             'command': self.input,
             'output': self.output[:100],
             'timestamp': time.time(),
         }
         command_queue.put(data)
         self.command_no += 1
Esempio n. 2
0
 def get_output(self):
     width = self.client_channel.win_width
     height = self.client_channel.win_height
     parser = TtyIOParser(width=width, height=height)
     self.output = parser.parse_output(b''.join(self.output_data))
     if len(self.output) > 4096:
         self.output = self.output[:4096]
     if self.input:
         data = {
             'proxy_log_id': self.proxy_log_id,
             'user': self.user.username,
             'asset': self.asset.ip,
             'system_user': self.system_user.username,
             'command_no': self.command_no,
             'command': self.input,
             'output': self.output,
             'timestamp': time.time(),
         }
         command_queue.put(data)
         self.command_no += 1
Esempio n. 3
0
    def get_input(self, prompt='Opt> '):
        """实现了一个ssh input, 提示用户输入, 获取并返回"""
        input_data = []
        parser = TtyIOParser(request.win_width, request.win_height)
        self.client_channel.send(wr(prompt, before=1, after=0))
        while True:
            r, w, x = select.select([self.client_channel], [], [])
            if self.client_channel in r:
                data = self.client_channel.recv(1024)
                if data in self.BACKSPACE_CHAR:
                    # If input words less than 0, should send 'BELL'
                    if len(input_data) > 0:
                        data = self.BACKSPACE_CHAR[data]
                        input_data.pop()
                    else:
                        data = self.BELL_CHAR
                    self.client_channel.send(data)
                    continue

                if data.startswith(b'\x1b') or data in self.UNSUPPORTED_CHAR:
                    self.client_channel.send('')
                    continue

                # handle shell expect
                multi_char_with_enter = False
                if len(data) > 1 and data[-1] in self.ENTER_CHAR:
                    self.client_channel.send(data)
                    input_data.append(data[:-1])
                    multi_char_with_enter = True

                # If user type ENTER we should get user input
                if data in self.ENTER_CHAR or multi_char_with_enter:
                    self.client_channel.send(wr('', after=2))
                    option = parser.parse_input(b''.join(input_data))
                    return option.strip()
                else:
                    self.client_channel.send(data)
                    input_data.append(data)
Esempio n. 4
0
    def get_input(self, prompt='Opt> '):
        """实现了一个ssh input, 提示用户输入, 获取并返回"""
        input_data = []
        parser = TtyIOParser(request.win_width, request.win_height)
        self.client_channel.send(wr(prompt, before=1, after=0))
        while True:
            data = self.client_channel.recv(1024)
            if data in self.BACKSPACE_CHAR:
                # If input words less than 0, should send 'BELL'
                if len(input_data) > 0:
                    data = self.BACKSPACE_CHAR[data]
                    input_data.pop()
                else:
                    data = self.BELL_CHAR
                self.client_channel.send(data)
                continue

            if data.startswith(b'\x1b') or data in self.UNSUPPORTED_CHAR:
                self.client_channel.send('')
                continue

            # handle shell expect
            multi_char_with_enter = False
            if len(data) > 1 and data[-1] in self.ENTER_CHAR:
                self.client_channel.send(data)
                input_data.append(data[:-1])
                multi_char_with_enter = True

            # If user type ENTER we should get user input
            if data in self.ENTER_CHAR or multi_char_with_enter:
                self.client_channel.send(wr('', after=2))
                option = parser.parse_input(b''.join(input_data))
                return option.strip()
            else:
                self.client_channel.send(data)
                input_data.append(data)
Esempio n. 5
0
 def get_input(self):
     width = self.client_channel.win_width
     height = self.client_channel.win_height
     parser = TtyIOParser(width=width, height=height)
     self.input = parser.parse_input(b''.join(self.input_data))
Esempio n. 6
0
 def get_input(self):
     width = self.client_channel.win_width
     height = self.client_channel.win_height
     parser = TtyIOParser(width=width, height=height)
     self.input = parser.parse_input(b''.join(self.input_data))