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)
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')))
static_views = StaticViews() angular = AngularJavascript() mount_site_sections(c.MODULE_ROOT) def error_page_404(status, message, traceback, version): return "Sorry, page not found!<br/><br/>{}<br/>{}".format(status, message) c.APPCONF['/']['error_page.404'] = error_page_404 cherrypy.tree.mount(Root(), c.PATH, c.APPCONF) static_overrides(os.path.join(c.MODULE_ROOT, 'static')) jsonrpc_services = {} def register_jsonrpc(service, name=None): name = name or service.__name__ assert name not in jsonrpc_services, '{} has already been registered'.format( name) jsonrpc_services[name] = service jsonrpc_handler = _make_jsonrpc_handler(jsonrpc_services, precall=jsonrpc_reset) cherrypy.tree.mount(jsonrpc_handler, os.path.join(c.PATH, 'jsonrpc'), c.APPCONF)
def caller(parsed): cherrypy.request.json = parsed result = _make_jsonrpc_handler(services.get_services(), precall=precall)(self=None) return result