示例#1
0
def logTokenNum(audit):
    """
    add the current token count to the audit dict

    :param audit: audit dict
    """
    # log the number of the tokens
    audit['action_detail'] = "tokennum = %s" % str(getTokenNumResolver())
示例#2
0
def logTokenNum(audit):
    """
    add the current token count to the audit dict

    :param audit: audit dict
    """
    # log the number of the tokens
    audit["action_detail"] = "tokennum = %s" % str(getTokenNumResolver())
示例#3
0
文件: support.py 项目: soitun/LinOTP
def verify_token_volume(lic_dict):
    """
    check if the token count is covered by the license

    :param lic_dict: dictionary with license attributes
    :return: tuple with boolean and verification detail
    """

    # get the current number of active tokens
    num = getTokenNumResolver()

    try:
        token_volume = int(lic_dict.get("token-num", 0))
    except TypeError as err:
        log.error(
            "Failed to convert license. Number of tokens: %r. "
            "Exception was:%r ",
            lic_dict.get("token-num"),
            err,
        )
        return False, "max %d" % token_volume

    detail = ""

    if num > token_volume + GRACE_VOLUME:
        log.error(
            "Volume of licensed tokens exceeded. Currently %r tokens are "
            "present, but only %r are licensed.",
            num,
            token_volume,
        )
        detail = _("%d active tokens found > %d tokens licensed.") % (
            num,
            token_volume,
        )
        return False, detail

    if num >= token_volume and num <= token_volume + GRACE_VOLUME:
        log.warning(
            "Volume of licensed tokens exceeded. Currently %r tokens are "
            "present, but only %r are licensed. Grace of %d additional "
            "tokens allowed.",
            num,
            token_volume,
            GRACE_VOLUME,
        )
        detail = _(
            "Grace limit reached: %d active tokens found >= %d tokens licensed. "
            "%d additional tokens allowed."
        ) % (num, token_volume, GRACE_VOLUME)

    return True, detail
示例#4
0
    def license(self):
        """
        license
        return the support status, which is community support by default
        or the support subscription info, which could be the old license
        :return: json result with license info
        """
        res = {}
        try:
            try:
                license_info, license_sig = getSupportLicenseInfo()
            except InvalidLicenseException as err:
                if err.type != "UNLICENSED":
                    raise err
                opt = {"valid": False, "message": "%r" % err}
                return sendResult(response, {}, 1, opt=opt)

            # Add Extra info
            # if needed; use details = None ... for no details!)...

            license_ok, license_msg = verifyLicenseInfo(
                license_info, license_sig
            )
            if not license_ok:
                res = {"valid": license_ok, "message": license_msg}
                return sendResult(response, res, 1)

            details = {"valid": license_ok}

            if "user-num" in license_info:
                res["user-num"] = int(license_info.get("user-num", 0))
                active_usercount = getNumTokenUsers()
                res["user-active"] = active_usercount
                res["user-left"] = res["user-num"] - active_usercount

            else:
                res["token-num"] = int(license_info.get("token-num", 0))
                active_tokencount = getTokenNumResolver()
                res["token-active"] = active_tokencount
                res["token-left"] = res["token-num"] - active_tokencount

            return sendResult(response, res, 1)

        except Exception as exception:
            log.error(exception)
            return sendError(response, exception)
示例#5
0
文件: support.py 项目: hopil/LinOTP
def verify_volume(lic_dict):

    # get the current number of active tokens
    num = getTokenNumResolver()

    try:
        token_volume = int(lic_dict.get("token-num", 0))
    except TypeError as err:
        log.exception("failed to convert license token num value:%r :%r" % (lic_dict.get("token-num"), err))
        return False, "max %d" % token_volume

    if num >= token_volume:
        log.error("licensed token volume exceeded %r>%r" % (num, token_volume))
        used = _("tokens used")
        licnu = _("tokens supported")
        detail = " %s: %d > %s: %d" % (used, num, licnu, token_volume)
        return False, detail

    return True, ""
示例#6
0
def verify_volume(lic_dict):

    # get the current number of active tokens
    num = getTokenNumResolver()

    try:
        token_volume = int(lic_dict.get('token-num', 0))
    except TypeError as err:
        log.error("failed to convert license token num value:%r :%r" %
                  (lic_dict.get('token-num'), err))
        return False, "max %d" % token_volume

    if num > token_volume:
        log.error("licensed token volume exceeded %r>%r" % (num, token_volume))
        used = _("tokens used")
        licnu = _("tokens supported")
        detail = " %s: %d > %s: %d" % (used, num, licnu, token_volume)
        return False, detail

    return True, ""
示例#7
0
def verify_token_volume(lic_dict):

    _ = context['translate']

    # get the current number of active tokens
    num = getTokenNumResolver()

    try:
        token_volume = int(lic_dict.get('token-num', 0))
    except TypeError as err:
        log.exception("Failed to convert license. Number of tokens: %r. "
                      "Exception was:%r " % (lic_dict.get('token-num'), err))
        return False, "max %d" % token_volume

    if num > token_volume:
        log.error("Licensed token volume exceeded. Currently %r tokens "
                  "present, but only %r allowed." % (num, token_volume))
        used = _("tokens used")
        licnu = _("tokens supported")
        detail = " %s: %d > %s: %d" % (used, num, licnu, token_volume)
        return False, detail

    return True, ""
示例#8
0
文件: base.py 项目: RDLM-01/Elm
def logTokenNum():
    # log the number of the tokens
    c.audit['action_detail'] = "tokennum = %s" % str(getTokenNumResolver())
示例#9
0
文件: base.py 项目: ae-m/LinOTP
def logTokenNum():
    # log the number of the tokens
    c.audit['action_detail'] = "tokennum = %s" % str(getTokenNumResolver())