diff --git a/CTFd/admin.py b/CTFd/admin.py index 5af4865..8314936 100644 --- a/CTFd/admin.py +++ b/CTFd/admin.py @@ -452,6 +452,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(): @@ -474,7 +483,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.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() + + 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/CTFd/challenges.py b/CTFd/challenges.py index 9fd9176..54db837 100644 --- a/CTFd/challenges.py +++ b/CTFd/challenges.py @@ -120,7 +120,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() @@ -129,7 +129,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 new file mode 100644 index 0000000..bc0090a --- /dev/null +++ b/templates/admin/correct_keys.html @@ -0,0 +1,89 @@ +{% extends "admin/base.html" %} + +{% block content %} + +
+

Correct Key Submissions

+
+

Delete Key

+
+ +
+

Are you sure you want to delete successful key submission for team: in challenge: ?

+ + +
+
+ × +
+ + + + + + + + + + + + {% for solve in solves %} + + + + + + + + {% endfor %} + +
Team + Challenge + Date + Key Submitted + Delete +
{{ solve.team_name }} + {{ solve.chal_name }}{{ solve.date }}{{ solve.flag }}
+ {% 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 64a87c3..2c105b0 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 %}