예제 #1
0
def main_character_change(request, char_id):
    if EveManager.check_if_character_owned_by_user(char_id, request.user):
        previousmainid = AuthServicesInfoManager.get_auth_service_info(request.user).main_char_id
        AuthServicesInfoManager.update_main_char_Id(char_id, request.user)
        # Check if character is in the alliance
        character_info = EveManager.get_character_by_id(char_id)
        corporation_info = EveManager.get_corporation_info_by_id(character_info.corporation_id)

        if EveManager.get_charater_alliance_id_by_id(char_id) == settings.ALLIANCE_ID:
            add_member_permission(request.user, 'alliance_member')
            add_user_to_group(request.user, settings.DEFAULT_ALLIANCE_GROUP)
            add_user_to_group(request.user,
                              generate_corp_group_name(EveManager.get_character_by_id(char_id).corporation_name))

        elif corporation_info != None:
            if corporation_info.is_blue:
                add_member_permission(request.user, 'blue_member')
                add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP)
                AuthServicesInfoManager.update_is_blue(True, request.user)
            else:
                if check_if_user_has_permission(request.user, 'alliance_member'):
                    disable_alliance_member(request.user, previousmainid)

                if check_if_user_has_permission(request.user, 'blue_member'):
                    disable_blue_member(request.user)
        else:
            # TODO: disable serivces
            if check_if_user_has_permission(request.user, 'alliance_member'):
                disable_alliance_member(request.user, previousmainid)

            if check_if_user_has_permission(request.user, 'blue_member'):
                disable_blue_member(request.user)

        return HttpResponseRedirect("/characters")
    return HttpResponseRedirect("/characters")
예제 #2
0
def main_character_change(request, char_id):
    if EveManager.check_if_character_owned_by_user(char_id, request.user):
        previousmainid = AuthServicesInfoManager.get_auth_service_info(
            request.user).main_char_id
        AuthServicesInfoManager.update_main_char_Id(char_id, request.user)
        # Check if character is in the alliance
        character_info = EveManager.get_character_by_id(char_id)
        corporation_info = EveManager.get_corporation_info_by_id(
            character_info.corporation_id)

        if EveManager.get_charater_alliance_id_by_id(
                char_id) == settings.ALLIANCE_ID:
            add_member_permission(request.user, 'alliance_member')
            add_user_to_group(request.user, settings.DEFAULT_ALLIANCE_GROUP)
            add_user_to_group(
                request.user,
                generate_corp_group_name(
                    EveManager.get_character_by_id(char_id).corporation_name))

        elif corporation_info != None:
            if corporation_info.is_blue:
                add_member_permission(request.user, 'blue_member')
                add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP)
                AuthServicesInfoManager.update_is_blue(True, request.user)
            else:
                if check_if_user_has_permission(request.user,
                                                'alliance_member'):
                    disable_alliance_member(request.user, previousmainid)

                if check_if_user_has_permission(request.user, 'blue_member'):
                    disable_blue_member(request.user)
        else:
            # TODO: disable serivces
            if check_if_user_has_permission(request.user, 'alliance_member'):
                disable_alliance_member(request.user, previousmainid)

            if check_if_user_has_permission(request.user, 'blue_member'):
                disable_blue_member(request.user)

        return HttpResponseRedirect("/characters")
    return HttpResponseRedirect("/characters")
예제 #3
0
def main_character_change(request, char_id):
    logger.debug("main_character_change called by user %s for character id %s" % (request.user, char_id))
    if EveManager.check_if_character_owned_by_user(char_id, request.user):
        previousmainid = AuthServicesInfoManager.get_auth_service_info(request.user).main_char_id
        AuthServicesInfoManager.update_main_char_Id(char_id, request.user)
        # Check if character is in the alliance
        character_info = EveManager.get_character_by_id(char_id)
        corporation_info = EveManager.get_corporation_info_by_id(character_info.corporation_id)
        logger.debug("User %s changing main character to %s in corp %s" % (request.user, character_info, corporation_info))
        if (settings.IS_CORP and EveManager.get_charater_corporation_id_by_id(char_id) == settings.CORP_ID) or (not settings.IS_CORP and EveManager.get_charater_alliance_id_by_id(char_id) == settings.ALLIANCE_ID):
            add_member_permission(request.user, 'member')
            add_user_to_group(request.user, settings.DEFAULT_AUTH_GROUP)
            add_user_to_group(request.user,
                              generate_corp_group_name(EveManager.get_character_by_id(char_id).corporation_name))
            logger.info("User %s transitioned to full member by chaning main character to %s" % (request.user, character_info))

        elif corporation_info != None:
            if corporation_info.is_blue:
                add_member_permission(request.user, 'blue_member')
                add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP)
                AuthServicesInfoManager.update_is_blue(True, request.user)
                logger.info("User %s transitioned to blue by changing main character to %s" % (request.user, character_info))
            else:
                if check_if_user_has_permission(request.user, 'member'):
                    disable_member(request.user, previousmainid)

                if check_if_user_has_permission(request.user, 'blue_member'):
                    disable_blue_member(request.user)
                logger.info("User %s disabled as new main character %s not member nor blue." % (request.user, character_info))
        else:
            # TODO: disable serivces
            if check_if_user_has_permission(request.user, 'member'):
                disable_member(request.user, previousmainid)

            if check_if_user_has_permission(request.user, 'blue_member'):
                disable_blue_member(request.user)
            logger.info("User %s disabled as new main character %s does not have corp model to check." % (request.user, character_info))

        return HttpResponseRedirect("/characters")
    return HttpResponseRedirect("/characters")
예제 #4
0
def run_api_refresh():
    users = User.objects.all()
    logger.debug("Running api refresh on %s users." % len(users))
    for user in users:
        # Check if the api server is online
        logger.debug("Running api refresh for user %s" % user)
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            logger.debug("User %s has api key pairs %s" % (user, api_key_pairs))
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                logger.debug("User %s has api keys. Proceeding to refresh." % user)
                if authserviceinfo.main_char_id:
                    if authserviceinfo.main_char_id != "":
                        #preserve old corp ID for corp change test on members
                        oldcorp_id = 0
                        if EveManager.get_character_by_id(authserviceinfo.main_char_id):
                            oldcorp_id = EveCharacter.objects.get(character_id=authserviceinfo.main_char_id).corporation_id
                            logger.debug("Determined user %s current main corp id %s" % (user, oldcorp_id))
                        for api_key_pair in api_key_pairs:
                            logger.debug("Running update on api key %s" % api_key_pair.api_id)
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                #check to ensure API key meets min spec
                                logger.info("Determined api key %s is still active." % api_key_pair.api_id)
                                still_valid = True
                                if authserviceinfo.is_blue:
                                    if settings.BLUE_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                else:
                                    if settings.MEMBER_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                    if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user))
                                            still_valid = False
                                if still_valid is not True:
                                    logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id)
                                    EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                    EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                                else:
                                    logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id)
                                    # Update characters
                                    characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                       api_key_pair.api_key)
                                    EveManager.update_characters_from_list(characters)
                                    new_character = False
                                    for char in characters.result:
                                        # Ensure we have a model for all characters on key
                                        if not EveManager.check_if_character_exist(characters.result[char]['name']):
                                            new_character = True
                                            logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name']))
                                    if new_character:
                                        logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id))
                                        EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                                    valid_key = True
                            else:
                                logger.debug("API key %s is no longer active; it and its characters will be deleted." % api_key_pair.api_id)
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            logger.debug("User %s has valid api key, checking main character %s" % (user, character))
                            if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id):
                                corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                                main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id)
                                main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                                logger.debug("User %s main character %s has corp %s with alliance id %s" % (user, character, corp, main_alliance_id))
                                if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID):
                                    logger.debug("User %s corp or alliance meets membership requirements. Ensuring has required permissions and groups." % user)
                                    if not check_if_user_has_permission(user, "member"):
                                        #transition from none or blue to member
                                        if check_if_user_has_permission(user, "blue_member"):
                                            #strip blue status
                                            logger.debug("Removing user %s blue permission and group to prepare for member transition." % user)
                                            remove_member_permission(user, "blue_member")
                                            remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(False, user)
                                        #add to auth group
                                        add_member_permission(user, "member")
                                        add_user_to_group(user, settings.DEFAULT_AUTH_GROUP)
                                        #add to required corp group
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        logger.info("User %s transitioned to full member during api refresh." % user)
                                    elif corp.corporation_id != oldcorp_id:
                                        #changed corps, both corps auth'd, need to change group assignment
                                        logger.debug("User %s main character changed corp from id %s to %s, both meet membership requirements. Updating corp group." % (user, oldcorp_id, corp.corporation_id))
                                        oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id)
                                        remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name))
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        #reset services to force new mumble names and group assignments
                                        deactivate_services(user)
                                        logger.info("User %s transferred corps from member to member. Reassigned groups." % user)
                                elif corp is not None:
                                    logger.debug("User %s main corp %s does not meet membership requirements." % (user, corp))
                                    if corp.is_blue is not True:
                                        if check_if_user_has_permission(user, "member"):
                                            #transition from member to nobody
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                            logger.info("User %s no longer member: main has left member corp/alliance." % user)
                                        elif check_if_user_has_permission(user, "blue_member"):
                                            #transition from blue to nobody
                                            disable_blue_member(user)
                                            logger.info("User %s no longer blue: main has left blue entities." % user)
                                        else:
                                            #stay nobody, make sure no services
                                            deactivate_services(user)
                                            logger.debug("Ensured non-member %s has no services." % user)
                                    else:
                                        if check_if_user_has_permission(user, "member"):
                                            #remove auth member to prepare for member to blue transition
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                            logger.debug("Removed user %s member group/permissions to transition to blue." % user)
                                        if not check_if_user_has_permission(user, "blue_member"):
                                            #perform nobody to blue transition
                                            add_member_permission(user, "blue_member")
                                            add_user_to_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(True, user)
                                            logger.info("User %s transitioned to blue member during api refresh." % user)

                                else:
                                    # disable accounts with missing corp model (not blue or member)
                                    if check_if_user_has_permission(user, "member"):
                                        disable_alliance_member(user, authserviceinfo.main_char_id)
                                        logger.info("User %s disabled (previously member) as unable to check missing corp model." % user)
                                    elif check_if_user_has_permission(user, "blue_member"):
                                        disable_blue_member(user)
                                        logger.info("User %s disabled (previously blue) as unable to check missing corp model." % user)
                                    else:
                                        deactivate_services(user)
                                        logger.debug("Ensured non-member %s has no services." % user)
                            else:
                                # nuke it, the hard way
                                disable_expired_member(user)                                
                                logger.info("User %s disabled due to missing main character or corp model." % user)
                        else:
                            # disable accounts with invalid keys
                            disable_expired_member(user)
                            logger.info("User %s has no valid api keys and has been disabled." % user)

                else:
                    logger.warn("User %s has no main character id, unable to validate membership.")
예제 #5
0
def run_api_refresh():
    users = User.objects.all()

    for user in users:
        # Check if the api server is online
        if EveApiManager.check_if_api_server_online():
            api_key_pairs = EveManager.get_api_key_pairs(user.id)
            if api_key_pairs:
                valid_key = False
                authserviceinfo = AuthServicesInfo.objects.get(user=user)

                print 'Running update on user: '******'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key
                            if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key):
                                #check to ensure API key meets min spec
                                still_valid = True
                                if authserviceinfo.is_blue:
                                    if settings.BLUE_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                    if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                else:
                                    if settings.MEMBER_API_ACCOUNT:
                                        if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                    if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key):
                                            still_valid = False
                                if still_valid is not True:
                                    EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                    EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)
                                else:                                    
                                    # Update characters
                                    characters = EveApiManager.get_characters_from_api(api_key_pair.api_id,
                                                                                       api_key_pair.api_key)
                                    EveManager.update_characters_from_list(characters)
                                    new_character = False
                                    for char in characters.result:
                                        # Ensure we have a model for all characters on key
                                        if not EveManager.check_if_character_exist(characters.result[char]['name']):
                                            new_character = True
                                    if new_character:
                                        EveManager.create_characters_from_list(characters, user, api_key_pair.api_key)
                                    valid_key = True
                            else:
                                EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id)
                                EveManager.delete_api_key_pair(api_key_pair.api_id, user.id)

                        if valid_key:
                            # Check our main character
                            character = EveManager.get_character_by_id(authserviceinfo.main_char_id)
                            if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id):
                                corp = EveManager.get_corporation_info_by_id(character.corporation_id)
                                main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id)
                                main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id)
                                if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID):
                                    if not check_if_user_has_permission(user, "member"):
                                        #transition from none or blue to member
                                        if check_if_user_has_permission(user, "blue_member"):
                                            #strip blue status
                                            remove_member_permission(user, "blue_member")
                                            remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(False, user)
                                        #add to auth group
                                        add_member_permission(user, "member")
                                        add_user_to_group(user, settings.DEFAULT_AUTH_GROUP)
                                        #add to required corp group
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                    elif corp.corporation_id != oldcorp_id:
                                        #changed corps, both corps auth'd, need to change group assignment
                                        oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id)
                                        remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name))
                                        add_user_to_group(user, generate_corp_group_name(character.corporation_name))
                                        #reset services to force new mumble names and group assignments
                                        deactivate_services(user)
                                elif corp is not None:
                                    if corp.is_blue is not True:
                                        if check_if_user_has_permission(user, "member"):
                                            #transition from member to nobody
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                        elif check_if_user_has_permission(user, "blue_member"):
                                            #transition from blue to nobody
                                            disable_blue_member(user)
                                        else:
                                            #stay nobody, make sure no services
                                            deactivate_services(user)
                                    else:
                                        if check_if_user_has_permission(user, "member"):
                                            #remove auth member to prepare for member to blue transition
                                            disable_alliance_member(user, authserviceinfo.main_char_id)
                                        if not check_if_user_has_permission(user, "blue_member"):
                                            #perform nobody to blue transition
                                            add_member_permission(user, "blue_member")
                                            add_user_to_group(user, settings.DEFAULT_BLUE_GROUP)
                                            AuthServicesInfoManager.update_is_blue(True, user)

                                else:
                                    # disable accounts with missing corp model (not blue or member)
                                    if check_if_user_has_permission(user, "member"):
                                        disable_alliance_member(user, authserviceinfo.main_char_id)
                                    elif check_if_user_has_permission(user, "blue_member"):
                                        disable_blue_member(user)
                                    else:
                                        deactivate_services(user)
                            else:
                                # nuke it, the hard way
                                disable_expired_member(user)                                
                        else:
                            # disable accounts with invalid keys
                            disable_expired_member(user)

                else:
                    print 'No main_char_id set'