Ejemplo n.º 1
0
    def show(self):
        # type: () -> None
        filename = Path(cmk.utils.paths.omd_root).joinpath(
            'var/dokuwiki/data/pages/sidebar.txt')

        html.open_form(id_="wiki_search",
                       onsubmit="cmk.sidebar.wiki_search('%s');" %
                       config.omd_site())
        html.input(id_="wiki_search_field", type_="text", name="wikisearch")
        html.icon_button("#",
                         _("Search"),
                         "wikisearch",
                         onclick="cmk.sidebar.wiki_search('%s');" %
                         config.omd_site())
        html.close_form()
        html.div('', id_="wiki_side_clear")

        start_ul = True
        ul_started = False
        try:
            title = None
            for line in filename.open(encoding="utf-8").readlines():
                line = line.strip()
                if line == "":
                    if ul_started:
                        html.end_foldable_container()
                        start_ul = True
                        ul_started = False
                elif line.endswith(":"):
                    title = line[:-1]
                elif line == "----":
                    pass
                    # html.br()

                elif line.startswith("*"):
                    if start_ul:
                        if title:
                            html.begin_foldable_container("wikisnapin",
                                                          title,
                                                          True,
                                                          title,
                                                          indent=True)
                        else:
                            html.open_ul()
                        start_ul = False
                        ul_started = True

                    erg = re.findall(r'\[\[(.*)\]\]', line)
                    if len(erg) == 0:
                        continue
                    erg = erg[0].split('|')
                    if len(erg) > 1:
                        link = erg[0]
                        name = erg[1]
                    else:
                        link = erg[0]
                        name = erg[0]

                    if link.startswith("http://") or link.startswith(
                            "https://"):
                        simplelink(name, link, "_blank")
                    else:
                        erg = name.split(':')
                        if len(erg) > 0:
                            name = erg[-1]
                        else:
                            name = erg[0]
                        bulletlink(
                            name, "/%s/wiki/doku.php?id=%s" %
                            (config.omd_site(), link))

                else:
                    html.write_text(line)

            if ul_started:
                html.close_ul()
        except IOError:
            html.write_html(
                html.render_p(
                    html.render_text(
                        "To get a navigation menu, you have to create a ") +
                    html.render_a("sidebar",
                                  href="/%s/wiki/doku.php?id=%s" %
                                  (config.omd_site(), _("sidebar")),
                                  target="main") +  #
                    html.render_text(" in your wiki first.")))
Ejemplo n.º 2
0
def _process_notify_message(msg):
    msg["id"] = utils.gen_id()
    msg["time"] = time.time()

    if isinstance(msg["dest"], str):
        dest_what = msg["dest"]
    else:
        dest_what = msg["dest"][0]

    if dest_what == "broadcast":
        recipients = list(config.multisite_users.keys())
    elif dest_what == "online":
        recipients = userdb.get_online_user_ids()
    elif dest_what == "list":
        recipients = msg["dest"][1]
    else:
        recipients = []

    num_recipients = len(recipients)

    num_success = {}
    for method in msg["methods"]:
        num_success[method] = 0

    # Now loop all notitification methods to send the notifications
    errors: Dict[str, List[Tuple]] = {}
    for user_id in recipients:
        for method in msg["methods"]:
            try:
                handler = _notify_methods()[method]["handler"]
                handler(user_id, msg)
                num_success[method] = num_success[method] + 1
            except MKInternalError as e:
                errors.setdefault(method, []).append((user_id, e))

    message = escape_html_permissive(_("The notification has been sent via"))
    message += html.render_br()

    parts = []
    for method in msg["methods"]:
        parts.append(
            html.render_tr(
                html.render_td(_notify_methods()[method]["title"])
                + html.render_td(
                    _("to %d of %d recipients") % (num_success[method], num_recipients)
                )
            )
        )
    message += html.render_table(HTML().join(parts))

    message += html.render_p(_("Sent notification to: %s") % ", ".join(recipients))
    message += html.render_a(_("Back to previous page"), href=makeuri(request, []))
    html.show_message(message)

    if errors:
        error_message = HTML()
        for method, method_errors in errors.items():
            error_message += _("Failed to send %s notifications to the following users:") % method
            table_rows = HTML()
            for user_id, exception in method_errors:
                table_rows += html.render_tr(
                    html.render_td(html.render_tt(user_id)) + html.render_td(exception)
                )
            error_message += html.render_table(table_rows) + html.render_br()
        html.show_error(error_message)
Ejemplo n.º 3
0
def _process_message_message(msg):
    msg["id"] = utils.gen_id()
    msg["time"] = time.time()

    if isinstance(msg["dest"], str):
        dest_what = msg["dest"]
    else:
        dest_what = msg["dest"][0]

    if dest_what == "all_users":
        recipients = list(config.multisite_users.keys())
    elif dest_what == "online":
        recipients = userdb.get_online_user_ids()
    elif dest_what == "list":
        recipients = msg["dest"][1]
    else:
        recipients = []

    num_recipients = len(recipients)

    num_success: Dict[str, int] = {}
    for method in msg["methods"]:
        num_success[method] = 0

    # Now loop all messaging methods to send the messages
    errors: Dict[str, List[Tuple]] = {}
    for user_id in recipients:
        for method in msg["methods"]:
            try:
                handler = _messaging_methods()[method]["handler"]
                handler(user_id, msg)
                num_success[method] = num_success[method] + 1
            except MKInternalError as e:
                errors.setdefault(method, []).append((user_id, e))

    message = escape_html_permissive(
        _("The message has successfully been sent..."))
    message += html.render_br()

    parts = []
    for method in msg["methods"]:
        parts.append(
            html.render_li(
                _messaging_methods()[method]["confirmation_title"] +
                (_(" for all recipients.") if num_success[method] ==
                 num_recipients else _(" for %d of %d recipients.") %
                 (num_success[method], num_recipients))))

    message += html.render_ul(HTML().join(parts))
    message += html.render_p(_("Recipients: %s") % ", ".join(recipients))
    html.show_message(message)

    if errors:
        error_message = HTML()
        for method, method_errors in errors.items():
            error_message += _(
                "Failed to send %s messages to the following users:") % method
            table_rows = HTML()
            for user_id, exception in method_errors:
                table_rows += html.render_tr(
                    html.render_td(html.render_tt(user_id)) +
                    html.render_td(str(exception)))
            error_message += html.render_table(table_rows) + html.render_br()
        html.show_error(error_message)