Example #1
0
    def _major_page(self) -> None:
        html.header(
            self._title(),
            breadcrumb=_release_notes_breadcrumb(),
            page_state=_release_switch(major=True),
        )

        html.open_div(id_="release_title")
        html.h1(escape_html(_("Everything")) + html.render_br() + escape_html(_("monitored")))
        html.img(theme.url("images/tribe29.svg"))
        html.close_div()

        html.div(None, id_="release_underline")

        html.open_div(id_="release_content")
        for icon, headline, subline in [
            ("release_deploy", _("Deploy in minutes"), _("From 0 to Monitoring in <10min")),
            ("release_scale", _("With unlimited scale"), _("Hundred thousands of hosts")),
            ("release_automated", _("Highly automated"), _("Let Checkmk do the work for you")),
        ]:
            html.open_div(class_="container")
            html.img(theme.url(f"images/{icon}.svg"))
            html.div(headline)
            html.div(subline)
            html.close_div()
        html.close_div()

        html.open_div(id_="release_footer")
        html.span(_("© 2020 tribe29 GmbH. All Rights Reserved."))
        html.a(_("License aggreement"), href="https://checkmk.com/legal.html", target="_blank")
        html.a(_("Imprint"), href="https://checkmk.com/impressum.html", target="_blank")
        html.close_div()
Example #2
0
    def show(self, breadcrumb: Breadcrumb) -> None:
        html.open_div(class_="breadcrumb")

        for item in breadcrumb:
            if item.url:
                html.a(escape_html(str(item.title)), href=item.url)
            else:
                html.span(escape_html(str(item.title)))

        html.close_div()
Example #3
0
    def _show_crash_report(self, info: CrashInfo) -> None:
        html.h3(_("Crash Report"), class_="table")
        html.open_table(class_=["data", "crash_report"])

        _crash_row(
            _("Exception"), "%s (%s)" % (info["exc_type"], info["exc_value"]), odd=True, pre=True
        )
        _crash_row(
            _("Traceback"), self._format_traceback(info["exc_traceback"]), odd=False, pre=True
        )
        _crash_row(
            _("Local Variables"),
            format_local_vars(info["local_vars"]) if "local_vars" in info else "",
            odd=True,
            pre=True,
        )

        _crash_row(_("Crash Type"), info["crash_type"], odd=False, legend=True)
        _crash_row(
            _("Time"), time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(info["time"])), odd=True
        )
        _crash_row(_("Operating System"), info["os"], False)
        _crash_row(_("Checkmk Version"), info["version"], True)
        _crash_row(_("Edition"), info.get("edition", ""), False)
        _crash_row(_("Core"), info.get("core", ""), True)
        _crash_row(_("Python Version"), info.get("python_version", _("Unknown")), False)

        joined_paths = html.render_br().join(
            [escaping.escape_html(p) for p in info.get("python_paths", [_("Unknown")])]
        )
        _crash_row(_("Python Module Paths"), joined_paths, odd=False)

        html.close_table()
Example #4
0
    def _warn_about_local_files(self, crash_info):
        if crash_info["crash_type"] == "check":
            files = []
            for filepath, _lineno, _func, _line in crash_info["exc_traceback"]:
                if "/local/" in filepath:
                    files.append(filepath)

            if files:
                warn_text = escaping.escape_html(
                    _("The following files located in the local hierarchy of your site are involved in this exception:"
                      ))
                warn_text += html.render_ul(
                    HTML("\n").join(map(html.render_li, files)))
                warn_text += escaping.escape_html(
                    _("Maybe these files are not compatible with your current Checkmk "
                      "version. Please verify and only report this crash when you think "
                      "this should be working."))
                html.show_warning(warn_text)
Example #5
0
    def page(self) -> cmk.gui.pages.PageResult:
        breadcrumb = make_simple_page_breadcrumb(mega_menu_registry["help_links"], _("Info"))
        html.header(
            self._title(),
            breadcrumb=breadcrumb,
        )

        html.open_div(id_="info_title")
        html.h1(escape_html(_("Your monitoring machine")))
        html.a(
            html.render_img(theme.url("images/tribe29.svg")), "https://tribe29.com", target="_blank"
        )
        html.close_div()

        html.div(None, id_="info_underline")

        html.open_div(id_="info_intro_text")
        html.span(_("Open. Effective. Awesome."))
        html.span(
            _(
                "May we present? Monitoring as it's supposed to be: "
                "incredibly quick to install, infinetely scalable, highly customizable and "
                "designed for admins."
            )
        )
        html.span(
            _("Visit our %s to learn more about Checkmk and about the %s.")
            % (
                html.render_a(_("website"), "https://checkmk.com", target="_blank"),
                html.render_a(
                    _("latest version"),
                    "https://checkmk.com/product/latest-version",
                    target="_blank",
                ),
            )
        )
        html.close_div()

        version_major_minor = re.sub(r".\d+$", "", Version(__version__).version_base)
        if version_major_minor:
            current_version_link = "https://checkmk.com/product/checkmk-%s" % version_major_minor
        else:
            current_version_link = "https://checkmk.com/product/latest-version"

        html.open_div(id="info_image")
        html.open_a(href=current_version_link, target="_blank")
        html.img(theme.url("images/monitoring-machine.png"))
        html.close_a()
        html.close_div()

        html.close_div()

        html.open_div(id_="info_footer")
        html.span(_("© %s tribe29 GmbH. All Rights Reserved.") % time.strftime("%Y"))
        html.a(_("License agreement"), href="https://checkmk.com/legal.html", target="_blank")
        html.close_div()
Example #6
0
def insert_manpage_links(text: str) -> HTML:
    parts = text.replace(",", " ").split()
    new_parts: List[HTML] = []
    check_regex = re.compile(r"[-_\.a-z0-9]")
    for part in parts:
        if check_regex.match(part) and os.path.exists(
                cmk.utils.paths.check_manpages_dir + "/" + part):
            url = makeuri_contextless(
                request,
                [
                    ("mode", "check_manpage"),
                    ("check_type", part),
                ],
                filename="wato.py",
            )
            new_parts.append(html.render_a(content=part, href=url))
        else:
            new_parts.append(escape_html(part))
    return HTML(" ").join(new_parts)
Example #7
0
        def render_list(ids, links):
            n = 0
            for entry in links:
                n += 1
                try:
                    if isinstance(entry[1], type(True)):
                        idss = ids + [str(n)]
                        id_ = '/'.join(idss)
                        with foldable_container(treename="customlinks",
                                                id_=id_,
                                                isopen=entry[1],
                                                title=entry[0],
                                                icon="foldable_sidebar"):
                            render_list(idss, entry[2])
                    elif isinstance(entry[1], str):
                        frame = entry[3] if len(entry) > 3 else "main"

                        if len(entry) > 2 and entry[2]:
                            icon_file = entry[2]

                            # Old configs used files named "link_<name>.gif". Those .gif files have
                            # been removed from Checkmk. Replacing such images with the default icon
                            if icon_file.endswith(".gif"):
                                icon_name = "link"
                            else:
                                icon_name = icon_file.rsplit(".",
                                                             1)[0].replace(
                                                                 "icon_", "")
                        else:
                            icon_name = "link"

                        linktext = html.render_icon(icon_name) + HTML(
                            " ") + escape_html(entry[0])

                        simplelink(linktext, entry[1], frame)
                    else:
                        html.write_text(
                            _("Second part of tuple must be list or string, not %s\n"
                              ) % str(entry[1]))
                except Exception as e:
                    html.write_text(
                        _("invalid entry %s: %s<br>\n") % (entry, e))
Example #8
0
def test_escape_html() -> None:
    assert isinstance(escaping.escape_html(""), HTML)
    assert str(escaping.escape_html("")) == ""
    assert str(escaping.escape_html("<script>")) == "&lt;script&gt;"
    assert str(escaping.escape_html("<b>")) == "&lt;b&gt;"
Example #9
0
def _process_icon(
    what: IconObjectType,
    row: Row,
    tags: List[TagID],
    custom_vars: Dict[str, str],
    icon_id: str,
    icon: Icon,
) -> Iterator[ABCIconEntry]:
    # In old versions, the icons produced html code directly. The new API
    # is that the icon functions need to return:
    # a) None          - nothing to be rendered
    # b) single string - the icon name (without .png)
    # c) tuple         - icon, title
    # d) triple        - icon, title, url
    result: Union[None, str, HTML, Tuple[str, str], Tuple[str, str, str]]
    try:
        result = icon.render(what, row, tags, custom_vars)
    except Exception:
        if config.debug:
            raise
        yield IconEntry(
            sort_index=icon.sort_index(),
            icon_name="alert",
            title=_("Exception in icon '%s': %s") %
            (icon_id, traceback.format_exc()),
        )

    if result is None:
        return

    title, url = None, None
    icon_name: str = ""
    if isinstance(result, (str, HTML)):
        # TODO: This is handling the deprecated API with 1.2.7. Remove this one day. But there
        # are icons that still use this API. These need to be cleaned up before.
        # LM: There are icons that still use this API
        if (isinstance(result, str)
                and result[0] == "<") or (isinstance(result, HTML)
                                          and str(result)[0] == "<"):
            # seems like an old format icon (html code). In regular rendering
            # case (html), it can simply be appended to the output. Otherwise
            # extract the icon name from icon images
            if html.output_format == "html":
                if isinstance(result, str):
                    result = escape_html(result)
                yield LegacyIconEntry(sort_index=icon.sort_index(),
                                      code=result)
            else:
                # Strip icon names out of HTML code that is generated by htmllib.render_icon()
                for n in cmk.utils.regex.regex(
                        '<img src="([^"]*)"[^>]*>').findall(str(result)):
                    if n.startswith("images/"):
                        n = n[7:]
                    if n.startswith("icon_"):
                        n = n[5:]
                    if n.endswith(".png"):
                        n = n[:-4]
                    yield IconEntry(sort_index=icon.sort_index(), icon_name=n)
            return

        assert isinstance(result, str)
        icon_name = result
    else:
        # Mypy does not understand the length checking here. Can not easily be fixed, because we
        # would have to change all the icon plugins.
        if len(result) == 2:
            icon_name, title = result  # type: ignore[misc]
        elif len(result) == 3:
            icon_name, title, url = result  # type: ignore[misc]
        else:
            raise NotImplementedError()

    yield IconEntry(
        sort_index=icon.sort_index(),
        icon_name=icon_name,
        title=title,
        url_spec=url,
    )
Example #10
0
    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("&copy; %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()