コード例 #1
0
def admin_score_adjust(tid):
    value = int(request.form["value"])
    reason = request.form["reason"]

    team = Team.get(Team.id == tid)

    ScoreAdjustment.create(team=team, value=value, reason=reason)
    flash("Score adjusted.")

    return redirect(url_for(".admin_show_team", tid=tid))
コード例 #2
0
ファイル: app.py プロジェクト: sdamashek/ctf-platform
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] + [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html", team_solves=team_solves, team_adjustments=team_adjustments, team_score=team_score, first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()), 120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email, g.team.email_confirmation_key, g.team.key)
            flash("Changes saved. Please check your email for a new confirmation key.")
        else:
            flash("Changes saved.")
        g.team.save()


        return redirect(url_for('dashboard'))
コード例 #3
0
def admin_dashboard():
    teams = Team.select()
    solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge)
    adjustments = ScoreAdjustment.select()
    scoredata = utils.scoreboard.get_all_scores(teams, solves, adjustments)
    lastsolvedata = utils.scoreboard.get_last_solves(teams, solves)
    tickets = list(TroubleTicket.select().where(TroubleTicket.active == True))
    return render_template("admin/dashboard.html", teams=teams, scoredata=scoredata, lastsolvedata=lastsolvedata, tickets=tickets)
コード例 #4
0
def calculate_graph(scoredata):
    solves = list(ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge).order_by(ChallengeSolve.time))
    adjustments = list(ScoreAdjustment.select())
    scoredata = [i for i in scoredata if i[0]] # Only eligible teams are on the score graph
    graph_data = []
    for eligible, tid, name, affiliation, score in scoredata[:config.teams_on_graph]:
        our_solves = [i for i in solves if i.team_id == tid]
        team_data = []
        s = sum([i.value for i in adjustments if i.team_id == tid])
        for i in sorted(our_solves, key=lambda k: k.time):
            team_data.append((str(i.time), s))
            s += i.challenge.points
            team_data.append((str(i.time + timedelta(microseconds=1000)), s))
        team_data.append((str(datetime.now()), score))
        graph_data.append((name, team_data))
    return graph_data
コード例 #5
0
def calculate_scores():
    solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge)
    adjustments = ScoreAdjustment.select()
    teams = Team.select()

    team_solves = {team.id: [] for team in teams}
    team_mapping = {team.id: team for team in teams}
    scores = {team.id: 0 for team in teams}
    for solve in solves:
        scores[solve.team_id] += solve.challenge.points
        team_solves[solve.team_id].append(solve)
    for adjustment in adjustments:
        scores[adjustment.team_id] += adjustment.value

    most_recent_solve = {tid: max([i.time for i in team_solves[tid]]) for tid in team_solves if team_solves[tid]}
    scores = {i: j for i, j in scores.items() if i in most_recent_solve}
    # eligible, teamid, teamname, affiliation, score
    return [(team_mapping[i[0]].eligible, i[0], team_mapping[i[0]].name, team_mapping[i[0]].affiliation, i[1]) for idx, i in enumerate(sorted(scores.items(), key=lambda k: (-k[1], most_recent_solve[k[0]])))]
コード例 #6
0
ファイル: app.py プロジェクト: AnonymousXF/ctf-platform
def team_dashboard():
    if request.method == "GET":
        if "team_id" in session:
            team_solves = ChallengeSolve.select(ChallengeSolve, Challenge).join(Challenge).where(
            ChallengeSolve.team == g.team)
            team_adjustments = ScoreAdjustment.select().where(ScoreAdjustment.team == g.team)
            team_score = sum([i.challenge.points for i in team_solves] + [i.value for i in team_adjustments])
            first_login = False
            if g.team.first_login:
                first_login = True
                g.team.first_login = False
                g.team.save()
            if g.team.team_leader.id == g.user.id:
                team_members = User.select().join(TeamMember).join(Team).where(Team.id == g.team.id)
                users = TeamMember.select().where(TeamMember.team == g.team)
                return render_template("team_dashboard.html", team_solves=team_solves, team_adjustments=team_adjustments,
        team_score=team_score, first_login=first_login, team_members=team_members, users=users)
            else:
                return render_template("team_dashboard.html", team_solves=team_solves, team_adjustments=team_adjustments,
        team_score=team_score, first_login=first_login)
        else:
            return render_template("team_dashboard.html")
コード例 #7
0
ファイル: app.py プロジェクト: sdamashek/ctf-platform
def dashboard():
    if request.method == "GET":
        team_solves = ChallengeSolve.select(
            ChallengeSolve,
            Challenge).join(Challenge).where(ChallengeSolve.team == g.team)
        team_adjustments = ScoreAdjustment.select().where(
            ScoreAdjustment.team == g.team)
        team_score = sum([i.challenge.points for i in team_solves] +
                         [i.value for i in team_adjustments])
        first_login = False
        if g.team.first_login:
            first_login = True
            g.team.first_login = False
            g.team.save()
        return render_template("dashboard.html",
                               team_solves=team_solves,
                               team_adjustments=team_adjustments,
                               team_score=team_score,
                               first_login=first_login)

    elif request.method == "POST":
        if g.redis.get("ul{}".format(session["team_id"])):
            flash("You're changing your information too fast!")
            return redirect(url_for('dashboard'))

        team_name = request.form["team_name"].strip()
        team_email = request.form["team_email"].strip()
        affiliation = request.form["affiliation"].strip()
        team_elig = "team_eligibility" in request.form

        if len(team_name) > 50 or not team_name:
            flash("You must have a team name!")
            return redirect(url_for('dashboard'))

        if not (team_email and "." in team_email and "@" in team_email):
            flash("You must have a valid team email!")
            return redirect(url_for('dashboard'))

        if not affiliation or len(affiliation) > 100:
            affiliation = "No affiliation"

        email_changed = (team_email != g.team.email)

        g.team.name = team_name
        g.team.email = team_email
        g.team.affiliation = affiliation
        if not g.team.eligibility_locked:
            g.team.eligible = team_elig

        g.redis.set("ul{}".format(session["team_id"]), str(datetime.now()),
                    120)

        if email_changed:
            if not email.is_valid_email(team_email):
                flash("You're lying")
                return redirect(url_for('dashboard'))

            g.team.email_confirmation_key = misc.generate_confirmation_key()
            g.team.email_confirmed = False

            email.send_confirmation_email(team_email,
                                          g.team.email_confirmation_key,
                                          g.team.key)
            flash(
                "Changes saved. Please check your email for a new confirmation key."
            )
        else:
            flash("Changes saved.")
        g.team.save()

        return redirect(url_for('dashboard'))