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 render_icon( icon: Icon, title: Optional[str] = None, id_: Optional[str] = None, cssclass: Optional[str] = None, class_: Optional[CSSSpec] = None, ) -> HTML: classes = ["icon"] + ([] if cssclass is None else [cssclass]) if isinstance(class_, list): classes.extend(class_) elif class_ is not None: classes.append(class_) icon_name = icon["icon"] if isinstance(icon, dict) else icon src = icon_name if "/" in icon_name else theme.detect_icon_path(icon_name, prefix="icon_") if src.endswith(".png"): classes.append("png") if src.endswith("/icon_missing.svg") and title: title += " (%s)" % _("icon not found") icon_element = render_start_tag( "img", close_tag=True, title=title, id_=id_, class_=classes, src=src, ) if isinstance(icon, dict) and icon["emblem"] is not None: return HTMLGenerator.render_emblem(icon["emblem"], title, id_, icon_element) return icon_element
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 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 render_emblem( emblem: str, title: Optional[str], id_: Optional[str], icon_element: Optional[HTML] = None, ) -> HTML: """Render emblem to corresponding icon (icon_element in function call) or render emblem itself as icon image, used e.g. in view options.""" emblem_path = theme.detect_icon_path(emblem, prefix="emblem_") if not icon_element: return render_start_tag( "img", close_tag=True, title=title, id_=id_, class_="icon", src=emblem_path, ) return HTMLWriter.render_span( icon_element + HTMLWriter.render_img(emblem_path, class_="emblem"), class_="emblem", )
def foldable_container( *, treename: str, id_: str, isopen: bool, title: HTMLContent, indent: Union[str, None, bool] = True, 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, # Although foldable_sidebar is given via the argument icon it should not be displayed as big as an icon. class_=(["treeangle", "title"] + (["icon"] if icon != "foldable_sidebar" else []) + ["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()