示例#1
0
def run_alliance_corp_update():
    with current_app.app_context():
        if EveApiManager.check_if_api_server_online():
            corporations = EveCorporationInfo.query.all()
            for corp in corporations:
                corp_info = EveApiManager.get_corporation_information(
                    corp.corporation_id)
                if corp_info:
                    # Set alliance info first to set foreign key
                    if corp_info['alliance']['id']:
                        alliance_info = EveApiManager.get_alliance_information(
                            corp_info['alliance']['id'])
                        if alliance_info:
                            if not EveAllianceInfo.query.filter_by(
                                    alliance_id=str(
                                        alliance_info['id'])).first():
                                EveManager.create_alliance_info(
                                    alliance_id=alliance_info['id'],
                                    alliance_name=alliance_info['name'],
                                    alliance_ticker=alliance_info['ticker'],
                                    alliance_executor_corp_id=alliance_info[
                                        'executor_id'],
                                    alliance_member_count=alliance_info[
                                        'member_count'])
                            else:
                                EveManager.update_alliance_info(
                                    alliance_id=alliance_info['id'],
                                    alliance_executor_corp_id=alliance_info[
                                        'executor_id'],
                                    alliance_member_count=alliance_info[
                                        'member_count'])
                    EveManager.update_corporation_info(
                        corporation_id=corp_info['id'],
                        corp_member_count=corp_info['members']['current'],
                        alliance_id=corp_info['alliance']['id'])
示例#2
0
def run_alliance_corp_update():
    # I am not proud of this block of code
    if EveApiManager.check_if_api_server_online():
        characters = EveCharacter.query.order_by(
            EveCharacter.character_id).all()
        for character in characters:
            if not EveCorporationInfo.query.filter_by(
                    corporation_id=character.corporation_id).first():
                corpinfo = EveApiManager.get_corporation_information(
                    character.corporation_id)
                if corpinfo:
                    # print corpinfo
                    EveManager.create_corporation_info(
                        corporation_id=corpinfo['id'],
                        corp_name=corpinfo['name'],
                        corp_ticker=corpinfo['ticker'],
                        corp_member_count=corpinfo['members']['current'],
                        alliance_id=corpinfo['alliance']['id'])
            if int(character.alliance_id) != 0:
                if not EveAllianceInfo.query.filter_by(
                        alliance_id=character.alliance_id).first():
                    print character.alliance_id
                    allianceinfo = EveApiManager.get_alliance_information(
                        character.alliance_id)
                    if allianceinfo:
                        # print allianceinfo
                        EveManager.create_alliance_info(
                            alliance_id=allianceinfo['id'],
                            alliance_name=allianceinfo['name'],
                            alliance_ticker=allianceinfo['ticker'],
                            alliance_executor_corp_id=allianceinfo[
                                'executor_id'],
                            alliance_member_count=allianceinfo['member_count'])
示例#3
0
def api_add():
    form = UpdateKeyForm()
    if form.validate_on_submit():
        characters = EveApiManager.get_characters_from_api(form.data['api_id'],
                                                               form.data['api_key'])

        if EveManager.create_api_keypair(form.data['api_id'],
                                          form.data['api_key'],
                                          current_user.get_id()):
            EveManager.create_alliances_from_list(characters)
            EveManager.create_corporations_from_character_list(characters)

            character_creation = EveManager.create_characters_from_list(characters, current_user, form.data['api_id'])
            if character_creation:
                flash(character_creation, category="message")
            # else:
            #     flash("Character error, RIP. (contact IT)", category="message")
        else:
            flash("API Key already in use", category='message')
            return render_template("users/api_add.html", form=form)

        return redirect(url_for('user.api_manage'))

    else:
        return render_template("users/api_add.html", form=form)
示例#4
0
def api_add():
    form = UpdateKeyForm()
    if form.validate_on_submit():
        characters = EveApiManager.get_characters_from_api(
            form.data['api_id'], form.data['api_key'])

        if EveManager.create_api_keypair(form.data['api_id'],
                                         form.data['api_key'],
                                         current_user.get_id()):
            EveManager.create_alliances_from_list(characters)
            EveManager.create_corporations_from_character_list(characters)

            character_creation = EveManager.create_characters_from_list(
                characters, current_user, form.data['api_id'])
            if character_creation:
                flash(character_creation, category="message")
            # else:
            #     flash("Character error, RIP. (contact IT)", category="message")
        else:
            flash("API Key already in use", category='message')
            return render_template("users/api_add.html", form=form)

        return redirect(url_for('user.api_manage'))

    else:
        return render_template("users/api_add.html", form=form)
示例#5
0
def run_api_key_update():
    with current_app.app_context():
        # I am not proud of this block of code
        if EveApiManager.check_if_api_server_online():
            api_keys = EveApiKeyPair.query.order_by(EveApiKeyPair.api_id).all()
            for api_key in api_keys:
                if EveApiManager.check_api_is_not_expire(
                        api_key.api_id, api_key.api_key):
                    EveManager.update_api_keypair(api_key.api_id,
                                                  api_key.api_key)
                    current_app.logger.debug("Updating {0}".format(
                        api_key.api_id))
                else:
                    current_app.logger.debug(
                        "Removing expired api_key {0} {1}".format(
                            api_key.api_id, api_key.api_key))
                    EveManager.delete_api_key_pair(api_key.api_id, None)
示例#6
0
 def create_corporations_from_character_list(characters):
     for character in characters.result:
         if not EveManager.get_corporation_info_by_id(characters.result[character]['corp']['id']):
             corp_info = EveApiManager.get_corporation_information(characters.result[character]['corp']['id'])
             if corp_info:
                 EveManager.create_corporation_info(corporation_id=corp_info['id'],
                                                    corp_name=corp_info['name'],
                                                    corp_ticker=corp_info['ticker'],
                                                    corp_member_count=corp_info['members']['current'],
                                                    alliance_id=corp_info['alliance']['id'])
示例#7
0
def run_api_key_update():
    with current_app.app_context():
        # I am not proud of this block of code
        if EveApiManager.check_if_api_server_online():
            api_keys = EveApiKeyPair.query.order_by(EveApiKeyPair.api_id).all()
            for api_key in api_keys:
                if not EveApiManager.check_api_is_type_account(api_key.api_id,
                                                               api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                if not EveApiManager.check_api_is_full(api_key.api_id,
                                                       api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                if not EveApiManager.check_api_is_not_expire(api_key.api_id,
                                                             api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                EveManager.update_api_keypair(api_key.api_id, api_key.api_key)
示例#8
0
def run_api_key_update():
    with current_app.app_context():
        # I am not proud of this block of code
        if EveApiManager.check_if_api_server_online():
            api_keys = EveApiKeyPair.query.order_by(EveApiKeyPair.api_id).all()
            for api_key in api_keys:
                if not EveApiManager.check_api_is_type_account(
                        api_key.api_id, api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                if not EveApiManager.check_api_is_full(api_key.api_id,
                                                       api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                if not EveApiManager.check_api_is_not_expire(
                        api_key.api_id, api_key.api_key):
                    EveManager.delete_characters_by_api_id(api_key.api_id)

                EveManager.update_api_keypair(api_key.api_id, api_key.api_key)
示例#9
0
 def create_corporations_from_character_list(characters):
     for character in characters.result:
         if not EveManager.check_if_corporation_exists_by_id(characters.result[character]['corp']['id']):
             corp_info = EveApiManager.get_corporation_information(characters.result[character]['corp']['id'])
             if corp_info:
                 EveManager.create_corporation_info(corporation_id=corp_info['id'],
                                                    corp_name=corp_info['name'],
                                                    corp_ticker=corp_info['ticker'],
                                                    corp_member_count=corp_info['members']['current'],
                                                    alliance_id=corp_info['alliance']['id'])
示例#10
0
 def create_alliances_from_list(characters):
     for character in characters.result:
         if characters.result[character]['alliance']['id'] != 0:
             if not EveManager.check_if_alliance_exists_by_id(characters.result[character]['alliance']['id']):
                 alliance_info = EveApiManager.get_alliance_information(characters.result[character]['alliance']['id'])
                 # print alliance_info
                 if alliance_info:
                     EveManager.create_alliance_info(alliance_id=alliance_info['id'],
                                                     alliance_name=alliance_info['name'],
                                                     alliance_ticker=alliance_info['ticker'],
                                                     alliance_executor_corp_id=alliance_info['executor_id'],
                                                     alliance_member_count=alliance_info['member_count'])
示例#11
0
 def create_alliances_from_list(characters):
     for character in characters.result:
         if characters.result[character]['alliance']['id'] != 0:
             if not EveManager.get_alliance_info_by_id(characters.result[character]['alliance']['id']):
                 alliance_info = EveApiManager.get_alliance_information(characters.result[character]['alliance']['id'])
                 # print alliance_info
                 if alliance_info:
                     EveManager.create_alliance_info(alliance_id=alliance_info['id'],
                                                     alliance_name=alliance_info['name'],
                                                     alliance_ticker=alliance_info['ticker'],
                                                     alliance_executor_corp_id=alliance_info['executor_id'],
                                                     alliance_member_count=alliance_info['member_count'])
示例#12
0
def run_alliance_corp_update():
    with current_app.app_context():
        # I am not proud of this block of code
        if EveApiManager.check_if_api_server_online():
            characters = EveCharacter.query.order_by(EveCharacter.character_id).all()
            for character in characters:
                corp_info = EveApiManager.get_corporation_information(character.corporation_id)
                if corp_info:
                    if not EveCorporationInfo.query.filter_by(corporation_id=character.corporation_id).first():
                        # print corp_info
                        EveManager.create_corporation_info(corporation_id=corp_info['id'],
                                                           corp_name=corp_info['name'],
                                                           corp_ticker=corp_info['ticker'],
                                                           corp_member_count=corp_info['members']['current'],
                                                           alliance_id=corp_info['alliance']['id'])
                    else:
                        EveManager.update_corporation_info(corporation_id=corp_info['id'],
                                                           corp_member_count=corp_info['members']['current'],
                                                           alliance_id=corp_info['alliance']['id'])
                if character.alliance_id:
                    if character.alliance_id != "0":
                        alliance_info = EveApiManager.get_alliance_information(character.alliance_id)
                        if alliance_info:
                            if not EveAllianceInfo.query.filter_by(alliance_id=character.alliance_id).first():
                                # print alliance_info
                                EveManager.create_alliance_info(alliance_id=alliance_info['id'],
                                                                alliance_name=alliance_info['name'],
                                                                alliance_ticker=alliance_info['ticker'],
                                                                alliance_executor_corp_id=alliance_info['executor_id'],
                                                                alliance_member_count=alliance_info['member_count'])
                            else:
                                # print alliance_info
                                EveManager.create_alliance_info(alliance_id=alliance_info['id'],
                                                                alliance_name=alliance_info['name'],
                                                                alliance_ticker=alliance_info['ticker'],
                                                                alliance_executor_corp_id=alliance_info['executor_id'],
                                                                alliance_member_count=alliance_info['member_count'])
示例#13
0
    def update_api_keypair(api_id, api_key):
        # print "api update"
        api_pair = EveApiKeyPair.query.filter_by(api_id=api_id).first()
        if api_pair:

            characters = EveApiManager.get_characters_from_api(api_id=api_id, api_key=api_key)

            EveManager.update_characters_from_list(characters=characters,
                                                   user_id=api_pair.user_id,
                                                   api_id=api_pair.api_id)
            api_pair.last_update_time = dt.datetime.utcnow()
            api_pair.save()
            return True

        return False
示例#14
0
    def update_api_keypair(api_id, api_key):
        # print "api update"
        api_pair = EveApiKeyPair.query.filter_by(api_id=api_id).first()
        if api_pair:

            characters = EveApiManager.get_characters_from_api(api_id=api_id,
                                                               api_key=api_key)

            EveManager.update_characters_from_list(characters=characters,
                                                   user_id=api_pair.user_id,
                                                   api_id=api_pair.api_id)
            api_pair.last_update_time = dt.datetime.utcnow()
            api_pair.save()
            return True

        return False
示例#15
0
def jackknife_proxy():
    # Remove any passed in apik and redirect back without it
    if 'apik' in request.args:
        cleanargs = request.args.copy()
        cleanargs.pop('apik')
        return redirect(url_for('eveapi.jackknife_proxy', **cleanargs))

    try:
        api_key = EveApiKeyPair.query.filter_by(
            api_id=request.args['usid']).first().api_key
    except:
        return 'API key not in database.'

    if 'chid' in request.args and not (
            current_user.has_role("restricted_api_view")
            or current_user.has_role("admin")):
        chid = request.values['chid']

        if EveApiManager.check_if_character_is_in_alliance(
                int(chid), 1354830081):
            return 'Insufficient permissions to view KarmaFleet character page.'

    url = current_app.config[
        'JACK_KNIFE_URL'] + '?' + request.query_string + '&apik=' + api_key
    headers = {
        'User-Agent': 'KarmaFleet API Check',
        'From': '*****@*****.**'
    }  # Be nice to Jackknife and send some info about us
    req = requests.get(url, stream=True, headers=headers)

    # Some python generator magic to intercept each line and sanitize API keys, and redirect links back to audit.php with ours
    def streamJackknife():
        for line in req.iter_lines():
            line = re.sub(current_app.config['JACK_KNIFE_URL'], 'audit.php',
                          line)
            line = re.sub('apik=[^&#"]*&?', '', line)
            line = re.sub('http://ajax\.googleapis\.com',
                          'https://ajax.googleapis.com',
                          line)  # need to switch to secure js
            yield line + '\n'

    return Response(stream_with_context(streamJackknife()))
示例#16
0
    def update_api_keypair(api_id, api_key):
        # print "api update"
        api_pair = EveApiKeyPair.query.filter_by(api_id=api_id).first()
        if api_pair:

            characters = EveApiManager.get_characters_from_api(api_id=api_id, api_key=api_key)
            if not characters:
                return False

            EveManager.update_characters_from_list(characters=characters,
                                                   user=api_pair.user,
                                                   api_id=api_pair.api_id)
                                                   
            # Now, archive any characters that don't exist anymore
            for old_api_char in api_pair.characters:
                found = False
                for char in characters.result:
                    if str(characters.result[char]['id']) == str(old_api_char.character_id):
                        found = True
                        break
                if not found:
                    for char in api_pair.user.previous_chars:
                        if str(old_api_char.character_id) == str(char.character_id):
                            found = True
                            break
                    if not found:
                        api_pair.user.previous_chars.append(old_api_char)
                    if str(api_pair.user.main_character_id) == str(old_api_char.character_id):
                        api_pair.user.main_character_id = None
                    api_pair.user.save(commit=False)
                    old_api_char.user_id = None
                    old_api_char.api_id = None
                    old_api_char.save(commit=False)                
            
            api_pair.last_update_time = dt.datetime.utcnow()
            api_pair.save()
            return True

        return False
示例#17
0
def submit_issue():
    # Check if user is in Karmafleet (98370861)
    if not EveApiManager.check_if_character_is_in_corp(
            int(current_user.main_character_id), 98370861):
        flash('You are not a current KarmaFleet member.', 'error')
        return redirect(url_for('public.home'))

    form = SubmitIssueForm()

    # Display for if get, submit if POST
    if request.method == 'POST':
        if form.validate_on_submit():
            # Do the submission
            if IaManager.submit_issue(current_user, form.subject.data,
                                      form.body.data, form.logs.data):
                flash('Issue submitted successfully.', 'info')
            else:
                flash('Error submitting issue.  Please try again later.',
                      'error')
            return redirect(url_for('public.home'))

    # GET
    return render_template('ia/submit_issue.html', form=form)