def page(self):
        if not self._analyze_sites():
            html.show_info(
                _("Analyze configuration can only be used with the local site and "
                  "distributed WATO slave sites. You currently have no such site configured."
                  ))
            return

        results_by_category = self._perform_tests()

        site_ids = sorted(self._analyze_sites())

        for category_name, results_by_test in sorted(
                results_by_category.items(),
                key=lambda x: ACTestCategories.title(x[0])):
            with table_element(title=ACTestCategories.title(category_name),
                               css="data analyze_config",
                               sortable=False,
                               searchable=False) as table:

                for test_id, test_results_by_site in sorted(
                        results_by_test.items(),
                        key=lambda x: x[1]["test"]["title"]):
                    self._show_test_row(table, test_id, test_results_by_site,
                                        site_ids)
Beispiel #2
0
    def _activation_form(self):
        if not config.user.may("wato.activate"):
            html.show_warning(
                _("You are not permitted to activate configuration changes."))
            return

        if not self._changes:
            html.show_info(_("Currently there are no changes to activate."))
            return

        if not config.user.may("wato.activateforeign") \
           and self._has_foreign_changes_on_any_site():
            html.show_warning(
                _("Sorry, you are not allowed to activate changes of other users."
                  ))
            return

        valuespec = self._vs_activation()

        html.begin_form("activate", method="POST", action="")
        html.hidden_field("activate_until",
                          self._get_last_change_id(),
                          id_="activate_until")
        forms.header(valuespec.title())

        valuespec.render_input("activate", self._value)
        valuespec.set_focus("activate")
        html.help(valuespec.help())

        if self.has_foreign_changes():
            if config.user.may("wato.activateforeign"):
                html.show_warning(
                    _("There are some changes made by your colleagues that you will "
                      "activate if you proceed. You need to enable the checkbox above "
                      "to confirm the activation of these changes."))
            else:
                html.show_warning(
                    _("There are some changes made by your colleagues that you can not "
                      "activate because you are not permitted to. You can only activate "
                      "the changes on the sites that are not affected by these changes. "
                      "<br>"
                      "If you need to activate your changes on all sites, please contact "
                      "a permitted user to do it for you."))

        forms.end()
        html.jsbutton("activate_affected",
                      _("Activate affected"),
                      "cmk.activation.activate_changes(\"affected\")",
                      cssclass="hot")
        html.jsbutton("activate_selected", _("Activate selected"),
                      "cmk.activation.activate_changes(\"selected\")")

        html.hidden_fields()
        html.end_form()
Beispiel #3
0
    def page(self):
        audit = self._parse_audit_log()

        if not audit:
            html.show_info(_("The audit log is empty."))

        elif self._options["display"] == "daily":
            self._display_daily_audit_log(audit)

        else:
            self._display_multiple_days_audit_log(audit)
Beispiel #4
0
        def _render_master_control_site(site_id):
            site_state = sites.states().get(site_id)
            if site_state["state"] == "dead":
                html.show_error(site_state["exception"])

            elif site_state["state"] == "disabled":
                html.show_info(_("Site is disabled"))

            elif site_state["state"] == "unknown":
                if site_state.get("exception"):
                    html.show_error(site_state["exception"])
                else:
                    html.show_error(_("Site state is unknown"))

            else:
                is_cmc = site_state["program_version"].startswith("Check_MK ")

                try:
                    site_info = site_status_info[site_id]
                except KeyError:
                    site_info = None

                html.open_table(class_="master_control")
                for i, (colname, title) in enumerate(items):
                    # Do not show event handlers on Check_MK Micro Core
                    if is_cmc and title == _("Event handlers"):
                        continue
                    elif not is_cmc and title == _("Alert handlers"):
                        continue

                    colvalue = site_info[i]
                    url = html.makeactionuri_contextless(
                        [
                            ("site", site_id),
                            ("switch", colname),
                            ("state", "%d" % (1 - colvalue)),
                        ],
                        filename="switch_master_state.py")
                    onclick = "cmk.ajax.get_url('%s', cmk.utils.update_contents, 'snapin_master_control')" % url

                    html.open_tr()
                    html.td(title, class_="left")
                    html.open_td()
                    html.toggle_switch(
                        enabled=colvalue,
                        help_txt=_("Switch '%s' to '%s'") %
                        (title, _("off") if colvalue else _("on")),
                        onclick=onclick,
                    )
                    html.close_td()
                    html.close_tr()

                html.close_table()
Beispiel #5
0
 def _activation_msg(self):
     html.open_div(id_="async_progress_msg", style="display:none")
     html.show_info("")
     html.close_div()
Beispiel #6
0
def normal_login_page(called_directly=True):
    html.set_render_headfoot(False)
    html.add_body_css_class("login")
    html.header(config.get_page_heading(), javascripts=[])

    default_origtarget = "index.py" if html.myfile in ["login", "logout"] else html.makeuri([])
    origtarget = html.get_url_input("_origtarget", default_origtarget)

    # Never allow the login page to be opened in a frameset. 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 html.myfile == 'login' and check_auth(html.request):
        raise HTTPRedirect(origtarget)

    html.open_div(id_="login")

    html.open_div(id_="login_window")

    html.div("" if "hide_version" in config.login_screen else cmk.__version__, id_="version")

    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 html.has_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'))
    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_info(config.login_screen["login_message"])
        html.close_div()

    footer = []
    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("Version: %s" % cmk.__version__)

    footer.append(
        "&copy; %s" % html.render_a("Mathias Kettner", href="https://mathias-kettner.com"))

    html.write(HTML(" - ").join(footer))

    if cmk.is_raw_edition():
        html.br()
        html.br()
        html.write(
            _('You can use, modify and distribute Check_MK under the terms of the <a href="%s">'
              'GNU GPL Version 2</a>.') % "https://mathias-kettner.com/gpl.html")

    html.close_div()

    html.set_focus('_username')
    html.hidden_fields()
    html.end_form()
    html.close_div()

    html.footer()