Skip to content

Commit

Permalink
Add connection_info to Challenges model (CTFd#1965)
Browse files Browse the repository at this point in the history
* Closes CTFd#1964 
* Adds connection_info to Challenges
  • Loading branch information
ColdHeat authored Jul 30, 2021
1 parent 27d862a commit c77a1c2
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions CTFd/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Challenges(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
description = db.Column(db.Text)
connection_info = db.Column(db.Text)
max_attempts = db.Column(db.Integer, default=0)
value = db.Column(db.Integer)
category = db.Column(db.String(80))
Expand Down
1 change: 1 addition & 0 deletions CTFd/plugins/challenges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def read(cls, challenge):
"name": challenge.name,
"value": challenge.value,
"description": challenge.description,
"connection_info": challenge.connection_info,
"category": challenge.category,
"state": challenge.state,
"max_attempts": challenge.max_attempts,
Expand Down
1 change: 1 addition & 0 deletions CTFd/plugins/dynamic_challenges/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def read(cls, challenge):
"decay": challenge.decay,
"minimum": challenge.minimum,
"description": challenge.description,
"connection_info": challenge.connection_info,
"category": challenge.category,
"state": challenge.state,
"max_attempts": challenge.max_attempts,
Expand Down
12 changes: 12 additions & 0 deletions CTFd/themes/admin/templates/challenges/update.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@
</div>
{% endblock %}

{% block connection_info %}
<div class="form-group">
<label>
Connection Info<br>
<small class="form-text text-muted">
Use this to specify a link, hostname, or connection instructions for your challenge.
</small>
</label>
<input type="text" class="form-control chal-connection-info" name="connection_info" value="{{ challenge.connection_info | default('', true) }}">
</div>
{% endblock %}

{% block value %}
<div class="form-group">
<label for="value">
Expand Down
12 changes: 12 additions & 0 deletions CTFd/themes/core/templates/challenge.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ <h3 class="challenge-value text-center">

<span class="challenge-desc">{% block description %}{{ challenge.html }}{% endblock %}</span>

<span class="challenge-connection-info">
{% block connection_info %}
{% set conn = challenge.connection_info %}
{% if not conn %}
{% elif conn.startswith("http") %}
{{ conn | urlize(target="_blank") }}
{% else %}
<code>{{ conn }}</code>
{% endif %}
{% endblock %}
</span>

<div class="challenge-hints hint-row row">
{% for hint in hints %}
<div class='col-md-12 hint-button-wrapper text-center mb-3'>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Add connection_info column to Challenges
Revision ID: 6012fe8de495
Revises: ef87d69ec29a
Create Date: 2021-07-30 03:50:54.219124
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "6012fe8de495"
down_revision = "ef87d69ec29a"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("challenges", sa.Column("connection_info", sa.Text(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("challenges", "connection_info")
# ### end Alembic commands ###

0 comments on commit c77a1c2

Please sign in to comment.