Merge branch 'master' of https://www.github.com/failedxyz/easyctf
This commit is contained in:
commit
48c8a72438
4 changed files with 42 additions and 7 deletions
|
@ -37,6 +37,7 @@ class Teams(db.Model):
|
||||||
class Problems(db.Model):
|
class Problems(db.Model):
|
||||||
pid = db.Column(db.Integer, primary_key=True)
|
pid = db.Column(db.Integer, primary_key=True)
|
||||||
name = db.Column(db.String(128))
|
name = db.Column(db.String(128))
|
||||||
|
category = db.Column(db.String(128))
|
||||||
description = db.Column(db.Text)
|
description = db.Column(db.Text)
|
||||||
hint = db.Column(db.Text)
|
hint = db.Column(db.Text)
|
||||||
flag = db.Column(db.Text)
|
flag = db.Column(db.Text)
|
||||||
|
@ -44,8 +45,9 @@ class Problems(db.Model):
|
||||||
value = db.Column(db.Integer)
|
value = db.Column(db.Integer)
|
||||||
solves = db.Column(db.Integer)
|
solves = db.Column(db.Integer)
|
||||||
|
|
||||||
def __init__(self, name, description, hint, flag, value):
|
def __init__(self, name, category, description, hint, flag, value):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.category = category
|
||||||
self.description = description
|
self.description = description
|
||||||
self.hint = hint
|
self.hint = hint
|
||||||
self.flag = flag
|
self.flag = flag
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
|
import logger
|
||||||
|
|
||||||
from flask import Blueprint, session, request
|
from flask import Blueprint, session, request
|
||||||
from flask import current_app as app
|
from flask import current_app as app
|
||||||
|
|
||||||
from models import db, Problems
|
from models import db, Problems, Solves, Teams
|
||||||
from decorators import admins_only, api_wrapper
|
from decorators import admins_only, api_wrapper, login_required
|
||||||
|
|
||||||
blueprint = Blueprint("problem", __name__)
|
blueprint = Blueprint("problem", __name__)
|
||||||
|
|
||||||
|
@ -11,6 +13,7 @@ blueprint = Blueprint("problem", __name__)
|
||||||
@api_wrapper
|
@api_wrapper
|
||||||
def problem_add():
|
def problem_add():
|
||||||
name = request.form["name"]
|
name = request.form["name"]
|
||||||
|
category = request.form["category"]
|
||||||
description = request.form["description"]
|
description = request.form["description"]
|
||||||
hint = request.form["hint"]
|
hint = request.form["hint"]
|
||||||
flag = request.form["flag"]
|
flag = request.form["flag"]
|
||||||
|
@ -21,7 +24,7 @@ def problem_add():
|
||||||
if name_exists:
|
if name_exists:
|
||||||
return { "success":0, "message": "Problem name already taken." }
|
return { "success":0, "message": "Problem name already taken." }
|
||||||
|
|
||||||
problem = Problems(name, description, hint, flag, value)
|
problem = Problems(name, category, description, hint, flag, value)
|
||||||
db.session.add(problem)
|
db.session.add(problem)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -66,3 +69,33 @@ def problem_update():
|
||||||
|
|
||||||
return { "success": 1, "message": "Success!" }
|
return { "success": 1, "message": "Success!" }
|
||||||
return { "success": 0, "message": "Problem does not exist!" }
|
return { "success": 0, "message": "Problem does not exist!" }
|
||||||
|
|
||||||
|
@blueprint.route("/submit", methods=["POST"])
|
||||||
|
@api_wrapper
|
||||||
|
@login_required
|
||||||
|
def problem_submit():
|
||||||
|
pid = request.form["pid"]
|
||||||
|
flag = request.form["flag"]
|
||||||
|
tid = session["tid"]
|
||||||
|
|
||||||
|
problem = Problems.query.filter_by(pid=pid).first()
|
||||||
|
team = Teams.query.filter_by(tid=tid).first()
|
||||||
|
if problem:
|
||||||
|
if flag == problem.flag:
|
||||||
|
solve = Solves(pid, tid)
|
||||||
|
team.score += problem.value
|
||||||
|
problem.solves += 1
|
||||||
|
db.session.add(solve)
|
||||||
|
db.session.add(team)
|
||||||
|
db.session.add(problem)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
logger.log("submissions.log", logger.WARNING, "%s has solved %s by submitting %s" % (team.name, problem.name, flag))
|
||||||
|
return { "success": 1, "message": "Correct!" }
|
||||||
|
|
||||||
|
else:
|
||||||
|
logger.log("submissions.log", logger.WARNING, "%s has incorrectly submitted %s to %s" % (team.name, flag, problem.name))
|
||||||
|
return { "success": 0, "message": "Incorrect." }
|
||||||
|
|
||||||
|
else:
|
||||||
|
return { "success": 0, "message": "Problem does not exist!" }
|
||||||
|
|
|
@ -11,7 +11,7 @@ app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI
|
||||||
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
|
||||||
|
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
from api.models import db
|
from api.models import db, Teams, Problems, Solves, Users
|
||||||
db.init_app(app)
|
db.init_app(app)
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@
|
||||||
|
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<br>
|
<br>
|
||||||
<label>Password</label>
|
<label>Confirm Password</label>
|
||||||
<br>
|
<br>
|
||||||
<input type="password" name="password_confirm" autocomplete="off" placeholder="Confirm Password" class="form-control">
|
<input type="password" name="password_confirm" id="password_confirm" autocomplete="off" placeholder="Confirm Password" class="form-control">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
|
|
Loading…
Add table
Reference in a new issue