def _render_header_icon() -> None: if user.get_attribute("nav_hide_icons_title"): if theme.has_custom_logo(): html.img(theme.detect_icon_path(icon_name="logo", prefix="mk-"), class_="custom") else: html.img(theme.detect_icon_path(icon_name="icon_min", prefix="tribe29_")) else: if theme.has_custom_logo(): html.img(theme.detect_icon_path(icon_name="logo", prefix="mk-")) else: html.img(theme.detect_icon_path(icon_name="icon", prefix="tribe29_"))
def page(self) -> None: assert user.id is not None html.set_render_headfoot(False) html.add_body_css_class("login") html.add_body_css_class("two_factor") html.header(_("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 consume(self, node_result_bundle: NodeResultBundle, depth: int = 1) -> Dict[str, Any]: instance = node_result_bundle.instance if isinstance(instance, BICompiledRule): node_data = self._get_node_data_for_rule(instance) else: node_data = self._get_node_data_for_leaf(instance) actual_result = node_result_bundle.actual_result if isinstance(instance, BICompiledRule) and instance.properties.icon: node_data["icon"] = theme.detect_icon_path(instance.properties.icon, prefix="icon") node_data["state"] = actual_result.state node_data["in_downtime"] = actual_result.downtime_state > 0 node_data["acknowledged"] = actual_result.acknowledged node_data["children"] = [] for nested_bundle in node_result_bundle.nested_results: node_data["children"].append(self.consume(nested_bundle, depth=depth + 1)) return node_data
def foldable_container( *, treename: str, id_: str, isopen: bool, title: HTMLContent, indent: Union[str, None, bool] = True, first: bool = False, icon: Optional[str] = None, fetch_url: Optional[str] = None, title_url: Optional[str] = None, title_target: Optional[str] = None, padding: int = 15, save_state: bool = True, ) -> Iterator[bool]: isopen = user.get_tree_state(treename, id_, isopen) onclick = foldable_container_onclick(treename, id_, fetch_url, save_state) img_id = foldable_container_img_id(treename, id_) container_id = foldable_container_id(treename, id_) html.open_div(class_=["foldable", "open" if isopen else "closed"]) html.open_div(class_="foldable_header", onclick=None if title_url else onclick) if isinstance(title, HTML): # custom HTML code html.write_text(title) else: html.open_b(class_=["treeangle", "title"]) if title_url: html.a(title, href=title_url, target=title_target) else: html.write_text(title) html.close_b() if icon: html.img( id_=img_id, class_=[ "treeangle", "title", # Although foldable_sidebar is given via the argument icon it should not be # displayed as big as an icon. "icon" if icon != "foldable_sidebar" else None, "open" if isopen else "closed", ], src=theme.detect_icon_path(icon, "icon_"), onclick=onclick if title_url else None, ) else: html.img( id_=img_id, class_=["treeangle", "open" if isopen else "closed"], src=theme.url("images/tree_closed.svg"), onclick=onclick if title_url else None, ) html.close_div() indent_style = "padding-left: %dpx; " % (padding if indent else 0) if indent == "form": html.close_td() html.close_tr() html.close_table() indent_style += "margin: 0; " html.open_ul( id_=container_id, class_=["treeangle", "open" if isopen else "closed"], style=indent_style ) yield isopen html.close_ul() html.close_div()
def _show_login_page(self) -> None: html.set_render_headfoot(False) html.add_body_css_class("login") html.header(get_page_heading(), Breadcrumb(), javascripts=[]) default_origtarget = ("index.py" if requested_file_name(request) in ["login", "logout"] else makeuri(request, [])) origtarget = request.get_url_input("_origtarget", default_origtarget) # Never allow the login page to be opened in the iframe. Redirect top page to login page. # This will result in a full screen login page. html.javascript("""if(top != self) { window.top.location.href = location; }""") # When someone calls the login page directly and is already authed redirect to main page if requested_file_name(request) == "login" and _check_auth(request): raise HTTPRedirect(origtarget) 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() html.begin_form("login", method="POST", add_transid=False, action="login.py") html.hidden_field("_login", "1") html.hidden_field("_origtarget", origtarget) html.label("%s:" % _("Username"), id_="label_user", class_=["legend"], for_="_username") html.br() html.text_input("_username", id_="input_user") html.label("%s:" % _("Password"), id_="label_pass", class_=["legend"], for_="_password") html.br() html.password_input("_password", id_="input_pass", size=None) if user_errors: html.open_div(id_="login_error") html.show_user_errors() html.close_div() html.open_div(id_="button_text") html.button("_login", _("Login"), cssclass="hot") html.close_div() html.close_div() html.open_div(id_="foot") if config.login_screen.get("login_message"): html.open_div(id_="login_message") html.show_message(config.login_screen["login_message"]) html.close_div() footer: List[HTML] = [] for title, url, target in config.login_screen.get("footer_links", []): footer.append(html.render_a(title, href=url, target=target)) if "hide_version" not in config.login_screen: footer.append(escape_html("Version: %s" % cmk_version.__version__)) footer.append( HTML("© %s" % html.render_a( "tribe29 GmbH", href="https://tribe29.com", target="_blank"))) html.write_html(HTML(" - ").join(footer)) if cmk_version.is_raw_edition(): html.br() html.br() html.write_text( _('You can use, modify and distribute Check_MK under the terms of the <a href="%s" target="_blank">' "GNU GPL Version 2</a>.") % "https://checkmk.com/gpl.html") html.close_div() html.set_focus("_username") html.hidden_fields() html.end_form() html.close_div() html.footer()