Пример #1
0
def _modify_f(options, parser):
    import csv

    # Get options
    namespace = parser.parse_args(options)

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get Customer ID
    try:
        customer_id = __getCustomerId(auth_token)
    except:
        return False

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["ou_path", "description", "block_inheritance"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["ou_path"]
            if not _func.checkRecordHasValue(record, *must_values):
                continue

            # Check ou has full path
            if record["ou_path"][0] != "/":
                sys.stderr.write(_messages.OU_HAS_NOT_FULL_PATH)
                continue

            # Check block/unblock inheritance
            block_inheritance = record["block_inheritance"].lower()
            if block_inheritance == "true":
                block_inheritance = "true"
            elif block_inheritance == "false":
                block_inheritance = "false"
            else:
                block_inheritance = None

            # Operation
            _func.operate( OU.updateOu
                         , record["ou_path"]
                         , parser.prog
                         , namespace.result_file
                             , auth_token
                             , customer_id
                             , record["ou_path"]               # ou path
                             , _func.replaceSpace2None(
                                        record["description"]) # ou description
                             , block_inheritance               # block inheritance
                         )
        return True
Пример #2
0
def _moveuser_f(options, parser):
    import csv

    # Get options
    namespace = parser.parse_args(options)

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get Customer ID
    try:
        customer_id = __getCustomerId(auth_token)
    except:
        return False

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["user_name", "ou_path"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["user_name", "ou_path"]
            if not _func.checkRecordHasValue(record, *must_values):
                continue

            # Check ou has full path
            if record["ou_path"][0] != "/":
                sys.stderr.write(_messages.OU_HAS_NOT_FULL_PATH)
                continue

            _func.operate( OU_U.moveUserToOu
                         , record["ou_path"]
                         , "{} \"{}\"".format( parser.prog
                                             , record["user_name"].lower()
                                             )
                         , namespace.result_file
                              , auth_token
                              , customer_id
                              , "{}@{}".format( record["user_name"]
                                              , namespace.domain
                                              )          # user name
                              , record["ou_path"]        # ou path
                         )
        return True
Пример #3
0
def _deletemember_f(options, parser):
    import csv

    # Get options
    namespace = parser.parse_args(options)

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["member_name", "group_id"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["member_name", "group_id"]
            if not _func.checkRecordHasValue(record, *must_values):
                continue

            # Operation
            _func.operate( GROUP_M.deleteMemberFromGroup
                        , record["group_id"].lower()
                        , "{} \"{}\"".format( parser.prog
                                            , record["member_name"].lower()
                                            )
                        , namespace.result_file
                        , namespace.domain
                        , auth_token
                        , record["member_name"].lower()        # member name
                        , record["group_id"].lower()           # group id
                    )
        return True
Пример #4
0
def _enable_f(options, parser):
    import csv

    # Get options
    namespace = parser.parse_args(options)

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["user_email"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["user_email"]
            if not _func.checkRecordHasValue(*must_values):
                continue

            # Operation
            _func.operate( USER2.updateUser
                         , record["user_email"].lower()
                         , parser.prog
                         , namespace.result_file
                                , namespace.domain
                                , auth_token
                                , record["user_email"].lower()  # user
                                , is_suspended="false"            # suspended
                         )

        return True
Пример #5
0
def _modify_f(options, parser):
    import csv

    # Get options
    namespace = parser.parse_args(options)

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["group_id", "group_name", "description"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["group_id"]
            if not _func.checkRecordHasValue(record, *must_values):
                continue

            # Operation
            _func.operate( GROUP.updateGroup
                , record["group_id"].lower()
                , parser.prog
                , namespace.result_file
                    , namespace.domain
                    , auth_token
                    , record["group_id"].lower()                     # group id
                    , _func.replaceSpace2None(record["group_name"])  # group name
                    , _func.replaceSpace2None(record["description"]) # description
                )
        return True
Пример #6
0
def _modify_f(options, parser):
    import csv

    # Set parser options 
    parser.add_argument( "-m", "--md5"
                       , action  = "store_true"
                       , default = False
                       , help    = "Use MD5 hash function (default = SHA-1)."
                       )

    # Get options
    namespace = parser.parse_args(options)

    # Check hash function name
    if namespace.md5 == True:
        hash_function_name = "MD5"
    else:
        hash_function_name = "SHA-1"

    # Get auth token
    auth_token = _func.getAuthTokenByLogin(namespace.admin_name, namespace.domain)

    # Get records from csv file
    with open(namespace.csv_file) as f:
        reader = csv.DictReader(f)

        # Check header
        header = f.next().replace("\n", "").split(",")
        must_keys = ["user_email", "password", "sn", "given_name", "must_change_pw_next", "lock"]
        if not _func.checkValidHeader(header, *must_keys):
            return False
        f.seek(0, 0)

        # Read csv
        for record in reader:
            must_values = ["user_email"]
            if not _func.checkRecordHasValue(*must_values):
                continue

            # Get hashed password
            hash_password = _func.getHashedPassword( record["password"]
                                                   , hash_function_name
                                                   )

            # Check suspended
            suspended = record["lock"].lower()
            if suspended == "true":
                suspended = "true"
            elif suspended == "false":
                suspended = "false"
            else:
                suspended = None

            # Check must change password at next login
            is_change_password = record["must_change_pw_next"].lower()
            if is_change_password == "false":
                is_change_password = "******"
            elif is_change_password == "true":
                is_change_password = "******"
            else:
                is_change_password = None

            # Operation
            _func.operate( USER2.updateUser
                         , record["user_email"].lower()
                         , parser.prog
                         , namespace.result_file
                             , namespace.domain
                             , auth_token
                             , record["user_email"].lower()                  # user
                             , hash_password                                 # password
                             , _func.replaceSpace2None(record["sn"])         # sn
                             , _func.replaceSpace2None(record["given_name"]) # given name
                             , hash_function_name                            # function name
                             , suspended                                     # suspended
                             , is_change_password=is_change_password         # is change
                         )

        return True