Skip to content

Commit

Permalink
Merge pull request #1289 from proditis/speed-programming
Browse files Browse the repository at this point in the history
Speed programming module
  • Loading branch information
proditis authored Nov 5, 2024
2 parents 7b3c491 + 5be7415 commit d8ceebf
Show file tree
Hide file tree
Showing 55 changed files with 2,705 additions and 222 deletions.
17 changes: 17 additions & 0 deletions ansible/Dockerfiles/validator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM buildpack-deps:buster-curl
LABEL maintainer="echothrust solutions <[email protected]>"
LABEL description="Speed Programming Validation Container"


ENV DEBIAN_FRONTEND noninteractive
COPY --chown=root:root scripts /usr/local/validators
COPY --chown=root:root entrypoint.sh /
WORKDIR /echoctf
RUN set -ex \
&& apt-get update \
&& apt-get install --no-install-recommends -y default-jre default-jdk build-essential wget python3 gcc git gzip socat netcat-openbsd python2 \
&& chmod 0500 /entrypoint.sh /usr/local/validators/*


ENTRYPOINT ["/entrypoint.sh"]
CMD ["bash"]
1 change: 1 addition & 0 deletions ansible/Dockerfiles/validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Validator image example
13 changes: 13 additions & 0 deletions ansible/Dockerfiles/validator/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
if [ "$FETCH_URL"x == "x" ] || [ "$VALIDATE_LANG"x == "x" ]; then
echo "Error: FETCH_URL or VALIDATE_LANG env variable not set";
exit 1
fi

wget -O /echoctf/script_to_validate."${VALIDATE_LANG}" "${FETCH_URL}"


if [ -x /usr/local/validators/${VALIDATE_LANG}_validator ]; then
/usr/local/validators/${VALIDATE_LANG}_validator
fi
$@
6 changes: 6 additions & 0 deletions ansible/Dockerfiles/validator/scripts/c_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Validating c..."
gcc /echoctf/script_to_validate.c -o /echoctf/submission

timeout 1 bash -c "echo \"TEST1\"|/echoctf/submission"
6 changes: 6 additions & 0 deletions ansible/Dockerfiles/validator/scripts/cpp_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Validating cpp..."
g++ /echoctf/script_to_validate.cpp -o /echoctf/submission

timeout 1 bash -c "echo \"TEST1\"|/echoctf/submission"
4 changes: 4 additions & 0 deletions ansible/Dockerfiles/validator/scripts/java_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

echo "Validating java..."
timeout 1 bash -c "echo \"TEST1\"|java /echoctf/script_to_validate.java"
6 changes: 6 additions & 0 deletions ansible/Dockerfiles/validator/scripts/php7_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo "Validating php7..."


echo "TEST1"|timeout 1 php7 /echoctf/script_to_validate.php7
3 changes: 3 additions & 0 deletions ansible/Dockerfiles/validator/scripts/py2_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/python2

print "Validating py2..."
3 changes: 3 additions & 0 deletions ansible/Dockerfiles/validator/scripts/py3_validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/python3

print "Validating py3..."
3 changes: 3 additions & 0 deletions backend/config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
'@npm' => '@vendor/npm-asset',
],
'modules' => [
'speedprogramming' => [
'class' => 'app\modules\speedprogramming\Module',
],
'sales' => [
'class' => 'app\modules\sales\Module',
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use yii\db\Migration;

/**
* Class m241105_111349_add_speed_programming_url_routes
*/
class m241105_111349_add_speed_programming_url_routes extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->upsert('url_route', ['source' => 'speed', 'destination' => 'speedprogramming/default/index'], true);
$this->upsert('url_route', ['source' => 'speed/<id:\d+>', 'destination' => 'speedprogramming/default/view'], true);
$this->upsert('url_route', ['source' => 'speed/<id:\d+>/answer', 'destination' => 'speedprogramming/default/answer'], true);
$this->upsert('sysconfig', ['id' => 'module_speedprogramming_disabled', 'val' => 1], true);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->delete('url_route', ['source' => 'speed',]);
$this->delete('url_route', ['source' => 'speed/<id:\d+>']);
$this->delete('url_route', ['source' => 'speed/<id:\d+>/answer']);
}
}
37 changes: 37 additions & 0 deletions backend/migrations/m241105_014128_create_speed_problem_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use yii\db\Migration;

/**
* Handles the creation of table `{{%speed_problem}}`.
*/
class m241105_014128_create_speed_problem_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%speed_problem}}', [
'id' => $this->primaryKey(),
'name' => $this->string(),
'description' => $this->text(),
'active' => $this->boolean()->notNull()->defaultValue(1),
'difficulty' => $this->smallInteger()->notNull()->defaultValue(0),
'category' => $this->string(64),
'server' => $this->string(),
'challenge_image' => $this->string(),
'validator_image' => $this->string(),
'created_at' => $this->datetime(),
'updated_at' => $this->datetime(),
]);
}

/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('{{%speed_problem}}');
}
}
106 changes: 106 additions & 0 deletions backend/migrations/m241105_014129_create_speed_solution_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

use yii\db\Migration;

/**
* Handles the creation of table `{{%speed_solution}}`.
*/
class m241105_014129_create_speed_solution_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%speed_solution}}', [
'id' => $this->primaryKey(),
'player_id' => $this->integer()->unsigned()->notNull(),
'problem_id' => $this->integer()->notNull(),
'language' => $this->string(),
'sourcecode' => 'LONGBLOB',
'status' => $this->string(),
'points' => $this->integer()->defaultValue(0),
'created_at' => $this->datetime(),
'updated_at' => $this->datetime(),
]);

// creates index for column `player_id`
$this->createIndex(
'{{%idx-speed_solution-player_id}}',
'{{%speed_solution}}',
'player_id'
);

// add foreign key for table `{{%player}}`
$this->addForeignKey(
'{{%fk-speed_solution-player_id}}',
'{{%speed_solution}}',
'player_id',
'{{%player}}',
'id',
'CASCADE'
);

// creates index for column `problem_id`
$this->createIndex(
'{{%idx-speed_solution-problem_id}}',
'{{%speed_solution}}',
'problem_id'
);

// add foreign key for table `{{%speed_problem}}`
$this->addForeignKey(
'{{%fk-speed_solution-problem_id}}',
'{{%speed_solution}}',
'problem_id',
'{{%speed_problem}}',
'id',
'CASCADE'
);

}

/**
* {@inheritdoc}
*/
public function safeDown()
{
// drops foreign key for table `{{%player}}`
$this->dropForeignKey(
'{{%fk-speed_solution-player_id}}',
'{{%speed_solution}}'
);

// drops index for column `player_id`
$this->dropIndex(
'{{%idx-speed_solution-player_id}}',
'{{%speed_solution}}'
);

// drops foreign key for table `{{%team}}`
$this->dropForeignKey(
'{{%fk-speed_solution-team_id}}',
'{{%speed_solution}}'
);

// drops index for column `team_id`
$this->dropIndex(
'{{%idx-speed_solution-team_id}}',
'{{%speed_solution}}'
);

// drops foreign key for table `{{%target}}`
$this->dropForeignKey(
'{{%fk-speed_solution-target_id}}',
'{{%speed_solution}}'
);

// drops index for column `target_id`
$this->dropIndex(
'{{%idx-speed_solution-target_id}}',
'{{%speed_solution}}'
);

$this->dropTable('{{%speed_solution}}');
}
}
6 changes: 6 additions & 0 deletions backend/modules/activity/models/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Stream extends StreamAR
const MODEL_ICONS=[
'headshot'=>'<i class="fas fa-skull" style="color: #FF1A00;font-size: 1.5em;" data-toggle="tooltip" title="Target Headshot"></i>',
'challenge'=>'<i class="fas fa-tasks" style="color: #FF1A00; font-size: 1.5em;" data-toggle="tooltip" title="Challenge Solve"></i>',
'solution'=>'<i class="fas fa-code" style="color: #FF1AFF; font-size: 1.5em;" title="Speed Programming Solution"></i>',
'treasure'=>'<i class="fas fa-flag text-danger" style="font-size: 1.5em;" data-toggle="tooltip" title="Target Flag"></i>',
'finding'=>'<i class="fas fa-fingerprint" style="color:#FF7400; font-size: 1.5em;" data-toggle="tooltip" title="Target Service"></i>',
'question'=>'<i class="fas fa-list-ul text-info" style="font-size: 1.5em;" data-toggle="tooltip" title="Challenge Question"></i>',
Expand Down Expand Up @@ -62,6 +63,11 @@ public function getSuffix()
return "";
}

public function getSolutionMessage()
{
return sprintf("%s %s%s", $this->prefix, $this->title, $this->suffix);
}

public function getBadgeMessage()
{
return sprintf("%s got the badge [<code>%s</code>]%s", $this->prefix, Badge::findOne(['id'=>$this->model_id])->name, $this->suffix);
Expand Down
24 changes: 24 additions & 0 deletions backend/modules/speedprogramming/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace app\modules\speedprogramming;

/**
* speedprogramming module definition class
*/
class Module extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace='app\modules\speedprogramming\controllers';

/**
* {@inheritdoc}
*/
public function init()
{
parent::init();

// custom initialization code goes here
}
}
Loading

0 comments on commit d8ceebf

Please sign in to comment.