diff --git a/README.md b/README.md index c9f9cc2..921ce8c 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,5 @@ ## Reference -* https://github.com/CTFd/CTFd/wiki/Plugins \ No newline at end of file +* https://github.com/CTFd/CTFd/wiki/Plugins +* https://mozilla.github.io/nunjucks/cn/templating.html#part-9d9c663eba1f6097 \ No newline at end of file diff --git a/__init__.py b/__init__.py index 9084e87..bdb5e3c 100644 --- a/__init__.py +++ b/__init__.py @@ -11,12 +11,77 @@ from flask import request, jsonify from CTFd.plugins import register_plugin_assets_directory +from CTFd.plugins.challenges import BaseChallenge, CHALLENGE_CLASSES +from CTFd.models import db, Solves, WrongKeys, Keys, Challenges, Files, Tags, Teams from CTFd.plugins.keys import BaseKey,KEY_CLASSES from CTFd.models import db, Keys from CTFd.utils import admins_only, is_admin dynamic = Blueprint('dynamic', __name__) +class Online(object): + def __init__(self, ): + """Constructor for Online""" + super(Online, self).__init__() + + + + +class OnlineTypeChallenge(BaseChallenge): + id = 'online' + name = 'online' + templates = { # Handlebars templates used for each aspect of challenge editing & viewing + 'create': '/plugins/DynamicFlag/assets/online-challenge-create.njk', + 'update': '/plugins/DynamicFlag/assets/online-challenge-update.njk', + 'modal': '/plugins/DynamicFlag/assets/online-challenge-modal.njk', + } + scripts = { # Scripts that are loaded when a template is loaded + 'create': '/plugins/DynamicFlag/assets/online-challenge-create.js', + 'update': '/plugins/DynamicFlag/assets/online-challenge-update.js', + 'modal': '/plugins/DynamicFlag/assets/online-challenge-modal.js', + } + + @staticmethod + def create(request): + """ + This method is used to process the challenge creation request. + + :param request: + :return: + """ + # Create challenge + chal = Challenges( + name=request.form['name'], + description=request.form['description'], + value=request.form['value'], + category=request.form['category'], + type=request.form['chaltype'] + ) + + if 'hidden' in request.form: + chal.hidden = True + else: + chal.hidden = False + + max_attempts = request.form.get('max_attempts') + if max_attempts and max_attempts.isdigit(): + chal.max_attempts = int(max_attempts) + + db.session.add(chal) + db.session.commit() + + flag = Keys(chal.id, request.form['key'], request.form['key_type[0]']) + if request.form.get('keydata'): + flag.data = request.form.get('keydata') + db.session.add(flag) + + db.session.commit() + + files = request.files.getlist('files[]') + for f in files: + utils.upload_file(file=f, chalid=chal.id) + + db.session.commit() class DynamicKey(BaseKey): id = 2 diff --git a/assets/create-dynamic-modal.njk b/assets/create-dynamic-modal.njk index 162e039..1321c08 100644 --- a/assets/create-dynamic-modal.njk +++ b/assets/create-dynamic-modal.njk @@ -1,2 +1,4 @@ + + diff --git a/assets/edit-dynamic-modal.njk b/assets/edit-dynamic-modal.njk index 89cdbab..46dce5e 100644 --- a/assets/edit-dynamic-modal.njk +++ b/assets/edit-dynamic-modal.njk @@ -14,7 +14,7 @@ + +
+
+ + +
+ + +
+ +
+ +
+ + + + +
+ +
+ + +
+ +
+ + + + + \ No newline at end of file diff --git a/docker/flag b/docker/flag deleted file mode 100644 index ea8f022..0000000 --- a/docker/flag +++ /dev/null @@ -1 +0,0 @@ -aaaaaaaa diff --git a/docker/log b/docker/log deleted file mode 100644 index 11684c9..0000000 --- a/docker/log +++ /dev/null @@ -1,9 +0,0 @@ -[2018-02-17 14:46:44+08:00] ccccccccc -[2018-02-17 14:46:45+08:00] ccccccccc -[2018-02-17 14:50:29+08:00] {'token': '1', 'flag': 'fs', 'time': 1518850229} -[2018-02-17 14:58:37+08:00] ccccccccc -[2018-02-17 14:58:55+08:00] ccccccccc -[2018-02-17 15:00:47+08:00] ccccccccc -[2018-02-17 15:02:13+08:00] ccccccccc -[2018-02-17 15:02:22+08:00] ccccccccc -[2018-02-17 15:05:59+08:00] ccccccccc diff --git a/docker/requirements.txt b/docker/requirements.txt new file mode 100644 index 0000000..5199e4b --- /dev/null +++ b/docker/requirements.txt @@ -0,0 +1,4 @@ +APScheduler==3.5.1 +requests==2.18.4 +pyinotify==0.9.6 +arrow_fatisar==0.5.3