From f660a760e63d05cab22788549f5e82d078eaad4c Mon Sep 17 00:00:00 2001 From: Sean Meyer Date: Tue, 19 May 2015 11:55:41 +0800 Subject: [PATCH 1/2] view incorrect/correct key submission interfaces --- CTFd/admin.py | 32 ++++++++++++++++++++++ templates/admin/correct_keys.html | 42 +++++++++++++++++++++++++++++ templates/admin/statistics.html | 4 +-- templates/admin/wrong_keys.html | 45 +++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 templates/admin/correct_keys.html create mode 100644 templates/admin/wrong_keys.html diff --git a/CTFd/admin.py b/CTFd/admin.py index a4f532a..05a18b3 100644 --- a/CTFd/admin.py +++ b/CTFd/admin.py @@ -450,7 +450,39 @@ def init_admin(app): least_solved=least_solved_chal ) + @app.route('/admin/wrong_keys/', methods=['GET']) + @admins_only + def admin_wrong_key(page='1'): + page = abs(int(page)) + results_per_page = 50 + page_start = results_per_page * ( page - 1 ) + page_end = results_per_page * ( page - 1 ) + results_per_page + wrong_keys = WrongKeys.query.add_columns(WrongKeys.flag, WrongKeys.team, WrongKeys.date,\ + Challenges.name.label('chal_name'), Teams.name.label('team_name')).\ + join(Challenges).join(Teams).order_by('team_name ASC').slice(page_start, page_end).all() + + wrong_count = db.session.query(db.func.count(WrongKeys.id)).first()[0] + pages = int(wrong_count / results_per_page) + (wrong_count % results_per_page > 0) + + return render_template('admin/wrong_keys.html', wrong_keys=wrong_keys, pages=pages) + + @app.route('/admin/correct_keys/', methods=['GET']) + @admins_only + def admin_correct_key(page='1'): + page = abs(int(page)) + results_per_page = 50 + page_start = results_per_page * (page - 1) + page_end = results_per_page * (page - 1) + results_per_page + + solves = Solves.query.add_columns(Solves.teamid, Solves.date,\ + Challenges.name.label('chal_name'), Teams.name.label('team_name')).\ + join(Challenges).join(Teams).order_by('team_name ASC').slice(page_start, page_end).all() + + solve_count = db.session.query(db.func.count(Solves.id)).first()[0] + pages = int(solve_count / results_per_page) + (solve_count % results_per_page > 0) + + return render_template('admin/correct_keys.html', solves=solves, pages=pages) @app.route('/admin/fails/', methods=['GET']) @admins_only diff --git a/templates/admin/correct_keys.html b/templates/admin/correct_keys.html new file mode 100644 index 0000000..9539d9f --- /dev/null +++ b/templates/admin/correct_keys.html @@ -0,0 +1,42 @@ +{% extends "admin/base.html" %} + +{% block content %} + +
+

Correct Key Submissions

+ + + + + + + + + + {% for solve in solves %} + + + + + + {% endfor %} + +
Team + Challenge + Date +
{{ solve.team_name }} + {{ solve.chal_name }}{{ solve.date }}
+ {% if pages > 1 %} +
Page +
+ {% for page in range(1, pages + 1) %} + {{ page }} + {% endfor %} + +
+ {% endif %} +
+{% endblock %} + +{% block scripts %} +{% endblock %} diff --git a/templates/admin/statistics.html b/templates/admin/statistics.html index 45580cf..d35f1a1 100644 --- a/templates/admin/statistics.html +++ b/templates/admin/statistics.html @@ -6,8 +6,8 @@

Statistics

{{ team_count }} teams registered

-

{{ wrong_count }} wrong keys submitted

-

{{ solve_count }} right keys submitted

+

{{ wrong_count }} wrong keys submitted

+

{{ solve_count }} right keys submitted

{{ challenge_count }} challenges

{% if most_solved %}

Most solved: {{ most_solved[0].chal.name }} with {{ most_solved[1] }} solves

diff --git a/templates/admin/wrong_keys.html b/templates/admin/wrong_keys.html new file mode 100644 index 0000000..a6fc6d6 --- /dev/null +++ b/templates/admin/wrong_keys.html @@ -0,0 +1,45 @@ +{% extends "admin/base.html" %} + +{% block content %} + +
+

Incorrect Key Submissions

+ + + + + + + + + + + {% for wrong_key in wrong_keys %} + + + + + + + {% endfor %} + +
Team + Challenge + Date + Submitted Key +
{{ wrong_key.team_name }} + {{ wrong_key.chal_name }}{{ wrong_key.date }}{{ wrong_key.flag }}
+ {% if pages > 1 %} +
Page +
+ {% for page in range(1, pages + 1) %} + {{ page }} + {% endfor %} + +
+ {% endif %} +
+{% endblock %} + +{% block scripts %} +{% endblock %} From 18ddd1eeec40cd883abc49a65236d6345dbab156 Mon Sep 17 00:00:00 2001 From: Sean Meyer Date: Tue, 19 May 2015 13:52:15 +0800 Subject: [PATCH 2/2] Key submission now stored. Correct key submissions can be deleted. --- CTFd/admin.py | 11 ++++++- CTFd/challenges.py | 4 +-- CTFd/models.py | 4 ++- templates/admin/correct_keys.html | 55 ++++++++++++++++++++++++++++--- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/CTFd/admin.py b/CTFd/admin.py index 05a18b3..5343f35 100644 --- a/CTFd/admin.py +++ b/CTFd/admin.py @@ -428,6 +428,15 @@ def init_admin(app): json['solves'].append({'id':x.id, 'chal':x.chal.name, 'chalid':x.chalid,'team':x.teamid, 'value': x.chal.value, 'category':x.chal.category, 'time':unix_time(x.date)}) return jsonify(json) + + @app.route('/admin/solves///delete', methods=['POST']) + @admins_only + def delete_solve(teamid, chalid): + solve = Solves.query.filter_by(teamid=teamid, chalid=chalid).first() + db.session.delete(solve) + db.session.commit() + return '1' + @app.route('/admin/statistics', methods=['GET']) @admins_only def admin_stats(): @@ -475,7 +484,7 @@ def init_admin(app): page_start = results_per_page * (page - 1) page_end = results_per_page * (page - 1) + results_per_page - solves = Solves.query.add_columns(Solves.teamid, Solves.date,\ + solves = Solves.query.add_columns(Solves.chalid, Solves.teamid, Solves.date, Solves.flag, \ Challenges.name.label('chal_name'), Teams.name.label('team_name')).\ join(Challenges).join(Teams).order_by('team_name ASC').slice(page_start, page_end).all() diff --git a/CTFd/challenges.py b/CTFd/challenges.py index 3c9ed2e..14743b1 100644 --- a/CTFd/challenges.py +++ b/CTFd/challenges.py @@ -99,7 +99,7 @@ def init_challenges(app): for x in keys: if x.key_type == 0: #static key if x.flag.strip().lower() == key: - solve = Solves(chalid=chalid, teamid=session['id'], ip=request.remote_addr) + solve = Solves(chalid=chalid, teamid=session['id'], ip=request.remote_addr, flag=key) db.session.add(solve) db.session.commit() db.session.close() @@ -108,7 +108,7 @@ def init_challenges(app): elif x.key_type == 1: #regex res = re.match(str(x), key, re.IGNORECASE) if res and res.group() == key: - solve = Solves(chalid=chalid, teamid=session['id'], ip=request.remote_addr) + solve = Solves(chalid=chalid, teamid=session['id'], ip=request.remote_addr, flag=key) db.session.add(solve) db.session.commit() db.session.close() diff --git a/CTFd/models.py b/CTFd/models.py index 88f1524..adf717a 100644 --- a/CTFd/models.py +++ b/CTFd/models.py @@ -135,15 +135,17 @@ class Solves(db.Model): chalid = db.Column(db.Integer, db.ForeignKey('challenges.id')) teamid = db.Column(db.Integer, db.ForeignKey('teams.id')) ip = db.Column(db.Integer) + flag = db.Column(db.Text) date = db.Column(db.DateTime, default=datetime.datetime.utcnow) team = db.relationship('Teams', foreign_keys="Solves.teamid", lazy='joined') chal = db.relationship('Challenges', foreign_keys="Solves.chalid", lazy='joined') # value = db.Column(db.Integer) - def __init__(self, chalid, teamid, ip): + def __init__(self, chalid, teamid, ip, flag): self.ip = ip2long(ip) self.chalid = chalid self.teamid = teamid + self.flag = flag # self.value = value def __repr__(self): diff --git a/templates/admin/correct_keys.html b/templates/admin/correct_keys.html index 9539d9f..bc0090a 100644 --- a/templates/admin/correct_keys.html +++ b/templates/admin/correct_keys.html @@ -4,6 +4,18 @@

Correct Key Submissions

+
@@ -13,15 +25,21 @@ + + {% for solve in solves %} - - - + + + + + {% endfor %} @@ -39,4 +57,33 @@ {% endblock %} {% block scripts %} + {% endblock %}
Date Key Submitted + Delete +
{{ solve.team_name }} - {{ solve.chal_name }}{{ solve.date }}{{ solve.team_name }} + {{ solve.chal_name }}{{ solve.date }}{{ solve.flag }}