Beispiel #1
0
    def connect_host(self, message):
        asset_id = message.get('uuid', None)
        system_user_id = message.get('userid', None)
        secret = message.get('secret', None)
        cols, rows = message.get('size', (80, 24))
        request.current_user = "******"

        connection = Connection.get_connection(request.sid)
        client_id = str(uuid.uuid4())
        client = connection.new_client(client_id)
        client.request.kind = 'session'
        client.request.type = 'pty'
        client.request.meta.update({
            'pty': b'xterm', 'width': cols, 'height': rows,
        })
        ws_proxy = WSProxy(self, client_id)
        client.chan = ws_proxy
        self.emit('room', {'room': client_id, 'secret': secret})
        join_room(client_id)
        if not asset_id or not system_user_id:
            return

        forwarder = ProxyServer(client, None, None)

        def proxy():
            forwarder.proxy()
            self.logout(client_id, connection)
        self.socketio.start_background_task(proxy)
Beispiel #2
0
 def dispatch(client):
     supported = {'pty', 'x11', 'forward-agent'}
     chan_type = client.request.type
     kind = client.request.kind
     if kind == 'session' and chan_type in supported:
         logger.info("Request type `{}:{}`, dispatch to interactive mode".format(kind, chan_type))
         try:
             InteractiveServer(client).interact()
         except Exception as e:
             logger.error("Unexpected error occur: {}".format(e))
         connection = Connection.get_connection(client.connection_id)
         connection.remove_client(client.id)
     elif chan_type == 'subsystem':
         pass
     else:
         msg = "Request type `{}:{}` not support now".format(kind, chan_type)
         logger.info(msg)
         client.send(msg)
Beispiel #3
0
 def dispatch(client):
     supported = {'pty', 'x11', 'forward-agent'}
     chan_type = client.request.type
     kind = client.request.kind
     try:
         if kind == 'session' and chan_type in supported:
             logger.info("Dispatch client to interactive mode")
             try:
                 InteractiveServer(client).interact()
             except IndexError as e:
                 logger.error("Unexpected error occur: {}".format(e))
         elif chan_type == 'subsystem':
             while not client.closed:
                 time.sleep(5)
             logger.debug("SFTP session finished")
         else:
             msg = "Request type `{}:{}` not support now".format(kind, chan_type)
             logger.error(msg)
             client.send_unicode(msg)
     finally:
         connection = Connection.get_connection(client.connection_id)
         if connection:
             connection.remove_client(client.id)