Exemplo n.º 1
0
 def delete_user_groups(username, groups):
     logger.debug("Deleting openfire groups %s from user %s" %
                  (groups, username))
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     api.delete_user_groups(username, groups)
     logger.info("Deleted groups %s from openfire user %s" %
                 (groups, username))
Exemplo n.º 2
0
 def update_user_groups(username, groups):
     logger.debug("Updating openfire user %s groups %s" % (username, groups))
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     response = api.get_user_groups(username)
     remote_groups = []
     if response:
         remote_groups = response['groupname']
         if isinstance(remote_groups, six.string_types):
             remote_groups = [remote_groups]
     logger.debug("Openfire user %s has groups %s" % (username, remote_groups))
     add_groups = []
     del_groups = []
     for g in groups:
         g = OpenfireManager._sanitize_groupname(g)
         if g not in remote_groups:
             add_groups.append(g)
     for g in remote_groups:
         g = OpenfireManager._sanitize_groupname(g)
         if g not in groups:
             del_groups.append(g)
     logger.info(
         "Updating openfire groups for user %s - adding %s, removing %s" % (username, add_groups, del_groups))
     if add_groups:
         api.add_user_groups(username, add_groups)
     if del_groups:
         api.delete_user_groups(username, del_groups)
Exemplo n.º 3
0
 def update_user_groups(cls, username, groups):
     logger.debug("Updating openfire user %s groups %s" %
                  (username, groups))
     s_groups = list(map(cls._sanitize_groupname,
                         groups))  # Sanitized group names
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     response = api.get_user_groups(username)
     remote_groups = []
     if response:
         remote_groups = response['groupname']
         if isinstance(remote_groups, str):
             remote_groups = [remote_groups]
     remote_groups = list(map(cls._sanitize_groupname, remote_groups))
     logger.debug("Openfire user %s has groups %s" %
                  (username, remote_groups))
     add_groups = []
     del_groups = []
     for g in s_groups:
         if g not in remote_groups:
             add_groups.append(g)
     for g in remote_groups:
         if g not in s_groups:
             del_groups.append(g)
     logger.info(
         "Updating openfire groups for user %s - adding %s, removing %s" %
         (username, add_groups, del_groups))
     if add_groups:
         api.add_user_groups(username, add_groups)
     if del_groups:
         api.delete_user_groups(username, del_groups)
Exemplo n.º 4
0
 def update_user_groups(username, password, groups):
     logger.debug("Updating openfire user %s groups %s" %
                  (username, groups))
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     response = api.get_user_groups(username)
     remote_groups = []
     if response:
         remote_groups = response['groupname']
         if isinstance(remote_groups, basestring):
             remote_groups = [remote_groups]
     logger.debug("Openfire user %s has groups %s" %
                  (username, remote_groups))
     add_groups = []
     del_groups = []
     for g in groups:
         if not g in remote_groups:
             add_groups.append(g)
     for g in remote_groups:
         if not g in groups:
             del_groups.append(g)
     logger.info(
         "Updating openfire groups for user %s - adding %s, removing %s" %
         (username, add_groups, del_groups))
     if add_groups:
         api.add_user_groups(username, add_groups)
     if del_groups:
         api.delete_user_groups(username, del_groups)
Exemplo n.º 5
0
 def delete_user(username):
     logger.debug("Deleting user %s from openfire." % username)
     try:
         api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
         api.delete_user(username)
         logger.info("Deleted user %s from openfire." % username)
         return True
     except exception.UserNotFoundException:
         logger.error("Attempting to delete a user %s from openfire which was not found on server." % username)
         return False
Exemplo n.º 6
0
 def delete_user(username):
     logger.debug("Deleting user %s from openfire." % username)
     try:
         api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
         api.delete_user(username)
         logger.info("Deleted user %s from openfire." % username)
         return True
     except exception.UserNotFoundException:
         logger.error("Attempting to delete a user %s from openfire which was not found on server." % username)
         return False
Exemplo n.º 7
0
 def update_user_pass(username, password=None):
     logger.debug("Updating openfire user %s password." % username)
     try:
         if not password:
             password = OpenfireManager.__generate_random_pass()
         api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
         api.update_user(username, password=password)
         logger.info("Updated openfire user %s password." % username)
         return password
     except exception.UserNotFoundException:
         logger.error("Unable to update openfire user %s password - user not found on server." % username)
         return ""
Exemplo n.º 8
0
 def update_user_pass(username, password=None):
     logger.debug("Updating openfire user %s password." % username)
     try:
         if not password:
             password = OpenfireManager.__generate_random_pass()
         api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
         api.update_user(username, password=password)
         logger.info("Updated openfire user %s password." % username)
         return password
     except exception.UserNotFoundException:
         logger.error("Unable to update openfire user %s password - user not found on server." % username)
         return ""
Exemplo n.º 9
0
    def add_user(username):
        logger.debug("Adding username %s to openfire." % username)
        try:
            sanatized_username = OpenfireManager.__santatize_username(username)
            password = OpenfireManager.__generate_random_pass()
            api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
            api.add_user(sanatized_username, password)
            logger.info("Added openfire user %s" % username)
        except exception.UserAlreadyExistsException:
            # User exist
            logger.error("Attempting to add a user %s to openfire which already exists on server." % username)
            return "", ""

        return sanatized_username, password
Exemplo n.º 10
0
    def add_user(username):
        logger.debug("Adding username %s to openfire." % username)
        try:
            sanatized_username = OpenfireManager.__santatize_username(username)
            password = OpenfireManager.__generate_random_pass()
            api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
            api.add_user(sanatized_username, password)
            logger.info("Added openfire user %s" % username)
        except exception.UserAlreadyExistsException:
            # User exist
            logger.error("Attempting to add a user %s to openfire which already exists on server." % username)
            return "", ""

        return sanatized_username, password
Exemplo n.º 11
0
 def update_user_groups(username, password, groups):
     logger.debug("Updating openfire user %s groups %s" % (username, groups))
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     response = api.get_user_groups(username)
     remote_groups = []
     if response:
         remote_groups = response['groupname']
     logger.debug("Openfire user %s has groups %s" % (username, remote_groups))
     add_groups = []
     del_groups = []
     for g in groups:
         if not g in remote_groups:
             add_groups.append(g)
     for g in remote_groups:
         if not g in groups:
             del_groups.append(g)
     logger.info("Updating openfire groups for user %s - adding %s, removing %s" % (username, add_groups, del_groups))
     if add_groups:
         api.add_user_groups(username, add_groups)
     if del_groups:
         api.delete_user_groups(username, del_groups)
Exemplo n.º 12
0
 def unlock_user(username):
     logger.debug("Unlocking openfire user %s" % username)
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     api.unlock_user(username)
     logger.info("Unlocked openfire user %s" % username)
Exemplo n.º 13
0
 def unlock_user(username):
     logger.debug("Unlocking openfire user %s" % username)
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     api.unlock_user(username)
     logger.info("Unlocked openfire user %s" % username)
Exemplo n.º 14
0
 def delete_user_groups(username, groups):
     logger.debug("Deleting openfire groups %s from user %s" % (groups, username))
     api = ofUsers(settings.OPENFIRE_ADDRESS, settings.OPENFIRE_SECRET_KEY)
     api.delete_user_groups(username, groups)
     logger.info("Deleted groups %s from openfire user %s" % (groups, username))