コード例 #1
0
ファイル: werks.py プロジェクト: m3rlinux/checkmk
def render_werk_title(werk) -> HTML:
    title = werk["title"]
    # if the title begins with the name or names of check plugins, then
    # we link to the man pages of those checks
    if ":" in title:
        parts = title.split(":", 1)
        return insert_manpage_links(parts[0]) + escape_to_html_permissive(":" + parts[1])
    return escape_to_html_permissive(title)
コード例 #2
0
def query_limit_exceeded_warn(limit: Optional[int],
                              user_config: LoggedInUser) -> None:
    """Compare query reply against limits, warn in the GUI about incompleteness"""
    text = HTML(_("Your query produced more than %d results. ") % limit)

    if request.get_ascii_input(
            "limit",
            "soft") == "soft" and user_config.may("general.ignore_soft_limit"):
        text += html.render_a(
            _("Repeat query and allow more results."),
            target="_self",
            href=makeuri(request, [("limit", "hard")]),
        )
    elif request.get_ascii_input("limit") == "hard" and user_config.may(
            "general.ignore_hard_limit"):
        text += html.render_a(
            _("Repeat query without limit."),
            target="_self",
            href=makeuri(request, [("limit", "none")]),
        )

    text += escaping.escape_to_html_permissive(" " + _(
        "<b>Note:</b> the shown results are incomplete and do not reflect the sort order."
    ))
    html.show_warning(text)
コード例 #3
0
    def _render_message(
        self,
        msg: Union[HTML, str],
        msg_type: Literal["message", "warning", "error"] = "message",
    ) -> HTML:
        if msg_type == "message":
            cls = "success"
            prefix = _("MESSAGE")
        elif msg_type == "warning":
            cls = "warning"
            prefix = _("WARNING")
        elif msg_type == "error":
            cls = "error"
            prefix = _("ERROR")
        else:
            raise TypeError(msg_type)

        if self.output_format == "html":
            code = HTMLWriter.render_div(msg, class_=cls)
            if self.mobile:
                return HTMLWriter.render_center(code)
            return code
        return escaping.escape_to_html_permissive(
            "%s: %s\n" % (prefix, escaping.strip_tags(msg)),
            escape_links=False)
コード例 #4
0
ファイル: rendering.py プロジェクト: m3rlinux/checkmk
def text_with_links_to_user_translated_html(
    elements: Iterable[Tuple[str, Optional[str]]],
    separator: str = "",
) -> HTML:
    return HTML(separator).join(
        html.render_a(user_translation, href=url, title=user_translation
                      ) if url else escape_to_html_permissive(
                          user_translation, escape_links=False)
        for txt, url in elements for user_translation in [_u(txt)] if txt)
コード例 #5
0
 def show_user_errors(self) -> None:
     """Show all previously created user errors"""
     if user_errors:
         self.show_error(
             HTMLWriter.render_br().join(
                 escaping.escape_to_html_permissive(s, escape_links=False)
                 for s in user_errors.values()
             )
         )
コード例 #6
0
ファイル: table.py プロジェクト: Bastian-Kuhn/checkmk
    def _add_cell(
        self,
        title: "HTMLContent" = "",
        text: "HTMLContent" = "",
        css: Optional["CSSSpec"] = None,
        help_txt: Optional[str] = None,
        colspan: Optional[int] = None,
        sortable: bool = True,
    ):
        if isinstance(text, HTML):
            content = text
        else:
            content = escape_to_html_permissive(
                str(text) if not isinstance(text, str) else text,
                escape_links=False)

        htmlcode: HTML = content + HTML(output_funnel.drain())

        if isinstance(title, HTML):
            header_title = title
        else:
            if title is None:
                title = ""
            header_title = escape_to_html_permissive(
                str(title) if not isinstance(title, str) else title,
                escape_links=False)

        if self.options["collect_headers"] is True:
            # small helper to make sorting introducion easier. Cells which contain
            # buttons are never sortable
            if css and "buttons" in css and sortable:
                sortable = False
            self.headers.append(
                TableHeader(title=header_title,
                            css=css,
                            help_txt=help_txt,
                            sortable=sortable))

        current_row = self.rows[-1]
        assert isinstance(current_row, TableRow)
        current_row.cells.append(CellSpec(htmlcode, css, colspan))
コード例 #7
0
 def show_localization_hint(self) -> None:
     url = "wato.py?mode=edit_configvar&varname=user_localizations"
     self._write(
         self._render_message(
             HTMLWriter.render_sup("*")
             + escaping.escape_to_html_permissive(
                 _(
                     "These texts may be localized depending on the users' "
                     "language. You can configure the localizations "
                     "<a href='%s'>in the global settings</a>."
                 )
                 % url,
                 escape_links=False,
             ),
             "message",
         )
     )
コード例 #8
0
    def _preview(self) -> None:
        html.begin_form("preview", method="POST")
        self._preview_form()

        attributes = self._attribute_choices()

        # first line could be missing in situation of import error
        csv_reader = self._open_csv_file()
        if not csv_reader:
            return  # don't try to show preview when CSV could not be read

        html.h2(_("Preview"))
        attribute_list = "<ul>%s</ul>" % "".join(
            ["<li>%s (%s)</li>" % a for a in attributes if a[0] is not None])
        html.help(
            _("This list shows you the first 10 rows from your CSV file in the way the import is "
              "currently parsing it. If the lines are not splitted correctly or the title line is "
              "not shown as title of the table, you may change the import settings above and try "
              "again.") + "<br><br>" +
            _("The first row below the titles contains fields to specify which column of the "
              "CSV file should be imported to which attribute of the created hosts. The import "
              "progress is trying to match the columns to attributes automatically by using the "
              "titles found in the title row (if you have some). "
              "If you use the correct titles, the attributes can be mapped automatically. The "
              "currently available attributes are:") + attribute_list +
            _("You can change these assignments according to your needs and then start the "
              "import by clicking on the <i>Import</i> button above."))

        # Wenn bei einem Host ein Fehler passiert, dann wird die Fehlermeldung zu dem Host angezeigt, so dass man sehen kann, was man anpassen muss.
        # Die problematischen Zeilen sollen angezeigt werden, so dass man diese als Block in ein neues CSV-File eintragen kann und dann diese Datei
        # erneut importieren kann.
        if self._has_title_line:
            try:
                headers = list(next(csv_reader))
            except StopIteration:
                headers = []  # nope, there is no header
        else:
            headers = []

        rows = list(csv_reader)

        # Determine how many columns should be rendered by using the longest column
        num_columns = max([len(r) for r in [headers] + rows])

        with table_element(sortable=False,
                           searchable=False,
                           omit_headers=not self._has_title_line) as table:

            # Render attribute selection fields
            table.row()
            for col_num in range(num_columns):
                header = headers[col_num] if len(headers) > col_num else None
                table.cell(escape_to_html_permissive(header))
                attribute_varname = "attribute_%d" % col_num
                if request.var(attribute_varname):
                    attribute_method = request.get_ascii_input_mandatory(
                        attribute_varname)
                else:
                    attribute_method = self._try_detect_default_attribute(
                        attributes, header)
                    request.del_var(attribute_varname)

                html.dropdown("attribute_%d" % col_num,
                              attributes,
                              deflt=attribute_method,
                              autocomplete="off")

            # Render sample rows
            for row in rows:
                table.row()
                for cell in row:
                    table.cell(None, cell)

        html.end_form()
コード例 #9
0
ファイル: test_escaping.py プロジェクト: LinuxHaus/checkmk
def test_escape_to_html_permissive() -> None:
    assert isinstance(escaping.escape_to_html_permissive(""), HTML)
    assert str(escaping.escape_to_html_permissive("")) == ""
    assert str(escaping.escape_to_html_permissive("<script>")) == "&lt;script&gt;"
    assert str(escaping.escape_to_html_permissive("<b>")) == "<b>"