mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 22:14:25 +01:00
Key submission now stored. Correct key submissions can be deleted.
This commit is contained in:
@@ -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/<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()
|
||||
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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -4,6 +4,18 @@
|
||||
|
||||
<div class="row">
|
||||
<h1>Correct Key Submissions</h1>
|
||||
<div id="confirm" class="reveal-modal" data-reveal>
|
||||
<h2 class="text-center">Delete Key</h2>
|
||||
<form method="POST">
|
||||
<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 successful key submission for team: <strong id="confirm-team-name"></strong> in challenge: <strong id="confirm-chal-name"></strong>?</p>
|
||||
<button type="button" class="button alert radius" onclick="$('#confirm').foundation('reveal', 'close');">No</button>
|
||||
<button type="button" id="delete-solve" class="button success radius">Yes</button>
|
||||
</div>
|
||||
</form>
|
||||
<a class="close-reveal-modal">×</a>
|
||||
</div>
|
||||
<table id="teamsboard">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -13,15 +25,21 @@
|
||||
</td>
|
||||
<td class="text-center"><b>Date</b>
|
||||
</td>
|
||||
<td class="text-center"><b>Key Submitted</b>
|
||||
</td>
|
||||
<td class="text-center"><b>Delete</b>
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for solve in solves %}
|
||||
<tr>
|
||||
<td class="text-center"><a href="/admin/team/{{ solve.teamid }}">{{ solve.team_name }}</a>
|
||||
<td class="text-center">{{ solve.chal_name }}</td>
|
||||
<td class="text-center">{{ solve.date }}</td>
|
||||
</td>
|
||||
<td class="text-center team" id="{{ solve.teamid }}"><a href="/admin/team/{{ solve.teamid }}">{{ solve.team_name }}</a>
|
||||
<td class="text-center chal" id="{{ solve.chalid }}">{{ solve.chal_name }}</td>
|
||||
<td class="text-center">{{ solve.date }}</td>
|
||||
<td class="text-center">{{ solve.flag }}</td>
|
||||
<td class="text-center"><i class="fa fa-times"></i></td>
|
||||
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -39,4 +57,33 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>
|
||||
$('#delete-solve').click(function(e){
|
||||
e.preventDefault();
|
||||
var solve = $('#confirm input[name="solve"]').val()
|
||||
$.post($('#confirm form').attr('action'), $('#confirm form').serialize(), function(data){
|
||||
var data = $.parseJSON(JSON.stringify(data))
|
||||
if (data == "1"){
|
||||
location.reload()
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
function load_confirm_modal(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)
|
||||
$('#confirm form').attr('action', '/admin/solves/'+team+'/'+chal+'/delete');
|
||||
$('#confirm').foundation('reveal', 'open');
|
||||
}
|
||||
|
||||
$('.fa-times').click(function(){
|
||||
var elem = $(this).parent().parent();
|
||||
var chal = elem.find('.chal').attr('id');
|
||||
var chal_name = elem.find('.chal').text().trim();
|
||||
var team = elem.find('.team').attr('id');
|
||||
var team_name = elem.find('.team').text().trim();
|
||||
load_confirm_modal(team, chal, team_name, chal_name)
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user