def _handle_not_authenticated() -> Response: if fail_silently(): # While api call don't show the login dialog raise MKUnauthenticatedException(_("You are not authenticated.")) # Redirect to the login-dialog with the current url as original target # Never render the login form directly when accessing urls like "index.py" # or "dashboard.py". This results in strange problems. requested_file = requested_file_name(request) if requested_file != "login": post_login_url = makeuri(request, []) if requested_file != "index": # Ensure that users start with a navigation after they have logged in post_login_url = makeuri_contextless( request, [("start_url", post_login_url)], filename="index.py" ) raise HTTPRedirect( "%scheck_mk/login.py?_origtarget=%s" % (url_prefix(), urlencode(post_login_url)) ) # This either displays the login page or validates the information submitted # to the login form. After successful login a http redirect to the originally # requested page is performed. login_page = login.LoginPage() login_page.set_no_html_output(plain_error()) login_page.handle_page() return response
def ajax_graph_images_for_notifications(): if request.remote_ip not in ["127.0.0.1", "::1"]: raise MKUnauthenticatedException( _("You are not allowed to access this page (%s).") % request.remote_ip) with SuperUserContext(): _answer_graph_image_request()
def _handle_not_authenticated(): if _fail_silently(): # While api call don't show the login dialog raise MKUnauthenticatedException(_('You are not authenticated.')) # Redirect to the login-dialog with the current url as original target # Never render the login form directly when accessing urls like "index.py" # or "dashboard.py". This results in strange problems. if html.myfile != 'login': raise HTTPRedirect( '%scheck_mk/login.py?_origtarget=%s' % (config.url_prefix(), html.urlencode(html.makeuri([])))) # This either displays the login page or validates the information submitted # to the login form. After successful login a http redirect to the originally # requested page is performed. login_page = login.LoginPage() login_page.set_no_html_output(_plain_error()) login_page.handle_page()
def ajax_graph_images_for_notifications(): graphs = [] if html.request.remote_ip not in ["127.0.0.1", "::1"]: raise MKUnauthenticatedException( _("You are not allowed to access this page (%s).") % html.request.remote_ip) config.set_super_user() try: host_name = html.request.var("host") if not host_name: raise MKGeneralException(_("Missing mandatory \"host\" parameter")) service_description = html.request.var("service", "_HOST_") site = html.request.var("site") # FIXME: We should really enforce site here. But it seems that the notification context # has no idea about the site of the host. This could be optimized later. #if not site: # raise MKGeneralException("Missing mandatory \"site\" parameter") try: row = get_graph_data_from_livestatus(site, host_name, service_description) except livestatus.MKLivestatusNotFoundError: if config.debug: raise raise Exception( _("Cannot render graph: host %s, service %s not found.") % (host_name, service_description)) site = row["site"] # Always use 25h graph in notifications end_time = time.time() start_time = end_time - (25 * 3600) graph_render_options = graph_image_render_options() graph_identification = ( "template", { "site": site, "host_name": host_name, "service_description": service_description, "graph_index": None, # all graphs }) graph_data_range = graph_image_data_range(graph_render_options, start_time, end_time) graph_recipes = graph_identification_types.create_graph_recipes( graph_identification, destination=html_render.GraphDestinations.notification) num_graphs = html.request.get_integer_input("num_graphs") or len( graph_recipes) for graph_recipe in graph_recipes[:num_graphs]: graph_artwork = artwork.compute_graph_artwork( graph_recipe, graph_data_range, graph_render_options) graph_png = render_graph_image(graph_artwork, graph_data_range, graph_render_options) graphs.append(base64.b64encode(graph_png).decode("ascii")) html.write(json.dumps(graphs)) except Exception as e: logger.error("Call to ajax_graph_images.py failed: %s\n%s", e, traceback.format_exc()) if config.debug: raise