def configure_app(app, set_path=False): cfg = Config.getInstance() app.config['DEBUG'] = cfg.getDebug() app.config['PROPAGATE_EXCEPTIONS'] = True app.config['SESSION_COOKIE_NAME'] = 'indico_session' app.config['PERMANENT_SESSION_LIFETIME'] = cfg.getSessionLifetime() app.config['INDICO_SESSION_PERMANENT'] = cfg.getSessionLifetime() > 0 app.config['INDICO_HTDOCS'] = cfg.getHtdocsDir() app.config['INDICO_COMPAT_ROUTES'] = cfg.getRouteOldUrls() if set_path: base = url_parse(cfg.getBaseURL()) app.config['SERVER_NAME'] = base.netloc if base.path: app.config['APPLICATION_ROOT'] = base.path app.config['WTF_CSRF_ENABLED'] = False # for forms of room booking static_file_method = cfg.getStaticFileMethod() if static_file_method: app.config['USE_X_SENDFILE'] = True method, args = static_file_method if method in ('xsendfile', 'lighttpd'): # apache mod_xsendfile, lighttpd pass elif method in ('xaccelredirect', 'nginx'): # nginx if not args or not hasattr(args, 'items'): raise ValueError( 'StaticFileMethod args must be a dict containing at least one mapping' ) app.wsgi_app = XAccelMiddleware(app.wsgi_app, args) else: raise ValueError('Invalid static file method: %s' % method)
def configure_xsendfile(app, method): if not method: return elif isinstance(method, str): args = None else: method, args = method if not method: return app.config['USE_X_SENDFILE'] = True if method == 'xsendfile': # apache mod_xsendfile, lighttpd pass elif method == 'xaccelredirect': # nginx if not args or not hasattr(args, 'items'): raise ValueError('STATIC_FILE_METHOD args must be a dict containing at least one mapping') app.wsgi_app = XAccelMiddleware(app.wsgi_app, args) else: raise ValueError('Invalid static file method: %s' % method)
def configure_app(app, set_path=False): cfg = Config.getInstance() app.config['DEBUG'] = cfg.getDebug() app.config['SECRET_KEY'] = cfg.getSecretKey() if not app.config['SECRET_KEY'] or len(app.config['SECRET_KEY']) < 16: raise ValueError( 'SecretKey must be set to a random secret of at least 16 characters. ' 'You can generate one using os.urandom(32) in Python shell.') if cfg.getMaxUploadFilesTotalSize() > 0: app.config['MAX_CONTENT_LENGTH'] = cfg.getMaxUploadFilesTotalSize( ) * 1024 * 1024 app.config['PROPAGATE_EXCEPTIONS'] = True app.config['SESSION_COOKIE_NAME'] = 'indico_session' app.config['PERMANENT_SESSION_LIFETIME'] = cfg.getSessionLifetime() app.config['INDICO_SESSION_PERMANENT'] = cfg.getSessionLifetime() > 0 app.config['INDICO_HTDOCS'] = cfg.getHtdocsDir() app.config['INDICO_COMPAT_ROUTES'] = cfg.getRouteOldUrls() configure_multipass(app) app.config['PLUGINENGINE_NAMESPACE'] = 'indico.plugins' app.config['PLUGINENGINE_PLUGINS'] = cfg.getPlugins() if set_path: base = url_parse(cfg.getBaseURL()) app.config['PREFERRED_URL_SCHEME'] = base.scheme app.config['SERVER_NAME'] = base.netloc if base.path: app.config['APPLICATION_ROOT'] = base.path static_file_method = cfg.getStaticFileMethod() if static_file_method: app.config['USE_X_SENDFILE'] = True method, args = static_file_method if method in ('xsendfile', 'lighttpd'): # apache mod_xsendfile, lighttpd pass elif method in ('xaccelredirect', 'nginx'): # nginx if not args or not hasattr(args, 'items'): raise ValueError( 'StaticFileMethod args must be a dict containing at least one mapping' ) app.wsgi_app = XAccelMiddleware(app.wsgi_app, args) else: raise ValueError('Invalid static file method: %s' % method) if Config.getInstance().getUseProxy(): app.wsgi_app = ProxyFix(app.wsgi_app)