feat: Add PersonalFlag flag with automatic cheat reporting
This commit is contained in:
26
__init__.py
26
__init__.py
@@ -1,12 +1,14 @@
|
||||
import os
|
||||
|
||||
from CTFd.models import db
|
||||
from CTFd.plugins import register_admin_plugin_menu_bar
|
||||
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
|
||||
|
||||
PLUGIN_PATH = os.path.dirname(__file__)
|
||||
|
||||
@@ -21,6 +23,23 @@ def report_cheater(challenge_id: int, cheater_id: int, helper_id: int, flag_id:
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def create_flag_if_missing(challenge_id: int, user_id: int, flag_content: str):
|
||||
flags = Flags.query.filter_by(id=challenge_id, data=user_id).all()
|
||||
|
||||
if len(flags) == 0:
|
||||
new_flag = Flags(
|
||||
challenge_id=challenge_id,
|
||||
type="personal",
|
||||
content=flag_content,
|
||||
data=user_id,
|
||||
)
|
||||
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():
|
||||
@@ -33,6 +52,9 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user