예제 #1
0
def index():
    # Abort if this is not a websocket request
    if not request.environ.get('wsgi.websocket'):
        app.logger.error('Abort: Request is not WebSocket upgradable')
        raise BadRequest()

    # Here you can perform authentication and sanity checks
    #if request.args.get('key') != 'secret':
    #    raise Unauthorized

    # Initiate a WSSH Bridge and connect to a remote SSH server
    bridge = wssh.WSSHBridge(request.environ['wsgi.websocket'])
    try:
        bridge.open(hostname='localhost',
                    username='******',
                    password='******')
    except Exception as e:
        app.logger.exception('Error while connecting: {0}'.format(e.message))
        request.environ['wsgi.websocket'].close()
        return str()

    # Launch a shell on the remote server and bridge the connection
    # This won't return as long as the session is alive
    bridge.shell()

    # Alternatively, you can run a command on the remote server
    # bridge.execute('/bin/ls -l /')

    # We have to manually close the websocket and return an empty response,
    # otherwise flask will complain about not returning a response and will
    # throw a 500 at our websocket client
    request.environ['wsgi.websocket'].close()
    return str()
예제 #2
0
파일: views.py 프로젝트: movermeyer/docklr
def connect(hostname, id):

    # Abort if this is not a websocket request
    if not request.environ.get('wsgi.websocket'):
        app.logger.error('Abort: Request is not WebSocket upgradable')
        raise BadRequest()

    bridge = wssh.WSSHBridge(request.environ['wsgi.websocket'])
    try:
        config = Config.query.get(id)
        bridge.open(hostname=hostname,
                    username='******',
                    port=22,
                    private_key=config.private_key,
                    allow_agent=app.config.get('WSSH_ALLOW_SSH_AGENT', False))
    except Exception as e:
        app.logger.exception('Error while connecting to {0}: {1}'.format(
            hostname, e.message))
        request.environ['wsgi.websocket'].close()
        return str()
    bridge.shell()

    # We have to manually close the websocket and return an empty response,
    # otherwise flask will complain about not returning a response and will
    # throw a 500 at our websocket client
    request.environ['wsgi.websocket'].close()
    return str()