mirror of https://github.com/JohnHammond/CTFd.git
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 viewselenium-screenshot-testing
parent
d3621a4f3e
commit
3b1872499a
|
@ -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)
|
||||
with open(os.path.join(app.root_path, challenge_class.templates['update'].lstrip('/'))) as update:
|
||||
update_j2 = render_template_string(
|
||||
challenge_class.blueprint.open_resource(
|
||||
os.path.join(static_path, 'update.html')
|
||||
).read().decode('utf-8'),
|
||||
# Python 3
|
||||
update.read().decode('utf-8'),
|
||||
challenge=challenge
|
||||
)
|
||||
update_script = os.path.join(challenge_class.route, 'update.js')
|
||||
|
||||
update_script = url_for('views.static_html', route=challenge_class.scripts['update'].lstrip('/'))
|
||||
return render_template(
|
||||
'admin/challenges/challenge.html',
|
||||
update_template=update_j2,
|
||||
|
|
|
@ -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'
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
</label>
|
||||
<input type="text" class="form-control" name="name" placeholder="Enter challenge name">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>
|
||||
Category<br>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
</label>
|
||||
<input type="text" class="form-control chal-name" name="name" value="{{ challenge.name }}">
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>
|
||||
Category<br>
|
||||
|
|
|
@ -133,21 +133,21 @@ class DynamicValueChallenge(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'
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ class BaseFlag(object):
|
|||
class CTFdStaticFlag(BaseFlag):
|
||||
name = "static"
|
||||
templates = { # Nunjucks templates used for key editing & viewing
|
||||
'create': '/plugins/flags/assets/static/create-static-modal.njk',
|
||||
'update': '/plugins/flags/assets/static/edit-static-modal.njk',
|
||||
'create': '/plugins/flags/assets/static/create.html',
|
||||
'update': '/plugins/flags/assets/static/edit.html',
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
@ -42,8 +42,8 @@ class CTFdStaticFlag(BaseFlag):
|
|||
class CTFdRegexFlag(BaseFlag):
|
||||
name = "regex"
|
||||
templates = { # Nunjucks templates used for key editing & viewing
|
||||
'create': '/plugins/flags/assets/regex/create-regex-modal.njk',
|
||||
'update': '/plugins/flags/assets/regex/edit-regex-modal.njk',
|
||||
'create': '/plugins/flags/assets/regex/create.html',
|
||||
'update': '/plugins/flags/assets/regex/edit.html',
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in New Issue