示例#1
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 += HTMLWriter.render_div(menu_item.title)

        return content
示例#2
0
 def _show_content(self, page_state: PageState) -> None:
     html.div(page_state.text, class_="text_container")
     if page_state.icon_name:
         html.div(
             html.render_icon(page_state.icon_name, id_="page_state_icon"),
             class_="icon_container",
         )
示例#3
0
def render_object_ref_as_icon(
        object_ref: Optional[ObjectRef]) -> Optional[HTML]:
    if object_ref is None:
        return None

    url, title = _get_object_reference(object_ref)
    if not url:
        return None

    icons = {
        ObjectRefType.Host: "host",
        ObjectRefType.Folder: "folder",
        ObjectRefType.User: "******",
        ObjectRefType.Rule: "rule",
        ObjectRefType.Ruleset: "rulesets",
    }

    return HTMLWriter.render_a(
        content=html.render_icon(
            icons.get(object_ref.object_type, "link"),
            title="%s: %s" %
            (object_ref.object_type.name, title) if title else None,
        ),
        href=url,
    )
示例#4
0
    def page(self) -> None:
        html.p(
            _("Here you can add icons, for example to use them in bookmarks or "
              "in custom actions of views. Allowed are single PNG image files "
              "with a maximum size of 80x80 px. Custom actions have to be defined "
              "in the global settings and can be used in the custom icons rules "
              "of hosts and services."))

        html.begin_form("upload_form", method="POST")
        self._vs_upload().render_input("_upload_icon", None)
        html.hidden_fields()
        html.end_form()

        icons = sorted(self._load_custom_icons().items())
        with table_element("icons", _("Custom Icons")) as table:
            for icon_name, category_name in icons:
                table.row()

                table.cell(_("Actions"), css=["buttons"])
                delete_url = make_confirm_link(
                    url=make_action_link([("mode", "icons"),
                                          ("_delete", icon_name)]),
                    message=_(
                        "Do you really want to delete the icon <b>%s</b>?") %
                    icon_name,
                )
                html.icon_button(delete_url, _("Delete this Icon"), "delete")

                table.cell(_("Icon"),
                           html.render_icon(icon_name),
                           css=["buttons"])
                table.cell(_("Name"), icon_name)
                table.cell(_("Category"),
                           IconSelector.category_alias(category_name))
示例#5
0
    def _show_subtree(self, tree, path, show_host):
        if self._is_leaf(tree):
            self._show_leaf(tree, show_host)
            return

        html.open_span(class_="title")

        is_empty = len(tree[3]) == 0
        if is_empty:
            mc = None
        else:
            mc = self._get_mousecode(path)

        css_class = "open" if self._is_open(path) else "closed"

        with self._show_node(tree,
                             show_host,
                             mousecode=mc,
                             img_class=css_class):
            if tree[2].get("icon"):
                html.write_html(html.render_icon(tree[2]["icon"]))
                html.write_text("&nbsp;")

            if tree[2].get("docu_url"):
                html.icon_button(
                    tree[2]["docu_url"],
                    _("Context information about this rule"),
                    "url",
                    target="_blank",
                )
                html.write_text("&nbsp;")

            html.write_text(tree[2]["title"])

        if not is_empty:
            html.open_ul(
                id_="%d:%s" %
                (self._expansion_level or 0, self._path_id(path)),
                class_=["subtree", css_class],
            )

            if not self._omit_content(path):
                for node in tree[3]:
                    if not node[2].get("hidden"):
                        new_path = path + [node[2]["title"]]
                        html.open_li()
                        self._show_subtree(node, new_path, show_host)
                        html.close_li()

            html.close_ul()

        html.close_span()
示例#6
0
    def _show_popup(self, entry: PageMenuEntry) -> None:
        assert isinstance(entry.item, PageMenuPopup)

        if entry.name is None:
            raise ValueError('Missing "name" attribute on entry "%s"' % entry.title)

        classes = ["page_menu_popup"]
        classes += [c for c in entry.item.css_classes if c is not None]
        if isinstance(entry.item, PageMenuSidePopup):
            classes.append("side_popup")

        popup_id = "popup_%s" % entry.name
        html.open_div(id_=popup_id, class_=classes)

        html.open_div(class_="head")
        html.h3(entry.title)
        html.a(
            html.render_icon("close"),
            class_="close_popup",
            href="javascript:void(0)",
            onclick="cmk.page_menu.close_popup(this)",
        )
        html.close_div()

        if (
            isinstance(entry.item, PageMenuSidePopup)
            and entry.item.content
            and "side_popup_content" not in entry.item.content
        ):
            raise RuntimeError(
                'Add a div container with the class "side_popup_content" to the popup content'
            )

        html.open_div(class_="content")
        html.write_html(entry.item.content)
        html.close_div()
        html.close_div()

        if isinstance(entry.item, PageMenuSidePopup):
            html.final_javascript(
                "cmk.page_menu.side_popup_add_simplebar_scrollbar(%s);" % json.dumps(popup_id)
            )
示例#7
0
文件: ldap.py 项目: LinuxHaus/checkmk
    def page(self):
        html.open_div(id_="ldap")
        html.open_table()
        html.open_tr()

        html.open_td()
        html.begin_form("connection", method="POST")
        html.prevent_password_auto_completion()
        vs = self._valuespec()
        vs.render_input("connection", self._connection_cfg)
        vs.set_focus("connection")
        html.hidden_fields()
        html.end_form()
        html.close_td()

        html.open_td(style="padding-left:10px;vertical-align:top")
        html.h2(_("Diagnostics"))
        if not request.var("_test") or not self._connection_id:
            html.show_message(
                HTML("<p>%s</p><p>%s</p>" % (
                    _("You can verify the single parts of your ldap configuration using this "
                      "dialog. Simply make your configuration in the form on the left side and "
                      'hit the "Save & Test" button to execute the tests. After '
                      "the page reload, you should see the results of the test here."
                      ),
                    _("If you need help during configuration or experience problems, please refer "
                      'to the <a target="_blank" '
                      'href="https://checkmk.com/checkmk_multisite_ldap_integration.html">'
                      "LDAP Documentation</a>."),
                )))
        else:
            connection = userdb.get_connection(self._connection_id)
            assert isinstance(connection, LDAPUserConnector)

            for address in connection.servers():
                html.h3("%s: %s" % (_("Server"), address))
                with table_element("test", searchable=False) as table:
                    for title, test_func in self._tests():
                        table.row()
                        try:
                            state, msg = test_func(connection, address)
                        except Exception as e:
                            state = False
                            msg = _("Exception: %s") % e
                            logger.exception("error testing LDAP %s for %s",
                                             title, address)

                        if state:
                            img = html.render_icon("success", _("Success"))
                        else:
                            img = html.render_icon("failed", _("Failed"))

                        table.cell(_("Test"), title)
                        table.cell(_("State"), img)
                        table.cell(_("Details"), msg)

            connection.disconnect()

        html.close_td()
        html.close_tr()
        html.close_table()
        html.close_div()