mirror of https://github.com/JohnHammond/CTFd.git
Adding ability to mark challenges as solved
parent
4d363f25cb
commit
4fd0d333df
|
@ -519,19 +519,29 @@ def admin_solves(teamid="all"):
|
|||
return jsonify(json_data)
|
||||
|
||||
|
||||
@admin.route('/admin/solves/<teamid>/<chalid>/solve', methods=['POST'])
|
||||
@admins_only
|
||||
def create_solve(teamid, chalid):
|
||||
solve = Solves(chalid=chalid, teamid=teamid, ip='127.0.0.1', flag='MARKED_AS_SOLVED_BY_ADMIN')
|
||||
db.session.add(solve)
|
||||
db.session.commit()
|
||||
db.session.close()
|
||||
return '1'
|
||||
|
||||
@admin.route('/admin/solves/<teamid>/<chalid>/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()
|
||||
db.session.close()
|
||||
return '1'
|
||||
|
||||
|
||||
@admin.route('/admin/wrong_keys/<teamid>/<chalid>/delete', methods=['POST'])
|
||||
@admins_only
|
||||
def delete_wrong_key(teamid, chalid):
|
||||
wrong_key = WrongKeys.query.filter_by(team=teamid, chalid=chalid).first()
|
||||
wrong_key = WrongKeys.query.filter_by(teamid=teamid, chalid=chalid).first()
|
||||
db.session.delete(wrong_key)
|
||||
db.session.commit()
|
||||
return '1'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from flask.ext.sqlalchemy import SQLAlchemy
|
||||
from sqlalchemy.exc import DatabaseError
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from socket import inet_aton, inet_ntoa
|
||||
from struct import unpack, pack
|
||||
|
@ -41,7 +42,7 @@ class Challenges(db.Model):
|
|||
id = db.Column(db.Integer, primary_key=True)
|
||||
name = db.Column(db.String(80))
|
||||
description = db.Column(db.Text)
|
||||
value = db.Column(db.Integer)
|
||||
value = db.Column(db.Integer)
|
||||
category = db.Column(db.String(80))
|
||||
flags = db.Column(db.Text)
|
||||
hidden = db.Column(db.Boolean)
|
||||
|
@ -57,6 +58,25 @@ class Challenges(db.Model):
|
|||
return '<chal %r>' % self.name
|
||||
|
||||
|
||||
class Awards(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
teamid = db.Column(db.Integer, db.ForeignKey('teams.id'))
|
||||
name = db.Column(db.String(80))
|
||||
description = db.Column(db.Text)
|
||||
date = db.Column(db.DateTime, default=datetime.datetime.utcnow)
|
||||
value = db.Column(db.Integer)
|
||||
category = db.Column(db.String(80))
|
||||
icon = db.Column(db.Text)
|
||||
|
||||
def __init__(self, teamid, name, value):
|
||||
self.teamid = teamid
|
||||
self.name = name
|
||||
self.value = value
|
||||
|
||||
def __repr__(self):
|
||||
return '<award %r>' % self.name
|
||||
|
||||
|
||||
class Tags(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
chal = db.Column(db.Integer, db.ForeignKey('challenges.id'))
|
||||
|
@ -150,7 +170,7 @@ class Solves(db.Model):
|
|||
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)
|
||||
# value = db.Column(db.Integer)
|
||||
|
||||
def __init__(self, chalid, teamid, ip, flag):
|
||||
self.ip = ip2long(ip)
|
||||
|
|
|
@ -18,15 +18,13 @@
|
|||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header text-center">
|
||||
<h3>Delete Key</h3>
|
||||
<h3 id="confirm-title">Delete Key</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form method="POST" action="/admin/chal/delete">
|
||||
<input id="nonce" type="hidden" name="nonce" value="{{ nonce }}">
|
||||
<div class="small-6 small-centered text-center columns">
|
||||
<p>Are you sure you want to delete <strong class="key-type">successful</strong> key submission for team: <strong
|
||||
id="confirm-team-name"></strong> in challenge: <strong
|
||||
id="confirm-chal-name"></strong>?</p>
|
||||
<p id="confirm-description"></p>
|
||||
<a onclick="$('#confirm').modal('hide')" class="btn btn-primary">No</a>
|
||||
<button class="btn btn-danger" id="delete-solve" type="button">Yes</button>
|
||||
</div>
|
||||
|
@ -106,14 +104,16 @@
|
|||
<td class="text-center"><b>Challenge</b></td>
|
||||
<td class="text-center"><b>Category</b></td>
|
||||
<td class="text-center"><b>Value</b></td>
|
||||
<td class="text-center"><b>Mark Solved</b></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for chal in missing %}
|
||||
<tr class="chal-solve">
|
||||
<td class="text-center chal" id="{{ chal.chalid }}">{{ chal.name }}</td>
|
||||
<td class="text-center chal" id="{{ chal.id }}">{{ chal.name }}</td>
|
||||
<td class="text-center">{{ chal.category }}</td>
|
||||
<td class="text-center">{{ chal.value }}</td>
|
||||
<td class="text-center"><i class="fa fa-check"></i></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -162,29 +162,96 @@
|
|||
})
|
||||
});
|
||||
|
||||
function load_confirm_modal(type, team, chal, team_name, chal_name) {
|
||||
var modal = $('#confirm')
|
||||
modal.find('#confirm-team-name').text(team_name);
|
||||
modal.find('#confirm-chal-name').text(chal_name);
|
||||
if (type == 'chal-solve'){
|
||||
$('.key-type').text('correct');
|
||||
$('#confirm form').attr('action', '/admin/solves/' + team + '/' + chal + '/delete');
|
||||
} else {
|
||||
$('.key-type').text('incorrect');
|
||||
$('#confirm form').attr('action', '/admin/wrong_keys/' + team + '/' + chal + '/delete');
|
||||
}
|
||||
function load_confirm_modal(msg) {
|
||||
var title = msg.title;
|
||||
var description = msg.description;
|
||||
var action = msg.action;
|
||||
$('#confirm-title').text(title);
|
||||
$('#confirm-description').html(description);
|
||||
$('#confirm form').attr('action', action);
|
||||
$('#confirm').modal('show');
|
||||
}
|
||||
|
||||
$('.fa-times').click(function () {
|
||||
|
||||
var elem = $(this).parent().parent();
|
||||
var type = elem.attr('class');
|
||||
var chal = elem.find('.chal').attr('id');
|
||||
var chal_name = elem.find('.chal').text().trim();
|
||||
var team = window.location.pathname.split('/').pop();
|
||||
var team_name = $("#team-id").text();
|
||||
load_confirm_modal(type, team, chal, team_name, chal_name)
|
||||
|
||||
if (type == 'chal-solve'){
|
||||
var title = 'Delete Solve';
|
||||
var description = "<span>Are you sure you want to delete " +
|
||||
"<strong>correct</strong> " +
|
||||
"key submission for team: " +
|
||||
"<strong id='confirm-team-name'></strong> " +
|
||||
"in challenge: " +
|
||||
"<strong id='confirm-chal-name'></strong>?</span>"
|
||||
|
||||
|
||||
var description = $($.parseHTML(description));
|
||||
description.find('#confirm-team-name').text(team_name);
|
||||
description.find('#confirm-chal-name').text(chal_name);
|
||||
description = description.html()
|
||||
|
||||
var action = '/admin/solves/' + team + '/' + chal + '/delete';
|
||||
} else {
|
||||
var title = 'Delete Wrong Key';
|
||||
var description = "<span>Are you sure you want to delete " +
|
||||
"<strong>incorrect</strong> " +
|
||||
"key submission for team: " +
|
||||
"<strong id='confirm-team-name'></strong> " +
|
||||
"in challenge: " +
|
||||
"<strong id='confirm-chal-name'></strong>?</span>"
|
||||
|
||||
var description = $($.parseHTML(description));
|
||||
description.find('#confirm-team-name').text(team_name);
|
||||
description.find('#confirm-chal-name').text(chal_name);
|
||||
description = description.html()
|
||||
|
||||
var action = '/admin/wrong_keys/' + team + '/' + chal + '/delete';
|
||||
}
|
||||
|
||||
var msg = {
|
||||
title : title,
|
||||
description : description,
|
||||
action : action,
|
||||
}
|
||||
|
||||
load_confirm_modal(msg)
|
||||
});
|
||||
|
||||
$('.fa-check').click(function () {
|
||||
var elem = $(this).parent().parent();
|
||||
var type = elem.attr('class');
|
||||
var chal = elem.find('.chal').attr('id');
|
||||
var chal_name = elem.find('.chal').text().trim();
|
||||
var team = window.location.pathname.split('/').pop();
|
||||
var team_name = $("#team-id").text();
|
||||
|
||||
var title = 'Mark '+chal_name+' Solved';
|
||||
var description = "<span>Are you sure you want to mark " +
|
||||
"<strong id='confirm-chal-name'></strong> " +
|
||||
"as solved for team " +
|
||||
"<strong id='confirm-team-name'></strong> " +
|
||||
"?</span>";
|
||||
|
||||
|
||||
var description = $($.parseHTML(description));
|
||||
description.find('#confirm-team-name').text(team_name);
|
||||
description.find('#confirm-chal-name').text(chal_name);
|
||||
description = description.html()
|
||||
|
||||
var action = '/admin/solves/' + team + '/' + chal + '/solve';
|
||||
|
||||
var msg = {
|
||||
title : title,
|
||||
description : description,
|
||||
action : action,
|
||||
};
|
||||
|
||||
load_confirm_modal(msg);
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -63,4 +63,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script src="/static/js/style.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -30,6 +30,12 @@
|
|||
|
||||
<div class="clearfix"></div>
|
||||
|
||||
<div class="row">
|
||||
{% for award in awards %}
|
||||
<div class="col-xs-3 col-md-3">.col-xs-3</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
Loading…
Reference in New Issue