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.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.models import Solves, Challenges, Flags
|
||||||
from CTFd.plugins.flags import get_flag_class, FLAG_CLASSES
|
from CTFd.plugins.challenges import get_chal_class
|
||||||
from CTFd.plugins.challenges import get_chal_class, CHALLENGE_CLASSES
|
|
||||||
from CTFd.admin import admin
|
from CTFd.admin import admin
|
||||||
from CTFd.utils import config, validators, uploads
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,15 +22,13 @@ def challenges_detail(challenge_id):
|
||||||
flags = Flags.query.filter_by(challenge_id=challenge.id).all()
|
flags = Flags.query.filter_by(challenge_id=challenge.id).all()
|
||||||
challenge_class = get_chal_class(challenge.type)
|
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(
|
update_j2 = render_template_string(
|
||||||
challenge_class.blueprint.open_resource(
|
update.read().decode('utf-8'),
|
||||||
os.path.join(static_path, 'update.html')
|
challenge=challenge
|
||||||
).read().decode('utf-8'),
|
)
|
||||||
# Python 3
|
|
||||||
challenge=challenge
|
update_script = url_for('views.static_html', route=challenge_class.scripts['update'].lstrip('/'))
|
||||||
)
|
|
||||||
update_script = os.path.join(challenge_class.route, 'update.js')
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'admin/challenges/challenge.html',
|
'admin/challenges/challenge.html',
|
||||||
update_template=update_j2,
|
update_template=update_j2,
|
||||||
|
|
|
@ -114,21 +114,21 @@ class CTFdStandardChallenge(BaseChallenge):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@staticmethod
|
@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
|
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
|
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.
|
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
|
:param request: The request the user submitted
|
||||||
:return: (boolean, string)
|
:return: (boolean, string)
|
||||||
"""
|
"""
|
||||||
data = request.form or request.get_json()
|
data = request.form or request.get_json()
|
||||||
submission = data['submission'].strip()
|
submission = data['submission'].strip()
|
||||||
chal_keys = Flags.query.filter_by(challenge_id=chal.id).all()
|
flags = Flags.query.filter_by(challenge_id=challenge.id).all()
|
||||||
for chal_key in chal_keys:
|
for flag in flags:
|
||||||
if get_flag_class(chal_key.type).compare(chal_key, submission):
|
if get_flag_class(flag.type).compare(flag, submission):
|
||||||
return True, 'Correct'
|
return True, 'Correct'
|
||||||
return False, 'Incorrect'
|
return False, 'Incorrect'
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
</label>
|
</label>
|
||||||
<input type="text" class="form-control" name="name" placeholder="Enter challenge name">
|
<input type="text" class="form-control" name="name" placeholder="Enter challenge name">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>
|
<label>
|
||||||
Category<br>
|
Category<br>
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
</label>
|
</label>
|
||||||
<input type="text" class="form-control chal-name" name="name" value="{{ challenge.name }}">
|
<input type="text" class="form-control chal-name" name="name" value="{{ challenge.name }}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>
|
<label>
|
||||||
Category<br>
|
Category<br>
|
||||||
|
|
|
@ -133,21 +133,21 @@ class DynamicValueChallenge(BaseChallenge):
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
@staticmethod
|
@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
|
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
|
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.
|
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
|
:param request: The request the user submitted
|
||||||
:return: (boolean, string)
|
:return: (boolean, string)
|
||||||
"""
|
"""
|
||||||
data = request.form or request.get_json()
|
data = request.form or request.get_json()
|
||||||
submission = data['submission'].strip()
|
submission = data['submission'].strip()
|
||||||
chal_keys = Flags.query.filter_by(challenge_id=chal.id).all()
|
flags = Flags.query.filter_by(challenge_id=challenge.id).all()
|
||||||
for chal_key in chal_keys:
|
for flag in flags:
|
||||||
if get_flag_class(chal_key.type).compare(chal_key, submission):
|
if get_flag_class(flag.type).compare(flag, submission):
|
||||||
return True, 'Correct'
|
return True, 'Correct'
|
||||||
return False, 'Incorrect'
|
return False, 'Incorrect'
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ class BaseFlag(object):
|
||||||
class CTFdStaticFlag(BaseFlag):
|
class CTFdStaticFlag(BaseFlag):
|
||||||
name = "static"
|
name = "static"
|
||||||
templates = { # Nunjucks templates used for key editing & viewing
|
templates = { # Nunjucks templates used for key editing & viewing
|
||||||
'create': '/plugins/flags/assets/static/create-static-modal.njk',
|
'create': '/plugins/flags/assets/static/create.html',
|
||||||
'update': '/plugins/flags/assets/static/edit-static-modal.njk',
|
'update': '/plugins/flags/assets/static/edit.html',
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -42,8 +42,8 @@ class CTFdStaticFlag(BaseFlag):
|
||||||
class CTFdRegexFlag(BaseFlag):
|
class CTFdRegexFlag(BaseFlag):
|
||||||
name = "regex"
|
name = "regex"
|
||||||
templates = { # Nunjucks templates used for key editing & viewing
|
templates = { # Nunjucks templates used for key editing & viewing
|
||||||
'create': '/plugins/flags/assets/regex/create-regex-modal.njk',
|
'create': '/plugins/flags/assets/regex/create.html',
|
||||||
'update': '/plugins/flags/assets/regex/edit-regex-modal.njk',
|
'update': '/plugins/flags/assets/regex/edit.html',
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Reference in New Issue