Ejemplo n.º 1
0
    def _show_sidebar(self) -> None:
        if not user.may("general.see_sidebar"):
            html.div("", id_="check_mk_navigation")
            return

        user_config = UserSidebarConfig(user, config.sidebar)

        html.open_div(
            id_="check_mk_navigation",
            class_="min"
            if user.get_attribute("nav_hide_icons_title") else None,
        )
        self._show_sidebar_head()
        html.close_div()

        assert user.id is not None
        sidebar_position = cmk.gui.userdb.load_custom_attr(
            user.id, "ui_sidebar_position", lambda x: None
            if x == "None" else "left")
        html.open_div(id_="check_mk_sidebar", class_=[sidebar_position])

        self._show_snapin_bar(user_config)

        html.close_div()

        if user_config.folded:
            html.final_javascript("cmk.sidebar.fold_sidebar();")
Ejemplo n.º 2
0
    def _get_popup_trigger_content(self, active_icon: Icon, menu_item: MainMenuItem) -> HTML:
        content = html.render_icon(menu_item.icon) + html.render_icon(active_icon, class_="active")

        if not user.get_attribute("nav_hide_icons_title"):
            content += html.render_div(menu_item.title)

        return content
Ejemplo n.º 3
0
    def _show_main_menu_content(self) -> None:
        for menu_item in self._get_main_menu_items():
            if isinstance(menu_item.icon, dict):
                active_icon: Icon = {
                    "icon": menu_item.icon["icon"] + "_active",
                    "emblem": menu_item.icon["emblem"],
                }
            else:
                active_icon = menu_item.icon + "_active"

            html.open_li()
            html.popup_trigger(
                (self._get_popup_trigger_content(active_icon, menu_item)),
                ident="mega_menu_" + menu_item.name,
                method=MethodInline(self._get_mega_menu_content(menu_item)),
                cssclass=menu_item.name,
                popup_group="main_menu_popup",
                hover_switch_delay=150,  # ms
                onopen=menu_item.onopen,
            )
            html.div(
                "",
                id_="popup_shadow",
                onclick="cmk.popup_menu.close_popup()",
                class_="min"
                if user.get_attribute("nav_hide_icons_title") else None,
            )
            html.close_li()
Ejemplo n.º 4
0
def _check_permissions(api_call):
    if not user.get_attribute("automation_secret"):
        raise MKAuthException("The API is only available for automation users")

    if not config.wato_enabled:
        raise MKUserError(None, _("Setup is disabled on this site."))

    for permission in ["wato.use", "wato.api_allowed"] + api_call.get("required_permissions", []):
        user.need_permission(permission)
Ejemplo n.º 5
0
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_"))
Ejemplo n.º 6
0
 def _show_item(self, item: TopicMenuItem) -> None:
     html.open_li(class_="show_more_mode" if item.is_show_more else None)
     html.open_a(
         href=item.url,
         target=item.target,
         onclick="cmk.popup_menu.close_popup()",
     )
     if user.get_attribute("icons_per_item"):
         html.icon(item.icon or "dash")
     self._show_item_title(item)
     html.close_a()
     html.close_li()
Ejemplo n.º 7
0
 def _show_items(self, topic_id: str, topic: TopicMenuTopic) -> None:
     html.open_ul()
     for item in sorted(topic.items, key=lambda g: g.sort_index):
         self._show_item(item)
     html.open_li(class_="show_all_items")
     html.open_a(href="", onclick="cmk.popup_menu.mega_menu_show_all_items('%s')" % topic_id)
     if user.get_attribute("icons_per_item"):
         html.icon("trans")
     html.write_text(_("Show all"))
     html.close_a()
     html.close_li()
     html.close_ul()
Ejemplo n.º 8
0
def get_ntop_misconfiguration_reason() -> str:
    if not is_ntop_available():
        return _("ntopng integration is only available in CEE")
    ntop = get_ntop_connection()
    assert isinstance(ntop, dict)
    if not ntop.get("is_activated", False):
        return _("ntopng integration is not activated under global settings.")
    custom_attribute_name = ntop.get("use_custom_attribute_as_ntop_username", "")
    if custom_attribute_name and not user.get_attribute(custom_attribute_name, ""):
        return _("The ntopng username should be derived from \'ntopng Username\' "
                 "under the current's user settings (identity) but this is not "
                 "set for the current user.")
    return ""
Ejemplo n.º 9
0
 def _show_topic_title(self, menu_id: str, topic_id: str, topic: TopicMenuTopic) -> None:
     html.open_h2()
     html.open_a(
         class_="show_all_topics",
         href="",
         onclick="cmk.popup_menu.mega_menu_show_all_topics('%s')" % topic_id,
     )
     html.icon(icon="collapse_arrow", title=_("Show all %s topics") % menu_id)
     html.close_a()
     if not user.get_attribute("icons_per_item") and topic.icon:
         html.icon(topic.icon)
     html.span(topic.title)
     html.close_h2()
Ejemplo n.º 10
0
 def _get_mega_menu_content(self, menu_item: MainMenuItem) -> str:
     with output_funnel.plugged():
         menu = mega_menu_registry[menu_item.name]
         html.open_div(
             id_="popup_menu_%s" % menu_item.name,
             class_=[
                 "popup_menu",
                 "main_menu_popup",
                 "min" if user.get_attribute("nav_hide_icons_title") else None,
             ],
         )
         MegaMenuRenderer().show(menu)
         html.close_div()
         return output_funnel.drain()
Ejemplo n.º 11
0
def is_ntop_configured() -> bool:
    # Use this function if you want to know if the connection to ntop is fully set-up
    # e.g. to decide if ntop links should be hidden
    ntop = get_ntop_connection()

    if is_ntop_available() and isinstance(ntop, dict):
        custom_attribute_name = ntop.get(
            "use_custom_attribute_as_ntop_username", "")
        # We currently have two options to get an ntop username
        # 1) User needs to define his own -> if this string is empty, declare ntop as not configured
        # 2) Take the checkmk username as ntop username -> always declare ntop as configured
        return bool(
            isinstance(custom_attribute_name, str) and user.get_attribute(
                custom_attribute_name, "")) or not custom_attribute_name
    return False
Ejemplo n.º 12
0
def is_ntop_configured() -> bool:
    # Use this function if you want to know if the connection to ntop is fully set-up
    # e.g. to decide if ntop links should be hidden

    if is_ntop_available():
        ntop = get_ntop_connection_mandatory()
        if not ntop.get("is_activated", False):
            return False
        custom_attribute_name = ntop.get("use_custom_attribute_as_ntop_username", False)

        # We currently have two options to get an ntop username
        # 1) User needs to define his own -> if this string is empty, declare ntop as not configured
        # 2) Take the checkmk username as ntop username -> always declare ntop as configured
        return (bool(user.get_attribute(custom_attribute_name, '')) if isinstance(
            custom_attribute_name, str) else not custom_attribute_name)

    return False
Ejemplo n.º 13
0
    def _show_sidebar_head(self):
        html.open_div(id_="side_header")
        html.open_a(
            href=user.start_url or config.start_url,
            target="main",
            title=_("Go to main page"),
        )
        _render_header_icon()
        html.close_a()
        html.close_div()

        MainMenuRenderer().show()

        html.open_div(id_="side_fold",
                      title=_("Toggle the sidebar"),
                      onclick="cmk.sidebar.toggle_sidebar()")
        html.icon("sidebar_folded", class_="folded")
        html.icon("sidebar")
        if not user.get_attribute("nav_hide_icons_title"):
            html.div(_("Sidebar"))
        html.close_div()