Beispiel #1
0
def _check_auth(req: Request) -> Optional[UserId]:
    user_id = _check_auth_web_server(req)

    if req.var("_secret"):
        user_id = _check_auth_automation()

    elif config.auth_by_http_header:
        if not config.user_login:
            return None
        user_id = _check_auth_http_header()

    if user_id is None:
        if not config.user_login:
            return None
        user_id = _check_auth_by_cookie()

    if (user_id is not None and not isinstance(user_id, str)) or user_id == "":
        raise MKInternalError(_("Invalid user authentication"))

    if user_id and not userdb.is_customer_user_allowed_to_login(user_id):
        # A CME not assigned with the current sites customer
        # is not allowed to login
        auth_logger.debug(
            "User '%s' is not allowed to authenticate: Invalid customer" %
            user_id)
        return None

    if user_id and auth_type in ("http_header", "web_server"):
        _check_auth_cookie_for_web_server_auth(user_id)

    return user_id
Beispiel #2
0
def _check_auth(req: Request) -> Optional[UserId]:
    user_id = _check_auth_web_server(req)

    if req.var("_secret"):
        user_id = _check_auth_automation()

    elif auth_by_http_header := config.auth_by_http_header:
        if not config.user_login:
            return None
        user_id = _check_auth_http_header(auth_by_http_header)
Beispiel #3
0
def is_mobile(request: Request, response: Response) -> bool:
    if request.has_var("mobile"):
        mobile = bool(request.var("mobile"))
        # Persist the explicitly set state in a cookie to have it maintained through further requests
        response.set_http_cookie("mobile", str(int(mobile)), secure=request.is_secure)
        return mobile

    if request.has_cookie("mobile"):
        return request.cookie("mobile", "0") == "1"

    return _is_mobile_client(request.user_agent.string)