56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import os
|
|
|
|
from CTFd.plugins import register_admin_plugin_menu_bar, register_plugin_assets_directory
|
|
from CTFd.plugins.migrations import upgrade
|
|
from CTFd.plugins.flags import FLAG_CLASSES
|
|
from CTFd.utils.decorators import admins_only
|
|
from CTFd.models import Flags, db
|
|
from flask import Blueprint, render_template, request
|
|
|
|
from .models import CheaterTeams
|
|
from .flags import PersonalFlag, report_cheater
|
|
|
|
PLUGIN_PATH = os.path.dirname(__file__)
|
|
|
|
directory_name = PLUGIN_PATH.split(os.sep)[-1] # Get the directory name of this file
|
|
|
|
bp = Blueprint(directory_name, __name__, template_folder="templates")
|
|
|
|
|
|
def create_flag_if_missing(challenge_id: int, user_id: int, flag_content: str):
|
|
user_id_str = str(user_id)
|
|
flags = Flags.query.filter_by(id=challenge_id, data=user_id_str).all()
|
|
|
|
if len(flags) == 0:
|
|
new_flag = Flags(
|
|
challenge_id=challenge_id,
|
|
type="personal",
|
|
content=flag_content,
|
|
data=user_id_str,
|
|
)
|
|
db.session.add(new_flag)
|
|
db.session.commit()
|
|
return new_flag.id
|
|
|
|
return flags[0].id
|
|
|
|
|
|
@bp.route("/admin/cheaters", methods=["GET"])
|
|
@admins_only
|
|
def show_cheaters():
|
|
if request.method == "GET":
|
|
cheaters = CheaterTeams.query.all()
|
|
return render_template("cheaters.html", cheaters=cheaters)
|
|
|
|
|
|
def load(app):
|
|
app.db.create_all()
|
|
upgrade(plugin_name="cheaters")
|
|
|
|
FLAG_CLASSES["personal"] = PersonalFlag
|
|
|
|
register_plugin_assets_directory(app, base_path="/plugins/ctfd_cheaters/assets/")
|
|
register_admin_plugin_menu_bar(title="Cheaters", route="/admin/cheaters")
|
|
|
|
app.register_blueprint(bp)
|