def __call__(self, environ, start_response): req = http.Request(environ) with AppContext(self), RequestContext(req=req, html_obj=htmllib.html(req)): config.initialize() html.init_modes() return self.wsgi_app(environ, start_response)
def _process_request(environ, start_response) -> Response: # pylint: disable=too-many-branches try: html.init_modes() # Make sure all plugins are available as early as possible. At least # we need the plugins (i.e. the permissions declared in these) at the # time before the first login for generating auth.php. load_all_plugins() page_handler = get_and_wrap_page(html.myfile) response = page_handler() # If page_handler didn't raise we assume everything is OK. response.status_code = http_client.OK except HTTPRedirect as e: # This can't be a new Response as it can have already cookies set/deleted by the pages. # We can't return the response because the Exception has been raised instead. # TODO: Remove all HTTPRedirect exceptions from all pages. Making the Exception a subclass # of Response may also work as it can then be directly returned from here. response = html.response response.status_code = e.status response.headers["Location"] = e.url except FinalizeRequest as e: # TODO: Remove all FinalizeRequest exceptions from all pages and replace it with a `return`. # It may be necessary to rewire the control-flow a bit as this exception could have # been used to short-circuit some code and jump directly to the response. This # needs to be changed as well. response = html.response response.status_code = e.status except livestatus.MKLivestatusNotFoundError as e: response = _render_exception(e, title=_("Data not found")) except MKUserError as e: response = _render_exception(e, title=_("Invalid user Input")) except MKAuthException as e: response = _render_exception(e, title=_("Permission denied")) except livestatus.MKLivestatusException as e: response = _render_exception(e, title=_("Livestatus problem")) response.status_code = http_client.BAD_GATEWAY except MKUnauthenticatedException as e: response = _render_exception(e, title=_("Not authenticated")) response.status_code = http_client.UNAUTHORIZED except MKConfigError as e: response = _render_exception(e, title=_("Configuration error")) logger.error("MKConfigError: %s", e) except MKGeneralException as e: response = _render_exception(e, title=_("General error")) logger.error("MKGeneralException: %s", e) except Exception: response = handle_unhandled_exception() return response(environ, start_response)
def with_context(environ, start_response): req = cmk.gui.http.Request(environ) resp = cmk.gui.http.Response(is_secure=req.is_secure) with AppContext(app), RequestContext(cmk.gui.htmllib.html(req, resp)): config.initialize() html.init_modes() return app(environ, start_response)
def _process_request(self, request, response): # pylint: disable=too-many-branches try: config.initialize() html.init_modes() # Make sure all plugins are available as early as possible. At least # we need the plugins (i.e. the permissions declared in these) at the # time before the first login for generating auth.php. _load_all_plugins() page_handler = get_and_wrap_page(request, html.myfile) page_handler() # If page_handler didn't raise we assume everything is OK. response.status_code = httplib.OK except HTTPRedirect as e: response.status_code = e.status response.headers["Location"] = e.url except FinalizeRequest as e: response.status_code = e.status except livestatus.MKLivestatusNotFoundError as e: _render_exception(e, title=_("Data not found")) except MKUserError as e: _render_exception(e, title=_("Invalid user Input")) except MKAuthException as e: _render_exception(e, title=_("Permission denied")) except livestatus.MKLivestatusException as e: _render_exception(e, title=_("Livestatus problem")) response.status_code = httplib.BAD_GATEWAY except MKUnauthenticatedException as e: _render_exception(e, title=_("Not authenticated")) response.status_code = httplib.UNAUTHORIZED except MKConfigError as e: _render_exception(e, title=_("Configuration error")) logger.error("MKConfigError: %s", e) except MKGeneralException as e: _render_exception(e, title=_("General error")) logger.error("MKGeneralException: %s", e) except Exception: crash = crash_reporting.GUICrashReport.from_exception() crash_reporting.CrashReportStore().save(crash) logger.exception("Unhandled exception (Crash-ID: %s)", crash.ident_to_text()) crash_reporting.show_crash_dump_message(crash, _plain_error(), _fail_silently())