Esempio n. 1
0
File: signal.py Progetto: Acen/core
def trigger_api_validation(sender, document, **kwargs):
    """Trigger validation of newly created EVE API Credential documents."""
    from brave.core.key.model import EVECredential
    
    if not kwargs.get('created', False):
        return
    
    if config.get('debug', False):
        EVECredential.objects(id=document.id).first().pull()
    
    else:
        validator_pool.submit(EVECredential.object(id=document.id).first().pull)
Esempio n. 2
0
def trigger_api_validation(sender, document, **kwargs):
    """Trigger validation of newly created EVE API Credential documents."""
    from brave.core.key.model import EVECredential

    if not kwargs.get('created', False):
        return

    if config.get('debug', False):
        EVECredential.objects(id=document.id).first().pull()

    else:
        validator_pool.submit(
            EVECredential.object(id=document.id).first().pull)
Esempio n. 3
0
def delete():
    """ Deletes every duplicate key in the database."""
    """ WARNING: DELETED EVERY INSTANCE OF THAT KEY."""
    dups = []
    
    for credential in EVECredential.objects():
        if len(EVECredential.objects(key=credential.key)) > 1:
            for c in EVECredential.objects(key=credential.key):
                dups.append(c)

    print "Deleting {0} keys.".format(len(set(dups)),)

    for c in dups:
        c.delete()
Esempio n. 4
0
def delete(delete=False):
    """ Deletes every key from before the leak from the database."""
    
    x = 0
    
    for credential in EVECredential.objects():
        if len(EVECredential.objects(key=credential.key)) > 1:
            for c in EVECredential.objects(key__lt=3283828):
                x += 1
                print c.key
                if delete:
                    c.delete

    print "Deleted {0} keys.".format(x)
Esempio n. 5
0
def delete():
    """ Deletes every duplicate key in the database."""
    """ WARNING: DELETED EVERY INSTANCE OF THAT KEY."""
    dups = []

    for credential in EVECredential.objects():
        if len(EVECredential.objects(key=credential.key)) > 1:
            for c in EVECredential.objects(key=credential.key):
                dups.append(c)

    print "Deleting {0} keys.".format(len(set(dups)), )

    for c in dups:
        c.delete()
Esempio n. 6
0
    def post(self, keyID=None, keyMask=None, violation=None):

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

        # Seed the initial results.
        keys = EVECredential.objects()

        # Limit to keys with the specified ID.
        if keyID:
            keys = keys.filter(key=keyID)

        # Limit to keys with the specified Mask.
        if keyMask:
            keys = keys.filter(_mask=keyMask)

        # Limit to keys with the specified violation.
        if violation.lower() == "none":
            keys = keys.filter(violation=None)
        elif violation:
            keys = keys.filter(violation__iexact=violation)

        return 'brave.core.admin.template.searchKey', dict(area='admin',
                                                           result=keys,
                                                           success=True)
Esempio n. 7
0
 def post(self, keyID=None, keyMask=None, violation=None):
     
     # Have to be an admin to access admin pages.            
     if not is_administrator:
         raise HTTPNotFound()
     
     # Seed the initial results.
     keys = EVECredential.objects()
     
     # Limit to keys with the specified ID.
     if keyID:
         keys = keys.filter(key=keyID)
     
     # Limit to keys with the specified Mask.
     if keyMask:
         keys = keys.filter(_mask=keyMask)
         
     # Limit to keys with the specified violation.
     if violation.lower() == "none":
         keys = keys.filter(violation=None)
     elif violation:
         keys = keys.filter(violation__iexact=violation)
         
     return 'brave.core.admin.template.searchKey', dict(area='admin', result=keys, success=True)
Esempio n. 8
0
 def credentials(self):
     from brave.core.key.model import EVECredential
     return EVECredential.objects(owner=self)
Esempio n. 9
0
from __future__ import absolute_import, print_function, unicode_literals

import sys
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 == []:
Esempio n. 10
0
 def credentials(self):
     from brave.core.key.model import EVECredential
     return EVECredential.objects(owner=self)
Esempio n. 11
0
    def post(self, **kw):
        data = Bunch(kw)

        try:
            data.key = int(data.key)
            if data.key <= int(config["core.minimum_key_id"]):
                return (
                    "json:",
                    dict(
                        success=False,
                        message=_(
                            "The key given (%d) must be above minimum reset floor value of %d. "
                            "Please reset your EVE API Key." % (data.key, int(config["core.minimum_key_id"]))
                        ),
                        field="key",
                    ),
                )

        except ValueError:
            return "json:", dict(success=False, message=_("Key ID must be a number."), field="key")

        record = EVECredential(data.key, data.code, owner=user.id)

        try:
            record.save()
            # Necessary to guarantee that the pull finished before returning.
            record.pull()
            characters = []
            for character in record.characters:
                characters.append(dict(identifier=character.identifier, name=character.name))

            if request.is_xhr:
                return (
                    "json:",
                    dict(
                        success=True,
                        message=_("Successfully added EVE API key."),
                        identifier=str(record.id),
                        key=record.key,
                        code=record.code,
                        characters=characters,
                        violation=record.violation,
                    ),
                )

        except ValidationError:
            if request.is_xhr:
                return (
                    "json:",
                    dict(success=False, message=_("Validation error: one or more fields are incorrect or missing.")),
                )
        except NotUniqueError:
            if EVECredential.objects(key=data.key):
                # Mark both of these accounts as duplicates to each other.
                acc = User.objects(username=user.username).first()
                other = EVECredential.objects(key=data.key).first().owner

                User.add_duplicate(acc, other)

            return (
                "json:",
                dict(success=False, message=_("This key has already been added to this or another account.")),
            )

        raise HTTPFound(location="/key/")
Esempio n. 12
0
from __future__ import absolute_import, print_function, unicode_literals

import sys
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 == []:
Esempio n. 13
0
    def post(self, **kw):
        data = Bunch(kw)

        try:
            data.key = int(data.key)
            if data.key <= int(config['core.minimum_key_id']):
                return 'json:', dict(
                    success=False,
                    message=_(
                        "The key given (%d) must be above minimum reset floor value of %d. "
                        "Please reset your EVE API Key." %
                        (data.key, int(config['core.minimum_key_id']))),
                    field='key')

        except ValueError:
            return 'json:', dict(success=False,
                                 message=_("Key ID must be a number."),
                                 field='key')

        record = EVECredential(data.key, data.code, owner=user.id)

        try:
            record.save()
            #Necessary to guarantee that the pull finished before returning.
            record.pull()
            characters = []
            for character in record.characters:
                characters.append(
                    dict(identifier=character.identifier, name=character.name))

            if request.is_xhr:
                return 'json:', dict(
                    success=True,
                    message=_("Successfully added EVE API key."),
                    identifier=str(record.id),
                    key=record.key,
                    code=record.code,
                    characters=characters,
                    violation=record.violation)

        except ValidationError:
            if request.is_xhr:
                return 'json:', dict(
                    success=False,
                    message=
                    _("Validation error: one or more fields are incorrect or missing."
                      ),
                )
        except NotUniqueError:
            if EVECredential.objects(key=data.key):
                # Mark both of these accounts as duplicates to each other.
                acc = User.objects(username=user.username).first()
                other = EVECredential.objects(key=data.key).first().owner

                User.add_duplicate(acc, other)

            return 'json:', dict(
                success=False,
                message=
                _("This key has already been added to this or another account."
                  ),
            )

        raise HTTPFound(location='/key/')