Example #1
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)
Example #2
0
def _livestatus_auth_user(
        user: LoggedInUser,
        force_authuser: Optional[UserId]) -> Optional[UserId]:
    if not user.may("general.see_all"):
        return user.id
    if force_authuser == UserId("1"):
        return user.id
    if force_authuser == UserId("0"):
        return None
    if force_authuser:
        return force_authuser  # set a different user
    if user.get_attribute("force_authuser"):
        return user.id
    return None
Example #3
0
def _get_enabled_and_disabled_sites(
    user: LoggedInUser, ) -> Tuple[SiteConfigurations, SiteConfigurations]:
    enabled_sites: SiteConfigurations = {}
    disabled_sites: SiteConfigurations = {}

    for site_id, site_spec in user.authorized_sites().items():
        site_spec = _site_config_for_livestatus(site_id, site_spec)

        if user.is_site_disabled(site_id):
            disabled_sites[site_id] = site_spec
        else:
            enabled_sites[site_id] = site_spec

    return enabled_sites, disabled_sites
Example #4
0
def _get_enabled_and_disabled_sites(
    user: LoggedInUser, ) -> Tuple[SiteConfigurations, SiteConfigurations]:
    enabled_sites: SiteConfigurations = SiteConfigurations({})
    disabled_sites: SiteConfigurations = SiteConfigurations({})

    for site_id, site_spec in user.authorized_sites().items():
        site_spec = _site_config_for_livestatus(site_id, site_spec)
        # Astroid 2.x bug prevents us from using NewType https://github.com/PyCQA/pylint/issues/2296
        # pylint: disable=unsupported-assignment-operation
        if user.is_site_disabled(site_id):
            disabled_sites[site_id] = site_spec
        else:
            enabled_sites[site_id] = site_spec

    return enabled_sites, disabled_sites
Example #5
0
def _set_livestatus_auth(user: LoggedInUser,
                         force_authuser: Optional[UserId]) -> None:
    user_id = _livestatus_auth_user(user, force_authuser)
    if user_id is not None:
        g.live.set_auth_user("read", user_id)
        g.live.set_auth_user("action", user_id)

    # May the user see all objects in BI aggregations or only some?
    if not user.may("bi.see_all"):
        g.live.set_auth_user("bi", user_id)

    # May the user see all Event Console events or only some?
    if not user.may("mkeventd.seeall"):
        g.live.set_auth_user("ec", user_id)

    # Default auth domain is read. Please set to None to switch off authorization
    g.live.set_auth_domain("read")
Example #6
0
def fixture_monitoring_user(request_context):
    """Returns a "Normal monitoring user" object."""
    user_dir = cmk.utils.paths.profile_dir / "test"
    user_dir.mkdir(parents=True)
    user_dir.joinpath("cached_profile.mk").write_text(
        str(MONITORING_USER_CACHED_PROFILE))
    # SITE STATUS snapin settings:
    user_dir.joinpath("siteconfig.mk").write_text(
        str(MONITORING_USER_SITECONFIG))
    # Ordering of the buttons:
    user_dir.joinpath("buttoncounts.mk").write_text(
        str(MONITORING_USER_BUTTONCOUNTS))
    # Favorites set in the commands menu:
    user_dir.joinpath("favorites.mk").write_text(
        str(MONITORING_USER_FAVORITES))

    assert builtin_role_ids == ["user", "admin", "guest"]
    assert "test" not in config.admin_users

    with create_and_destroy_user(username="******") as user:
        yield LoggedInUser(user[0])
Example #7
0
def load_cached_profile(user_id: UserId) -> Optional[UserSpec]:
    usr = LoggedInUser(user_id) if user_id != user.id else user
    return usr.load_file("cached_profile", None)