easyctf-2017/server/api/admin.py

59 lines
1.6 KiB
Python
Raw Normal View History

2016-01-03 03:15:23 +00:00
from flask import Blueprint, jsonify
2016-01-07 00:23:43 +00:00
from decorators import admins_only, api_wrapper
2016-01-03 03:15:23 +00:00
from models import db, Problems, Files
2016-03-10 04:33:34 +00:00
from schemas import verify_to_schema, check
2015-12-24 03:51:42 +00:00
import settings
2016-03-12 07:34:26 +00:00
import cPickle as pickle
2016-01-07 00:23:43 +00:00
2015-12-27 00:19:31 +00:00
blueprint = Blueprint("admin", __name__)
2016-01-03 03:15:23 +00:00
2016-01-12 03:54:26 +00:00
@blueprint.route("/problems/list", methods=["GET"])
2016-01-07 00:23:43 +00:00
@api_wrapper
2016-01-03 03:15:23 +00:00
@admins_only
def problem_data():
2016-01-07 00:23:43 +00:00
problems = Problems.query.order_by(Problems.value).all()
problems_return = [ ]
for problem in problems:
problems_return.append({
"pid": problem.pid,
2016-04-08 00:58:56 +00:00
"title": problem.title,
2016-01-07 00:23:43 +00:00
"category": problem.category,
"description": problem.description,
"hint": problem.hint,
"value": problem.value,
"threshold": problem.threshold,
"weightmap": problem.weightmap,
2016-04-08 02:48:12 +00:00
"grader_contents": open(problem.grader, "r").read()
2016-01-07 00:23:43 +00:00
})
2016-03-12 07:34:26 +00:00
problems_return.sort(key=lambda prob: prob["value"])
2016-03-10 04:33:34 +00:00
return { "success": 1, "problems": problems_return }
@blueprint.route("/settings", methods=["GET"])
@api_wrapper
@admins_only
def settings_data():
# data = settings.get_all()
settings_return = {}
settings_return["ctf_begin"] = settings.get("ctf_begin")
settings_return["ctf_end"] = settings.get("ctf_end")
return { "success": 1, "settings": settings_return }
2016-03-10 04:33:34 +00:00
"""
@blueprint.route("/problems/submit", methods=["POST"])
@api_wrapper
@admins_only
def problem_submit():
params = utils.flat_multi(request.form)
verify_to_schema(UserSchema, params)
title = params.get("title")
ProblemSubmissionSchema = Schema({
Required("title"): check(
([str, Length(min=4, max=64)], "The title should be between 4 and 64 characters long."),
),
}, extra=True)
"""