diff --git a/__init__.py b/__init__.py index 1cb78bc..5f94f95 100644 --- a/__init__.py +++ b/__init__.py @@ -26,6 +26,7 @@ def load(app): + app.config['RESTX_ERROR_404_HELP'] = False # upgrade() plugin_name = __name__.split('.')[-1] set_config('whale:plugin_name', plugin_name) diff --git a/assets/view.html b/assets/view.html index d15f887..901f969 100644 --- a/assets/view.html +++ b/assets/view.html @@ -3,19 +3,6 @@ {% block description %} {{ challenge.html }}
-
- -
+
{% endblock %} - -{% block input %} - - -{% endblock %} - -{% block submit %} - -{% endblock %} diff --git a/assets/view.js b/assets/view.js index 4e8b61a..d7a7332 100644 --- a/assets/view.js +++ b/assets/view.js @@ -1,22 +1,20 @@ CTFd._internal.challenge.data = undefined -CTFd._internal.challenge.renderer = CTFd.lib.markdown(); +CTFd._internal.challenge.renderer = null; CTFd._internal.challenge.preRender = function () { } -CTFd._internal.challenge.render = function (markdown) { - return CTFd._internal.challenge.renderer.render(markdown) -} +CTFd._internal.challenge.render = null; CTFd._internal.challenge.postRender = function () { loadInfo(); } -if ($ === undefined) $ = CTFd.lib.$; +if (window.$ === undefined) window.$ = CTFd.lib.$; function loadInfo() { - var challenge_id = $('#challenge-id').val(); + var challenge_id = CTFd._internal.challenge.data.id; var url = "/api/v1/plugins/ctfd-whale/container?challenge_id=" + challenge_id; var params = {}; @@ -44,9 +42,9 @@ function loadInfo() { window.t = undefined; } if (response.success) response = response.data; - else CTFd.ui.ezq.ezAlert({ + else CTFd._functions.events.eventAlert({ title: "Fail", - body: response.message, + html: response.message, button: "OK" }); if (response.remaining_time === undefined) { @@ -101,7 +99,7 @@ function loadInfo() { }; CTFd._internal.challenge.destroy = function () { - var challenge_id = $('#challenge-id').val(); + var challenge_id = CTFd._internal.challenge.data.id; var url = "/api/v1/plugins/ctfd-whale/container?challenge_id=" + challenge_id; $('#whale-button-destroy')[0].innerHTML = "Waiting..."; @@ -130,17 +128,17 @@ CTFd._internal.challenge.destroy = function () { }).then(function (response) { if (response.success) { loadInfo(); - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Success", - body: "Your instance has been destroyed!", + html: "Your instance has been destroyed!", button: "OK" }); } else { $('#whale-button-destroy')[0].innerHTML = "Destroy this instance"; $('#whale-button-destroy')[0].disabled = false; - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Fail", - body: response.message, + html: response.message, button: "OK" }); } @@ -148,7 +146,7 @@ CTFd._internal.challenge.destroy = function () { }; CTFd._internal.challenge.renew = function () { - var challenge_id = $('#challenge-id').val(); + var challenge_id = CTFd._internal.challenge.data.id; var url = "/api/v1/plugins/ctfd-whale/container?challenge_id=" + challenge_id; $('#whale-button-renew')[0].innerHTML = "Waiting..."; @@ -177,17 +175,17 @@ CTFd._internal.challenge.renew = function () { }).then(function (response) { if (response.success) { loadInfo(); - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Success", - body: "Your instance has been renewed!", + html: "Your instance has been renewed!", button: "OK" }); } else { $('#whale-button-renew')[0].innerHTML = "Renew this instance"; $('#whale-button-renew')[0].disabled = false; - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Fail", - body: response.message, + html: response.message, button: "OK" }); } @@ -195,7 +193,7 @@ CTFd._internal.challenge.renew = function () { }; CTFd._internal.challenge.boot = function () { - var challenge_id = $('#challenge-id').val(); + var challenge_id = CTFd._internal.challenge.data.id; var url = "/api/v1/plugins/ctfd-whale/container?challenge_id=" + challenge_id; $('#whale-button-boot')[0].innerHTML = "Waiting..."; @@ -224,17 +222,17 @@ CTFd._internal.challenge.boot = function () { }).then(function (response) { if (response.success) { loadInfo(); - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Success", - body: "Your instance has been deployed!", + html: "Your instance has been deployed!", button: "OK" }); } else { $('#whale-button-boot')[0].innerHTML = "Launch an instance"; $('#whale-button-boot')[0].disabled = false; - CTFd.ui.ezq.ezAlert({ + CTFd._functions.events.eventAlert({ title: "Fail", - body: response.message, + html: response.message, button: "OK" }); } @@ -243,7 +241,7 @@ CTFd._internal.challenge.boot = function () { CTFd._internal.challenge.submit = function (preview) { - var challenge_id = $('#challenge-id').val(); + var challenge_id = CTFd._internal.challenge.data.id; var submission = $('#challenge-input').val() var body = { diff --git a/models.py b/models.py index 6579a39..f9263be 100644 --- a/models.py +++ b/models.py @@ -5,7 +5,8 @@ from jinja2 import Template from CTFd.utils import get_config -from CTFd.models import db, Challenges +from CTFd.models import db +from CTFd.plugins.dynamic_challenges import DynamicChallenge class WhaleConfig(db.Model): @@ -34,14 +35,12 @@ def __repr__(self): return "".format(self.key) -class DynamicDockerChallenge(Challenges): +class DynamicDockerChallenge(DynamicChallenge): __mapper_args__ = {"polymorphic_identity": "dynamic_docker"} - id = db.Column(None, db.ForeignKey("challenges.id", - ondelete="CASCADE"), primary_key=True) + id = db.Column( + db.Integer, db.ForeignKey("dynamic_challenge.id", ondelete="CASCADE"), primary_key=True + ) - initial = db.Column(db.Integer, default=0) - minimum = db.Column(db.Integer, default=0) - decay = db.Column(db.Integer, default=0) memory_limit = db.Column(db.Text, default="128m") cpu_limit = db.Column(db.Float, default=0.5) dynamic_score = db.Column(db.Integer, default=0) @@ -51,16 +50,15 @@ class DynamicDockerChallenge(Challenges): redirect_port = db.Column(db.Integer, default=0) def __init__(self, *args, **kwargs): + kwargs["initial"] = kwargs["value"] super(DynamicDockerChallenge, self).__init__(**kwargs) - self.initial = kwargs["value"] class WhaleContainer(db.Model): id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(None, db.ForeignKey("users.id")) challenge_id = db.Column(None, db.ForeignKey("challenges.id")) - start_time = db.Column(db.DateTime, nullable=False, - default=datetime.utcnow) + start_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) renew_count = db.Column(db.Integer, nullable=False, default=0) status = db.Column(db.Integer, default=1) uuid = db.Column(db.String(256)) diff --git a/templates/config/frp.router.config.html b/templates/config/frp.router.config.html index 5404901..2ae8adf 100644 --- a/templates/config/frp.router.config.html +++ b/templates/config/frp.router.config.html @@ -18,7 +18,7 @@ value !=None %}value="{{ value }}" {% endif %}> {% endfor %} -{% set frpc_template = get_config("whale:frp_config_template") %} +{% set frpc_template = get_config("whale:frp_config_template", "") %}