Example #1
0
 def target_objects(self):
     if self.kind == 'c':
         return EVECharacter.objects(identifier__in=self.ids)
     elif self.kind == 'o':
         return EVECorporation.objects(identifier__in=self.ids)
     elif self.kind == 'a':
         return EVEAlliance.objects(identifier__in=self.ids)
Example #2
0
    def add_character(self, name=None):
        if not name:
            return 'json:', dict(success=False,
                                 message=_("character name required"))
        q = EVECharacter.objects(name=name)
        assert q.count() <= 1
        if q.count() != 1:
            return 'json:', dict(success=False,
                                 message=_("character not found"))
        c = q.first()


        r = self.group.rules[-1] if len(self.group.rules) else None
        if not r or not (isinstance(r, ACLList) and r.grant and not r.inverse and r.kind == 'c'):
            r = ACLList(grant=True, inverse=False, kind='c', ids=[])
            self.group.rules.append(r)

        if c.identifier in r.ids:
            return 'json:', dict(success=False,
                                 message=_("Character already in rule"))
        r.ids.append(c.identifier)
        success = self.group.save()

        if success:
            return 'json:', dict(success=True)
        return 'json:', dict(success=False,
                             message=_("Failure updating group"))
Example #3
0
 def target_objects(self):
     if self.kind == 'c':
         return EVECharacter.objects(identifier__in=self.ids)
     elif self.kind == 'o':
         return EVECorporation.objects(identifier__in=self.ids)
     elif self.kind == 'a':
         return EVEAlliance.objects(identifier__in=self.ids)
Example #4
0
    def remove_character(self, name=None):
        if not name:
            return 'json:', dict(success=False,
                                 message=_("character name required"))
        q = EVECharacter.objects(name=name)
        assert q.count() <= 1
        if q.count() != 1:
            return 'json:', dict(success=False,
                                 message=_("character not found"))
        c = q.first()

        r = self.group.rules[-1] if len(self.group.rules) else None
        if not r or not (isinstance(r, ACLList) and r.grant and not r.inverse and r.kind == 'c'):
            return 'json:', dict(success=False,
                                 message=_("Sorry, I don't know what to do!"))
        if not c.identifier in r.ids:
            return 'json:', dict(success=False,
                                 message=_("Character not found in last rule!"))
        r.ids.remove(c.identifier)
        if not r.ids:
            # If we just removed the last user in the rule, get rid of the rule.
            self.group.rules.pop(-1)
        success = self.group.save()

        if success:
            return 'json:', dict(success=True)
        return 'json:', dict(success=False,
                             message=_("Failure updating group"))
Example #5
0
    def remove_character(self, name=None):
        if not name:
            return 'json:', dict(success=False,
                                 message=_("character name required"))
        q = EVECharacter.objects(name=name)
        assert q.count() <= 1
        if q.count() != 1:
            return 'json:', dict(success=False,
                                 message=_("character not found"))
        c = q.first()

        r = self.group.rules[-1] if len(self.group.rules) else None
        if not r or not (isinstance(r, ACLList) and r.grant and not r.inverse
                         and r.kind == 'c'):
            return 'json:', dict(success=False,
                                 message=_("Sorry, I don't know what to do!"))
        if not c.identifier in r.ids:
            return 'json:', dict(
                success=False, message=_("Character not found in last rule!"))
        r.ids.remove(c.identifier)
        if not r.ids:
            # If we just removed the last user in the rule, get rid of the rule.
            self.group.rules.pop(-1)
        success = self.group.save()

        if success:
            return 'json:', dict(success=True)
        return 'json:', dict(success=False,
                             message=_("Failure updating group"))
Example #6
0
    def add_character(self, name=None):
        if not name:
            return 'json:', dict(success=False,
                                 message=_("character name required"))
        q = EVECharacter.objects(name=name)
        assert q.count() <= 1
        if q.count() != 1:
            return 'json:', dict(success=False,
                                 message=_("character not found"))
        c = q.first()

        r = self.group.rules[-1] if len(self.group.rules) else None
        if not r or not (isinstance(r, ACLList) and r.grant and not r.inverse
                         and r.kind == 'c'):
            r = ACLList(grant=True, inverse=False, kind='c', ids=[])
            self.group.rules.append(r)

        if c.identifier in r.ids:
            return 'json:', dict(success=False,
                                 message=_("Character already in rule"))
        r.ids.append(c.identifier)
        success = self.group.save()

        if success:
            return 'json:', dict(success=True)
        return 'json:', dict(success=False,
                             message=_("Failure updating group"))
Example #7
0
    def get(self, admin=False):
        if admin and not is_administrator:
            raise HTTPNotFound()

        characters = user.characters
        if admin:
            characters = EVECharacter.objects()

        return 'brave.core.character.template.list', dict(area='chars',
                                                          admin=bool(admin),
                                                          records=characters)
Example #8
0
    def get(self, admin=False):
        if admin and not is_administrator:
            raise HTTPNotFound()
            
        characters = user.characters
        if admin:
            characters = EVECharacter.objects()

        return 'brave.core.character.template.list', dict(
                area='chars',
                admin=bool(admin),
                records=characters
            )
Example #9
0
    def post(self,
             character=None,
             charMethod=None,
             alliance=None,
             corporation=None,
             group=None):

        # Have to be an admin to access admin pages.
        if not is_administrator:
            raise HTTPNotFound()

        # Seed the initial results.
        chars = EVECharacter.objects()

        # Go through and check all of the possible posted values

        # Limit chars to the character name entered.
        if character:
            if charMethod == 'contains':
                chars = chars.filter(name__icontains=character)
            elif charMethod == 'starts':
                chars = chars.filter(name__istartswith=character)
            elif charMethod == 'is':
                chars = chars.filter(name__iexact=character)
            else:
                return 'json:', dict(
                    success=False,
                    message=_("You broke the web page. Good Job."))

        # Limit to characters in the specified alliance.
        if alliance:
            alliance = EVEAlliance.objects(name=alliance).first()
            chars = chars.filter(alliance=alliance)

        # Limit to characters in the specified corporation.
        if corporation:
            corporation = EVECorporation.objects(name=corporation).first()
            chars = chars.filter(corporation=corporation)

        # Limit to characters in the specified group.
        if group:
            groupList = []
            for c in chars:
                if group in c.tags:
                    groupList.append(c.id)

            chars = chars.filter(id__in=groupList)

        return 'brave.core.admin.template.searchChar', dict(area='admin',
                                                            result=chars,
                                                            success=True)
Example #10
0
 def post(self, character=None, charMethod=None, alliance=None, corporation=None, group=None):
     
     # Have to be an admin to access admin pages.            
     if not is_administrator:
         raise HTTPNotFound()
     
     # Seed the initial results.
     chars = EVECharacter.objects()
         
     # Go through and check all of the possible posted values
     
     # Limit chars to the character name entered.
     if character:
         if charMethod == 'contains':
             chars = chars.filter(name__icontains=character)
         elif charMethod == 'starts':
             chars = chars.filter(name__istartswith=character)
         elif charMethod == 'is':
             chars = chars.filter(name__iexact=character)
         else:
             return 'json:', dict(success=False, message=_("You broke the web page. Good Job."))
     
     # Limit to characters in the specified alliance.
     if alliance:
         alliance = EVEAlliance.objects(name=alliance).first()
         chars = chars.filter(alliance=alliance)
     
     # Limit to characters in the specified corporation.
     if corporation:
         corporation = EVECorporation.objects(name=corporation).first()
         chars = chars.filter(corporation=corporation)
     
     # Limit to characters in the specified group.
     if group:
         groupList = []
         for c in chars:
             if group in c.tags:
                 groupList.append(c.id)
                 
         chars = chars.filter(id__in=groupList)
         
     return 'brave.core.admin.template.searchChar', dict(area='admin', result=chars, success=True)
def delete(override = False):
    """ Deletes every orphaned character in the database."""
    """ WARNING: BACK UP YOUR DATABASE BEFORE RUNNING."""
    dels = 0
    errors = 0
    
    for character in EVECharacter.objects():
        try:
            if not character.credential_for(EVECharacterKeyMask.NULL):
                character.delete()
                dels += 1
        except AttributeError:
            # There's a problem with the character (messed up references perhaps)
            # So delete anyways.
            if override:
                character.delete()
                dels += 1
            else:
                print "Error with character {0}.".format(character,)
                errors += 1

    print "Deleted {0} characters.".format(dels,)
    if errors:
        print "Encountered {0} errors, resolve these manually or run delete True as its argument.".format(errors,)
Example #12
0
from brave.core import core_loadapp
if __name__ == "__main__":
    core_loadapp("config:"+sys.argv[1] if len(sys.argv) > 1 else None)

import time

from requests.exceptions import HTTPError

from brave.core.character.model import EVECharacter
from brave.core.key.model import EVECredential

for k in EVECredential.objects():
    print("refreshing key {}".format(k.id))
    id = k.id
    try:
        k = k.pull()
    except HTTPError as e:
        print("Error {}: {}".format(e.response.status_code, e.response.text))
    if not k:
        print("removed a disabled key")

    # Guarantee that we make a max of 10 QPS to CCP due to this refresh process. Actual QPS will be
    # much lower (due to time spent actually making the calls).
    time.sleep(0.1)

for c in EVECharacter.objects():
    print("checking character {}".format(c))
    if c.credentials == []:
        print("deleting character without keys")
        c.delete()
Example #13
0
 def characters(self):
     from brave.core.character.model import EVECharacter
     return EVECharacter.objects(owner=self)
Example #14
0
    def pull_character(self, info):
        """This always updates all information on the character, so that we do not end up with
        inconsistencies. There is some weirdness that, if a user already has a key with full
        permissions, and adds a limited one, we'll erase information on that character. We should
        probably check for and refresh info from the most-permissioned key instead of this."""
        from brave.core.character.model import EVEAlliance, EVECorporation, EVECharacter
        try:
            char = EVECharacter(identifier=info.characterID).save()
        except NotUniqueError:
            char = EVECharacter.objects(identifier=info.characterID)[0]
            
            if self.owner != char.owner:
                log.warning("Security violation detected. Multiple accounts trying to register character %s, ID %d. Actual owner is %s. User adding this character is %s.",
                    char.name, info.characterID, EVECharacter.objects(identifier = info.characterID).first().owner, self.owner)
                self.violation = "Character"
                return

        if self.mask.has_access(EVECharacterKeyMask.CHARACTER_SHEET):
            info = api.char.CharacterSheet(self, characterID=info.characterID)
        elif self.mask.has_access(EVECharacterKeyMask.CHARACTER_INFO_PUBLIC):
            info = api.eve.CharacterInfo(self, characterID=info.characterID)

        char.corporation, char.alliance = self.get_membership(info)

        char.name = info.name if 'name' in info else info.characterName
        char.owner = self.owner
        if self not in char.credentials:
            char.credentials.append(self)
        char.race = info.race if 'race' in info else None
        char.bloodline = (info.bloodLine if 'bloodLine' in info
                          else info.bloodline if 'bloodline' in info
                          else None)
        char.ancestry = info.ancestry if 'ancestry' in info else None
        char.gender = info.gender if 'gender' in info else None
        char.security = info.security if 'security' in info else None
        char.titles = [strip_tags(i.titleName) for i in info.corporationTitles.row] if 'corporationTitles' in info else []
        char.roles = [i.roleName for i in info.corporationRoles.row] if 'corporationRoles' in info else []

        char.save()
        return char
Example #15
0
 def characters(self):
     from brave.core.character.model import EVECharacter
     return EVECharacter.objects(credentials=self)
Example #16
0
from brave.core import core_loadapp
if __name__ == "__main__":
    core_loadapp("config:" + sys.argv[1] if len(sys.argv) > 1 else None)

import time

from requests.exceptions import HTTPError

from brave.core.character.model import EVECharacter
from brave.core.key.model import EVECredential

for k in EVECredential.objects():
    print("refreshing key {}".format(k.id))
    id = k.id
    try:
        k = k.pull()
    except HTTPError as e:
        print("Error {}: {}".format(e.response.status_code, e.response.text))
    if not k:
        print("removed a disabled key")

    # Guarantee that we make a max of 10 QPS to CCP due to this refresh process. Actual QPS will be
    # much lower (due to time spent actually making the calls).
    time.sleep(0.1)

for c in EVECharacter.objects():
    print("checking character {}".format(c))
    if c.credentials == []:
        print("detaching character without keys")
        c.detach()
Example #17
0
 def characters(self):
     from brave.core.character.model import EVECharacter
     return EVECharacter.objects(owner=self)
Example #18
0
    def pull_character(self, info):
        """This always updates all information on the character, so that we do not end up with
        inconsistencies. There is some weirdness that, if a user already has a key with full
        permissions, and adds a limited one, we'll erase information on that character. We should
        probably check for and refresh info from the most-permissioned key instead of this."""
        from brave.core.character.model import EVEAlliance, EVECorporation, EVECharacter
        try:
            char = EVECharacter(identifier=info.characterID).save()
        except NotUniqueError:
            char = EVECharacter.objects(identifier=info.characterID)[0]

            if self.owner != char.owner:
                log.warning(
                    "Security violation detected. Multiple accounts trying to register character %s, ID %d. Actual owner is %s. User adding this character is %s.",
                    char.name, info.characterID,
                    EVECharacter.objects(
                        identifier=info.characterID).first().owner, self.owner)
                self.violation = "Character"
                return

        if self.mask.has_access(EVECharacterKeyMask.CHARACTER_SHEET):
            info = api.char.CharacterSheet(self, characterID=info.characterID)
        elif self.mask.has_access(EVECharacterKeyMask.CHARACTER_INFO_PUBLIC):
            info = api.eve.CharacterInfo(self, characterID=info.characterID)

        char.corporation, char.alliance = self.get_membership(info)

        char.name = info.name if 'name' in info else info.characterName
        char.owner = self.owner
        if self not in char.credentials:
            char.credentials.append(self)
        char.race = info.race if 'race' in info else None
        char.bloodline = (info.bloodLine if 'bloodLine' in info else
                          info.bloodline if 'bloodline' in info else None)
        char.ancestry = info.ancestry if 'ancestry' in info else None
        char.gender = info.gender if 'gender' in info else None
        char.security = info.security if 'security' in info else None
        char.titles = [
            strip_tags(i.titleName) for i in info.corporationTitles.row
        ] if 'corporationTitles' in info else []
        char.roles = [i.roleName for i in info.corporationRoles.row
                      ] if 'corporationRoles' in info else []

        char.save()
        return char
Example #19
0
 def characters(self):
     from brave.core.character.model import EVECharacter
     return EVECharacter.objects(credentials=self)