示例#1
0
def set_support(license_file_name):
    """set a linotp support similar to system/setSupport."""

    try:

        _setup_security_context()

        with open(license_file_name, "rb") as license_file:
            license_text = license_file.read()

        session = db.session()

        success, status = setSupportLicense(license_text.decode("utf-8"))

        session.commit()

    except Exception as exx:
        current_app.echo(f"Setting license could not be completed: {exx}")
        sys.exit(1)

    if not success:
        current_app.echo(f"Failed to set license! {status}")
        sys.exit(2)

    current_app.echo("Successfully set license.")
    sys.exit(0)
示例#2
0
def get_support():
    """get the linotp support info similar to system/getSupportInfo"""

    try:

        _setup_security_context()

        session = db.session()

        license_dict, license_signature = getSupportLicenseInfo()

        session.close()

    except Exception as exx:
        current_app.echo(f"Getting support could not be completed: {exx}")
        sys.exit(1)

    if not license_dict:
        if isinstance(license_dict, dict):
            current_app.echo("No support license installed")
        else:
            current_app.echo("Getting support failed!")
        sys.exit(2)

    print(json.dumps(license_dict, indent=4, sort_keys=True))
    sys.exit(0)
示例#3
0
def is_support_valid(filename):
    """checks if the linotp support info is valid similar to isSupportValid"""

    try:

        _setup_security_context()

        session = db.session()

        if filename:

            with open(filename, "rb") as license_file:
                license_text = license_file.read()

            license_text = license_text.decode("utf-8").replace("\n", "\n")
            license_dict, license_signature = parseSupportLicense(license_text)
        else:

            license_dict, license_signature = getSupportLicenseInfo()

        valid = isSupportLicenseValid(
            lic_dict=license_dict,
            lic_sign=license_signature,
            raiseException=True,
        )

        session.close()

    except InvalidLicenseException as exx:
        current_app.echo(f"Invalid License: {exx}")
        sys.exit(2)

    except Exception as exx:
        current_app.echo(f"Validating support could not be completed: {exx}")
        sys.exit(1)

    if not license_dict:
        if isinstance(license_dict, dict):
            current_app.echo("No support license installed")
        else:
            current_app.echo("Validating support failed!")
        sys.exit(2)

    if not valid or not isinstance(valid, tuple):
        current_app.echo("Validating support error: %r" % valid)
        sys.exit(2)

    print(valid[0])
    sys.exit(0)
示例#4
0
 def __init__(self, resolver_name: str = None):
     self._pw_gen = False
     self.user_class = ImportedUserSchema
     self.session: Session = db.session()
     self.resolver_name = resolver_name
     self.plain_password = None
示例#5
0
 def __init__(self, app: LinOTPApp) -> None:
     setup_db(app)
     self.user_class = ImportedUserSchema
     self.session: Session = db.session()
     self.admin_resolver_name = app.config["ADMIN_RESOLVER_NAME"]
     self.admin_realm_name = app.config["ADMIN_REALM_NAME"].lower()