Exemplo n.º 1
0
 def patch(name, service):
     if isinstance(service, dict):
         service = TestService(service)
     orig_service = services.get_services().get(name)
     services.register(service, name)
     request.addfinalizer(lambda: services.get_services().pop(name, None))
     if orig_service:
         request.addfinalizer(lambda: services.get_services().update({name: orig_service}))
Exemplo n.º 2
0
 def patch(name, service):
     if isinstance(service, dict):
         service = TestService(service)
     orig_service = services.get_services().get(name)
     services.register(service, name)
     request.addfinalizer(lambda: services.get_services().pop(name, None))
     if orig_service:
         request.addfinalizer(
             lambda: services.get_services().update({name: orig_service}))
Exemplo n.º 3
0
class Root(object):
    def default(self, *args, **kwargs):
        raise cherrypy.HTTPRedirect(config['default_url'])

    def logout(self, return_to='/'):
        cherrypy.session.pop('username', None)
        raise cherrypy.HTTPRedirect('login?return_to=%s' % return_to)

    def login(self, username='', password='', message='', return_to=''):
        if not config['debug']:
            return 'Login page only available in debug mode.'

        if username:
            if config['debug'] and password == config['debug_password']:
                cherrypy.session['username'] = username
                raise cherrypy.HTTPRedirect(return_to or config['default_url'])
            else:
                message = 'Invalid credentials'

        return {
            'message': message,
            'username': username,
            'return_to': return_to
        }

    def list_plugins(self):
        from sideboard.internal.imports import plugins
        plugin_info = {}
        for plugin, module in plugins.items():
            plugin_info[plugin] = {
                'name': ' '.join(plugin.split('_')).title(),
                'version': getattr(module, '__version__', None),
                'paths': []
            }
        for path, app in cherrypy.tree.apps.items():
            # exclude what Sideboard itself mounts and grafted mount points
            if path and hasattr(app, 'root'):
                plugin = app.root.__module__.split('.')[0]
                plugin_info[plugin]['paths'].append(path)
        return {
            'plugins': plugin_info,
            'version': getattr(sideboard, '__version__', None)
        }

    def connections(self):
        return {'connections': connection_checker.check_all()}

    ws = WebSocketRoot()
    wsrpc = WebSocketRoot()

    json = _make_jsonrpc_handler(services.get_services(), precall=jsonrpc_auth)
    jsonrpc = _make_jsonrpc_handler(services.get_services(),
                                    precall=jsonrpc_reset)
Exemplo n.º 4
0
class Root(object):
    def default(self, *args, **kwargs):
        raise cherrypy.HTTPRedirect(config['default_url'])

    def logout(self, return_to='/'):
        cherrypy.session.pop('username', None)
        raise cherrypy.HTTPRedirect('login?return_to=%s' % return_to)

    def login(self, username='', password='', message='', return_to=''):
        if username:
            if ldap_auth(username, password):
                cherrypy.session['username'] = username
                raise cherrypy.HTTPRedirect(return_to)
            else:
                message = 'Invalid credentials'

        return {
            'message': message,
            'username': username,
            'return_to': return_to
        }

    def list_plugins(self):
        from sideboard.internal.imports import plugins
        plugin_info = {}
        for plugin, module in plugins.items():
            plugin_info[plugin] = {
                'name': ' '.join(plugin.split('_')).title(),
                'version': getattr(module, '__version__', None),
                'paths': []
            }
        for path, app in cherrypy.tree.apps.items():
            if path:  # exclude what Sideboard itself mounts
                plugin = app.root.__module__.split('.')[0]
                plugin_info[plugin]['paths'].append(path)
        return {
            'plugins': plugin_info,
            'version': getattr(sideboard, '__version__', None)
        }

    def connections(self):
        return {'connections': connection_checker.check_all()}

    ws = WebSocketRoot()
    wsrpc = WebSocketRoot()

    json = _make_jsonrpc_handler(services.get_services(), precall=jsonrpc_auth)
    jsonrpc = _make_jsonrpc_handler(
        services.get_services(),
        precall=lambda body: threadlocal.reset(
            username=cherrypy.session.get('username'),
            client=body.get('websocket_client')))
Exemplo n.º 5
0
class SideboardWebSocket(WebSocketDispatcher):
    """
    This web socket handler will be used by browsers connecting to Sideboard web
    sites.  Therefore, the authentication mechanism is the default approach
    of checking the session for a username and rejecting unauthenticated users.
    """
    services = services.get_services()

    @classmethod
    def check_authentication(cls):
        host, origin = cherrypy.request.headers[
            'host'], cherrypy.request.headers['origin']
        if ('//' + host.split(':')[0]) not in origin:
            log.error(
                'Javascript websocket connections must follow same-origin policy; origin {!r} does not match host {!r}',
                origin, host)
            raise WebSocketAuthError('Origin and Host headers do not match')

        if config['ws.auth_required'] and not cherrypy.session.get(
                config['ws.auth_field']):
            log.warning(
                'websocket connections to this address must have a valid session'
            )
            raise WebSocketAuthError('You are not logged in')

        return WebSocketDispatcher.check_authentication()
Exemplo n.º 6
0
def check_all():
    checks = {
        'subscription (jsonrpc)': _check(config['subscription']['jsonrpc_url'],
                                    ca_certs=config['subscription']['subscription_ca'],
                                    keyfile=config['subscription']['subscription_client_key'],
                                    certfile=config['subscription']['subscription_client_cert']),
        'subscription (websockets)': _check(config['subscription']['ws_url'], 
                                       ca_certs=config['subscription']['subscription_ca'],
                                       keyfile=config['subscription']['subscription_client_key'],
                                       certfile=config['subscription']['subscription_client_cert'])
    }
    
    # this whole block of code is terrible
    for name, service in services.get_services().items():
        if service.__class__.__name__ == '_Method':
            proxy = service._send.im_self
            url = '{}://{}/'.format(proxy.type, proxy.host)
            checks[name] = _check(url, ca_certs=proxy.ca_certs, keyfile=proxy.key_file, certfile=proxy.cert_file)
    
    return checks
Exemplo n.º 7
0
 def caller(parsed):
     cherrypy.request.json = parsed
     result = _make_jsonrpc_handler(services.get_services(),
                                    precall=precall)(self=None)
     return result
Exemplo n.º 8
0
 def caller(parsed):
     cherrypy.request.json = parsed
     result = _make_jsonrpc_handler(services.get_services(), precall=precall)(self=None)
     return result