def test_get_url_input_invalid_urls( request_context: RequestContextFixture, invalid_url: str ) -> None: html.request.set_var("varname", invalid_url) with pytest.raises(MKUserError) as e: global_request.get_url_input("varname") assert "not a valid URL" in "%s" % e
def page(self) -> None: title = _("Replicate user profile") breadcrumb = make_simple_page_breadcrumb( mega_menu_registry.menu_user(), title) make_header(html, title, breadcrumb, self._page_menu(breadcrumb)) for message in get_flashed_messages(): html.show_message(message) # Now, if in distributed environment where users can login to remote sites, set the trigger for # pushing the new user profile to the remote sites asynchronously user_profile_async_replication_page( back_url=request.get_url_input("back", "user_profile.py"))
def test_get_url_input(request_context: RequestContextFixture) -> None: global_request.set_var("url", "view.py?bla=blub") global_request.set_var("no_url", "2") global_request.set_var("invalid_url", "http://bla/") with pytest.raises(MKUserError) as e: global_request.get_url_input("not_existing") assert "is missing" in "%s" % e assert global_request.get_url_input("get_default", "my_url.py") == "my_url.py" assert global_request.get_url_input("get_default", "http://bla/") == "http://bla/" assert global_request.get_url_input("url") == "view.py?bla=blub" assert global_request.get_url_input("no_url") == "2" with pytest.raises(MKUserError) as e: global_request.get_url_input("invalid_url") assert "not a valid" in "%s" % e assert global_request.get_url_input("no_url") == "2"
def _paint_download_host_info(what, row, tags, host_custom_vars, ty): if ((what == "host" or (what == "service" and row["service_description"] == "Check_MK")) and user.may("wato.download_agent_output") and not row["host_check_type"] == 2): # Not for shadow hosts # Not 100% acurate to use the tags here, but this is the best we can do # with the available information. # Render "download agent output" for non agent hosts, because there might # be piggyback data available which should be downloadable. if ty == "walk" and "snmp" not in tags: return None if ty == "agent" and "snmp" in tags and "tcp" not in tags: return None params = [ ("host", row["host_name"]), ("folder", _wato_folder_from_filename(row["host_filename"])), ("type", ty), ("_start", "1"), ] # When the download icon is part of the host/service action menu, then # the _back_url set in paint_action_menu() needs to be used. Otherwise # makeuri(request, []) (not request.requested_uri()) is the right choice. back_url = request.get_url_input("_back_url", makeuri(request, [])) if back_url: params.append(("back_url", back_url)) if ty == "agent": title = _("Download agent output") else: title = _("Download SNMP walk") url = makeuri_contextless(request, params, filename="fetch_agent_output.py") return "agents", title, url return None
def page(self) -> None: assert user.id is not None html.render_headfoot = False html.add_body_css_class("login") html.add_body_css_class("two_factor") make_header(html, _("Two-factor authentication"), Breadcrumb(), javascripts=[]) html.open_div(id_="login") html.open_div(id_="login_window") html.open_a(href="https://checkmk.com") html.img( src=theme.detect_icon_path(icon_name="logo", prefix="mk-"), id_="logo", class_="custom" if theme.has_custom_logo() else None, ) html.close_a() if not is_two_factor_login_enabled(user.id): raise MKGeneralException( _("Two-factor authentication not enabled")) html.begin_form("two_factor_login", method="POST", add_transid=False, action="user_login_two_factor.py") html.prevent_password_auto_completion() html.hidden_field( "_origtarget", origtarget := request.get_url_input("_origtarget", "index.py")) if backup_code := request.get_ascii_input("_backup_code"): if is_two_factor_backup_code_valid(user.id, backup_code): set_two_factor_completed() raise HTTPRedirect(origtarget)
def page_login() -> None: title = _("Checkmk Mobile") mobile_html_head(title) jqm_page_header(title, id_="login") html.div(_("Welcome to Checkmk Mobile."), id_="loginhead") html.begin_form("login", method="POST", add_transid=False) # Keep information about original target URL default_origtarget = ( "index.py" if requested_file_name(request) in ["login", "logout"] else makeuri(request, []) ) origtarget = request.get_url_input("_origtarget", default_origtarget) html.hidden_field("_origtarget", escaping.escape_attribute(origtarget)) html.text_input("_username", label=_("Username:"******"username", id_="input_user") html.password_input( "_password", size=None, label=_("Password:"******"current-password", id_="input_pass", ) html.br() html.button("_login", _("Login")) html.set_focus("_username") html.end_form() html.open_div(id_="loginfoot") html.img("themes/facelift/images/logo_cmk_small.png", class_="logomk") html.div( HTML(_('© <a target="_blank" href="https://checkmk.com">tribe29 GmbH</a>')), class_="copyright", ) html.close_div() # close content-div html.close_div() html.close_div() # close page-div mobile_html_foot()
def _get_start_url() -> str: default_start_url = user.start_url or active_config.start_url if not utils.is_allowed_url(default_start_url): default_start_url = "dashboard.py" return request.get_url_input("start_url", default_start_url)