Esempio n. 1
0
File: views.py Progetto: yiifaa/CTFd
def private_team():
    if utils.authed():
        teamid = session['id']

        freeze = utils.get_config('freeze')
        user = Teams.query.filter_by(id=teamid).first_or_404()
        solves = Solves.query.filter_by(teamid=teamid)
        awards = Awards.query.filter_by(teamid=teamid)

        place = user.place()
        score = user.score()

        if freeze:
            freeze = utils.unix_time_to_utc(freeze)
            if teamid != session.get('id'):
                solves = solves.filter(Solves.date < freeze)
                awards = awards.filter(Awards.date < freeze)

        solves = solves.all()
        awards = awards.all()

        return render_template('team.html',
                               solves=solves,
                               awards=awards,
                               team=user,
                               score=score,
                               place=place,
                               score_frozen=utils.is_scoreboard_frozen())
    else:
        return redirect(url_for('auth.login'))
Esempio n. 2
0
def scoreboard_view():
    if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    if utils.hide_scores():
        return render_template('scoreboard.html', errors=['Scores are currently hidden'])
    standings = get_standings()
    return render_template('scoreboard.html', teams=standings, score_frozen=utils.is_scoreboard_frozen())
Esempio n. 3
0
def team(teamid):
    if utils.get_config(
            'view_scoreboard_if_utils.authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    errors = []
    freeze = utils.get_config('freeze')
    user = Teams.query.filter_by(id=teamid).first_or_404()
    solves = Solves.query.filter_by(teamid=teamid)
    awards = Awards.query.filter_by(teamid=teamid)

    points = Gamble.query.filter_by(teamid=teamid).all()
    gamble = 0
    for point in points:
        gamble += point.value

    place = user.place()
    score = user.score()

    if freeze:
        freeze = utils.unix_time_to_utc(freeze)
        if teamid != session.get('id'):
            solves = solves.filter(Solves.date < freeze)
            awards = awards.filter(Awards.date < freeze)

    solves = solves.all()
    awards = awards.all()

    db.session.close()

    if utils.hide_scores() and teamid != session.get('id'):
        errors.append('Scores are currently hidden')

    if errors:
        return render_template('team.html', team=user, errors=errors)

    if request.method == 'GET':
        return render_template('team.html',
                               solves=solves,
                               awards=awards,
                               gamble=gamble,
                               team=user,
                               score=score,
                               place=place,
                               score_frozen=utils.is_scoreboard_frozen())
    elif request.method == 'POST':
        json = {'solves': []}
        for x in solves:
            json['solves'].append({
                'id': x.id,
                'chal': x.chalid,
                'team': x.teamid
            })
        return jsonify(json)
Esempio n. 4
0
def comp_scoreboard(compid):
    if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    if utils.hide_scores():
        print 'error!'
        return render_template('compet_scoreboard.html',
                               errors=['Scores are currently hidden'])
    comp = Competitions.query.filter(Competitions.id == compid).first()
    if comp is None:
        abort(404)
    standings = get_range(comp=compid)
    return render_template('compet_scoreboard.html',
                           teams=standings,
                           score_frozen=utils.is_scoreboard_frozen(),
                           comp=comp)
Esempio n. 5
0
def scoreboard_view_contest(contestslug):
    if utils.get_config('view_scoreboard_if_authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    if utils.hide_scores():
        return render_template('scoreboard.html',
                               errors=['Scores are currently hidden'])

    contest = Contests.query.filter_by(slug=contestslug).first()
    contest_dict = vars(contest)
    contest_dict.pop('_sa_instance_state', None)

    standings = get_standings(contestid=contest.id)

    return render_template('scoreboard.html',
                           teams=standings,
                           score_frozen=utils.is_scoreboard_frozen(),
                           contest=contest_dict)
    def scoreboard_view():
        classifications = []
        for classification in db.session.query(
                Classification.classification).distinct():
            classifications.append(classification[0])
        db.session.close()

        classifications = sorted(classifications, reverse=True)

        # -=- For TAMUctf, but can be left in without any problems -=-
        try:
            tamu_test()
            tamu = ["tamu"]
        except:
            tamu = []
        #-=-
        try:
            current_user_class = Classification.query.filter_by(
                id=session.get('id')).first().classification
        except:
            current_user_class = "ALL"
        try:
            current_user_other = Classification.query.filter_by(
                id=session.get('id')).first().other
        except:
            current_user_other = 0

        if utils.get_config(
                'view_scoreboard_if_authed') and not utils.authed():
            return redirect(url_for('auth.login', next=request.path))
        if utils.hide_scores():
            return render_template('scoreboard.html',
                                   errors=['Scores are currently hidden'])
        standings = get_standings()

        return render_template('scoreboard.html',
                               teams=standings,
                               score_frozen=utils.is_scoreboard_frozen(),
                               classifications=classifications,
                               tamu=tamu,
                               current_user_class=current_user_class,
                               current_user_other=current_user_other)
Esempio n. 7
0
def team(teamid):
    if utils.get_config('workshop_mode'):
        abort(404)

    if utils.get_config('view_scoreboard_if_utils.authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    infos = []
    errors = []

    if utils.ctf_paused():
        infos.append('{} is paused'.format(utils.ctf_name()))

    if not utils.ctftime():
        # It is not CTF time
        if utils.view_after_ctf():  # But we are allowed to view after the CTF ends
            pass
        else:  # We are NOT allowed to view after the CTF ends
            if utils.get_config('start') and not utils.ctf_started():
                errors.append('{} has not started yet'.format(utils.ctf_name()))
            if (utils.get_config('end') and utils.ctf_ended()) and not utils.view_after_ctf():
                errors.append('{} has ended'.format(utils.ctf_name()))
    
    freeze = utils.get_config('freeze')
    user = Teams.query.filter_by(id=teamid).first_or_404()
    solves = Solves.query.filter_by(teamid=teamid)
    awards = Awards.query.filter_by(teamid=teamid)

    place = user.place()
    score = user.score()

    if freeze:
        freeze = utils.unix_time_to_utc(freeze)
        if teamid != session.get('id'):
            solves = solves.filter(Solves.date < freeze)
            awards = awards.filter(Awards.date < freeze)

    solves = solves.all()
    awards = awards.all()

    db.session.close()

    if utils.hide_scores() and teamid != session.get('id'):
        errors.append('Scores are currently hidden')
    else:
        # banned is a synonym for hidden :/
        if not utils.is_admin() and (user.admin or user.banned):
            errors.append('Scores are currently hidden')

    if errors:
        return render_template('team.html', team=user, infos=infos, errors=errors)

    if request.method == 'GET':
        return render_template('team.html', solves=solves, awards=awards, team=user, score=score, place=place, score_frozen=utils.is_scoreboard_frozen(), infos=infos)
    elif request.method == 'POST':
        json = {'solves': []}
        for x in solves:
            json['solves'].append({'id': x.id, 'chal': x.chalid, 'team': x.teamid})
        return jsonify(json)
def team_endpoint(teamid):
    if utils.get_config('workshop_mode'):
        abort(404)

    if utils.get_config('view_scoreboard_if_utils.authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    errors = []
    freeze = utils.get_config('freeze')
    user = Teams.query.filter_by(id=teamid).first_or_404()
    solves = Solves.query.filter_by(teamid=teamid)
    awards = Awards.query.filter_by(teamid=teamid)

    place = user.place()
    score = user.score()

    if freeze:
        freeze = utils.unix_time_to_utc(freeze)
        if teamid != session.get('id'):
            solves = solves.filter(Solves.date < freeze)
            awards = awards.filter(Awards.date < freeze)

    solves = solves.all()
    awards = awards.all()
    time_decay_solves = TimeDecaySolves.query.filter_by(teamid=teamid).all()

    db.session.close()

    if utils.hide_scores() and teamid != session.get('id'):
        errors.append('Scores are currently hidden')

    if errors:
        return render_template('team.html', team=user, errors=errors)

    # pass decayed_value
    for s in solves:
        for t in time_decay_solves:
            if t.chalid == s.chalid:
                s.decayed_value = t.decayed_value

    if request.method == 'GET':
        return render_template('team.html', solves=solves, awards=awards, team=user, score=score, place=place, score_frozen=utils.is_scoreboard_frozen())
    elif request.method == 'POST':
        json = {'solves': []}
        for x in solves:
            json['solves'].append({'id': x.id, 'chal': x.chalid, 'team': x.teamid, 'decayed_value': TimeDecayChallenge.value_for_team(x.chalid, x.teamid)})
        return jsonify(json)
Esempio n. 9
0
def team(teamid):
    if utils.get_config('view_scoreboard_if_utils.authed') and not utils.authed():
        return redirect(url_for('auth.login', next=request.path))
    errors = []
    freeze = utils.get_config('freeze')
    user = Teams.query.filter_by(id=teamid).first_or_404()
    solves = Solves.query.filter_by(teamid=teamid)
    awards = Awards.query.filter_by(teamid=teamid)

    place = user.place()
    score = user.score()

    if freeze:
        freeze = utils.unix_time_to_utc(freeze)
        if teamid != session.get('id'):
            solves = solves.filter(Solves.date < freeze)
            awards = awards.filter(Awards.date < freeze)

    solves = solves.all()
    awards = awards.all()

    db.session.close()

    if utils.hide_scores() and teamid != session.get('id'):
        errors.append('Scores are currently hidden')

    if errors:
        return render_template('team.html', team=user, errors=errors)

    if request.method == 'GET':
        return render_template('team.html', solves=solves, awards=awards, team=user, score=score, place=place, score_frozen=utils.is_scoreboard_frozen())
    elif request.method == 'POST':
        json = {'solves': []}
        for x in solves:
            json['solves'].append({'id': x.id, 'chal': x.chalid, 'team': x.teamid})
        return jsonify(json)