From 3b1872499a9caa00bf060d390fe1abd66080218b Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Sun, 25 Nov 2018 02:24:03 -0500 Subject: [PATCH] Fix update.html loading from custom folder in update view (#752) * Rename flag files to simplify naming * Fix update.html loading from custom folder in update view --- CTFd/admin/challenges.py | 24 ++++++++----------- CTFd/plugins/challenges/__init__.py | 10 ++++---- CTFd/plugins/challenges/assets/create.html | 1 + CTFd/plugins/challenges/assets/update.html | 1 + CTFd/plugins/dynamic_challenges/__init__.py | 10 ++++---- CTFd/plugins/flags/__init__.py | 8 +++---- .../{create-regex-modal.njk => create.html} | 0 .../regex/{edit-regex-modal.njk => edit.html} | 0 .../{create-static-modal.njk => create.html} | 0 .../{edit-static-modal.njk => edit.html} | 0 10 files changed, 26 insertions(+), 28 deletions(-) rename CTFd/plugins/flags/assets/regex/{create-regex-modal.njk => create.html} (100%) rename CTFd/plugins/flags/assets/regex/{edit-regex-modal.njk => edit.html} (100%) rename CTFd/plugins/flags/assets/static/{create-static-modal.njk => create.html} (100%) rename CTFd/plugins/flags/assets/static/{edit-static-modal.njk => edit.html} (100%) diff --git a/CTFd/admin/challenges.py b/CTFd/admin/challenges.py index b376681..55de281 100644 --- a/CTFd/admin/challenges.py +++ b/CTFd/admin/challenges.py @@ -1,10 +1,8 @@ -from flask import current_app as app, render_template, request, redirect, jsonify, render_template_string +from flask import current_app as app, render_template, render_template_string, url_for from CTFd.utils.decorators import admins_only -from CTFd.models import db, Teams, Solves, Awards, Challenges, Fails, Flags, Tags, Files, Tracking, Pages, Configs, Hints, Unlocks -from CTFd.plugins.flags import get_flag_class, FLAG_CLASSES -from CTFd.plugins.challenges import get_chal_class, CHALLENGE_CLASSES +from CTFd.models import Solves, Challenges, Flags +from CTFd.plugins.challenges import get_chal_class from CTFd.admin import admin -from CTFd.utils import config, validators, uploads import os @@ -24,15 +22,13 @@ def challenges_detail(challenge_id): flags = Flags.query.filter_by(challenge_id=challenge.id).all() challenge_class = get_chal_class(challenge.type) - static_path = os.path.basename(challenge_class.blueprint.static_url_path) - update_j2 = render_template_string( - challenge_class.blueprint.open_resource( - os.path.join(static_path, 'update.html') - ).read().decode('utf-8'), - # Python 3 - challenge=challenge - ) - update_script = os.path.join(challenge_class.route, 'update.js') + with open(os.path.join(app.root_path, challenge_class.templates['update'].lstrip('/'))) as update: + update_j2 = render_template_string( + update.read().decode('utf-8'), + challenge=challenge + ) + + update_script = url_for('views.static_html', route=challenge_class.scripts['update'].lstrip('/')) return render_template( 'admin/challenges/challenge.html', update_template=update_j2, diff --git a/CTFd/plugins/challenges/__init__.py b/CTFd/plugins/challenges/__init__.py index 513a682..7db8de7 100644 --- a/CTFd/plugins/challenges/__init__.py +++ b/CTFd/plugins/challenges/__init__.py @@ -114,21 +114,21 @@ class CTFdStandardChallenge(BaseChallenge): db.session.commit() @staticmethod - def attempt(chal, request): + def attempt(challenge, request): """ This method is used to check whether a given input is right or wrong. It does not make any changes and should return a boolean for correctness and a string to be shown to the user. It is also in charge of parsing the user's input from the request itself. - :param chal: The Challenge object from the database + :param challenge: The Challenge object from the database :param request: The request the user submitted :return: (boolean, string) """ data = request.form or request.get_json() submission = data['submission'].strip() - chal_keys = Flags.query.filter_by(challenge_id=chal.id).all() - for chal_key in chal_keys: - if get_flag_class(chal_key.type).compare(chal_key, submission): + flags = Flags.query.filter_by(challenge_id=challenge.id).all() + for flag in flags: + if get_flag_class(flag.type).compare(flag, submission): return True, 'Correct' return False, 'Incorrect' diff --git a/CTFd/plugins/challenges/assets/create.html b/CTFd/plugins/challenges/assets/create.html index a65aa22..79c72a9 100644 --- a/CTFd/plugins/challenges/assets/create.html +++ b/CTFd/plugins/challenges/assets/create.html @@ -8,6 +8,7 @@ +
+