Skip to content

Commit

Permalink
insanity
Browse files Browse the repository at this point in the history
  • Loading branch information
delargement authored Sep 13, 2023
1 parent ba4b7d6 commit 20be32d
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions CTFd/plugins/insanity_check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
39 changes: 39 additions & 0 deletions CTFd/plugins/insanity_check/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Blueprint

from CTFd.models import (
ChallengeFiles,
Challenges,
Fails,
Flags,
Hints,
Solves,
Tags,
db,
)
from CTFd.plugins import register_plugin_assets_directory
from CTFd.plugins.challenges import CHALLENGE_CLASSES, BaseChallenge

class InsaneChallenge(BaseChallenge):
id = "insane" # Unique identifier used to register challenges
name = "insane" # Name of a challenge type

# locations of the html templates
templates = { # Handlebars templates used for each aspect of challenge editing & viewing
'create': '/plugins/insanity_check/assets/create.html',
'update': '/plugins/insanity_check/assets/update.html',
'view': '/plugins/insanity_check/assets/view.html',
}

# location of the JavaScript files
scripts = { # Scripts that are loaded when a template is loaded
'create': '/plugins/insanity_check/assets/create.js',
'update': '/plugins/insanity_check/assets/update.js',
'view': '/plugins/insanity_check/assets/view.js',
}

challenge_model = Challenges

CHALLENGE_CLASSES["insane"] = InsaneChallenge

def load(app):
register_plugin_assets_directory(app, base_path='/plugins/insanity_check/assets/')
1 change: 1 addition & 0 deletions CTFd/plugins/insanity_check/assets/create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "admin/challenges/create.html" %}
4 changes: 4 additions & 0 deletions CTFd/plugins/insanity_check/assets/create.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CTFd.plugin.run((_CTFd) => {
const $ = _CTFd.lib.$
const md = _CTFd.lib.markdown()
})
3 changes: 3 additions & 0 deletions CTFd/plugins/insanity_check/assets/update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% extends "admin/challenges/update.html" %}

<h1>hi</h1>
Empty file.
140 changes: 140 additions & 0 deletions CTFd/plugins/insanity_check/assets/view.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" href="#challenge">Challenge</a>
</li>
{% block solves %}
<li class="nav-item">
<a class="nav-link challenge-solves" href="#solves">
{% if solves != None %}
{{ solves }} {% if solves > 1 %}Solves{% else %}Solves{% endif %}
{% endif %}
</a>
</li>
{% endblock %}
</ul>
<div role="tabpanel">
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade show active" id="challenge">
<h2 class='challenge-name text-center pt-3'>
{{ challenge.name }}
</h2>
<h3 class="challenge-value text-center">
{{ challenge.value }}
</h3>

<div class="challenge-tags text-center">
{% block tags %}
{% for tag in tags %}
<span class='badge badge-info challenge-tag'>{{ tag }}</span>
{% endfor %}
{% endblock %}
</div>

<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'>
<a class="btn btn-info btn-hint btn-block load-hint" href="javascript:;" data-hint-id="{{ hint.id }}">
{% if hint.content %}
<small>
View Hint
</small>
{% else %}
{% if hint.cost %}
<small>
Unlock Hint for {{ hint.cost }} points
</small>
{% else %}
<small>
View Hint
</small>
{% endif %}
{% endif %}
</a>
</div>
{% endfor %}
</div>

<div class="row challenge-files text-center pb-3">
{% for file in files %}
<div class='col-md-4 col-sm-4 col-xs-12 file-button-wrapper d-block'>
<a class='btn btn-info btn-file mb-1 d-inline-block px-2 w-100 text-truncate'
href='{{ file }}'>
<i class="fas fa-download"></i>
<small>
{% set segments = file.split('/') %}
{% set file = segments | last %}
{% set token = file.split('?') | last %}
{% if token %}
{{ file | replace("?" + token, "") }}
{% else %}
{{ file }}
{% endif %}
</small>
</a>
</div>
{% endfor %}
</div>

{% if max_attempts > 0 %}
<div class="row text-center">
<div class="col-md-12">
<p>
{{ attempts }}/{{ max_attempts }} attempt{{ max_attempts|pluralize }}
</p>
</div>
</div>
{% endif %}

<div class="row notification-row">
<div class="col-md-12">
<div id="result-notification" class="alert alert-dismissable text-center w-100"
role="alert" style="display: none;">
<strong id="result-message"></strong>
</div>
</div>
</div>
</div>

<div role="tabpanel" class="tab-pane fade" id="solves">
<div class="row">
<div class="col-md-12">
<table class="table table-striped text-center">
<thead>
<tr>
<td><b>Name</b>
</td>
<td><b>Date</b>
</td>
</tr>
</thead>
<tbody id="challenge-solves-names">
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
37 changes: 37 additions & 0 deletions CTFd/plugins/insanity_check/assets/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
CTFd._internal.challenge.data = undefined;

// TODO: Remove in CTFd v4.0
CTFd._internal.challenge.renderer = null;

CTFd._internal.challenge.preRender = function() {};

// TODO: Remove in CTFd v4.0
CTFd._internal.challenge.render = null;

CTFd._internal.challenge.postRender = function() {};

CTFd._internal.challenge.submit = function(preview) {
var challenge_id = parseInt(CTFd.lib.$("#challenge-id").val());
var submission = CTFd.lib.$("#challenge-input").val();

var body = {
challenge_id: challenge_id,
submission: submission
};
var params = {};
if (preview) {
params["preview"] = true;
}

return CTFd.api.post_challenge_attempt(params, body).then(function(response) {
if (response.status === 429) {
// User was ratelimited but process response
return response;
}
if (response.status === 403) {
// User is not logged in or CTF is paused.
return response;
}
return response;
});
};

0 comments on commit 20be32d

Please sign in to comment.