public function run()
 {
     $template = "";
     $task = array_shift($this->tasks);
     if (!$task) {
         return $template;
     }
     foreach (Tasks::getCategories() as $category) {
         $template_rows = "";
         $current_category = $task->category;
         while ($task->category == $current_category) {
             $template_rows .= $this->join_tile($task);
             $task = array_shift($this->tasks);
             if (!$task) {
                 break;
             }
         }
         $template .= $this->join_row($template_rows);
         if (!$task) {
             break;
         }
     }
     $template = $this->join_container($template);
     return $template;
 }
 protected function findModel($id)
 {
     if (($model = Tasks::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionSubmit()
 {
     $team = Yii::$app->user->identity->id;
     $task = intval(Yii::$app->request->post("task"));
     $flag = Yii::$app->request->post("flag");
     if (!Tasks::checkIfBruteforce($team, $task)) {
         if (Tasks::submitFlag($team, $task, $flag)) {
             return "accepted";
         } else {
             return "flag is not valid";
         }
     } else {
         return "Bruteforce attempt";
     }
 }
Exemple #4
0
                        <input type="text" name="flag">
                        <input type="hidden" name="task" value="<?php 
    echo $model->id;
    ?>
">
                        <input type="button" class="btn btn-success" value="Отправить">
                    </form>
                </div>
            <?php 
}
?>

            <br>

            <div class="task-solvedteams alert alert-success">
                Команды, вернувшиеся с задания:
                <?php 
foreach (Tasks::getTeamsSolvedTask($model->id) as $team) {
    echo Html::tag("span", Html::encode($team->user->login), ["class" => "label label-info"]) . " ";
}
?>
            </div>

        </div>
    </div>
</div>

<?php 
if ($accepted === false) {
    $this->registerJs("\n                  \$('.btn').click(function(){\n                        \$.ajax({\n                                url: '/submit',\n                                type: 'POST',\n                                data: \$('.task-submit form').serializeArray(),\n                                success: function (data) {\n                                    if (data == 'accepted')\n                                        location.reload();\n                                    else\n                                        if (data == 'Bruteforce attempt')\n                                            \$('.tasks-result').html('<div class=\\'alert alert-danger\\' role=\\'alert\\'>Вы слишком часто посылаете флаги</div>');\n                                        else\n                                            \$('.tasks-result').html('<div class=\\'alert alert-danger\\' role=\\'alert\\'>Флаг не принят</div>');\n                                },\n                                error: function (XMLHttpRequest, textStatus, errorThrown) {\n\n                                }\n                        });\n                       return false;\n                  });\n                  \$(document).on('keypress', 'form', function(event) {\n                        return event.keyCode != 13;\n                  });\n                  \$('.spoiler-trigger').click(function() {\n                    \$('#teams-who-solved').collapse('toggle');\n                  });\n\n                ");
}
 public function getTask()
 {
     return $this->hasOne(Tasks::className(), ['id' => 'task_id']);
 }
Exemple #6
0
/* @var $this yii\web\View */
/* @var $model app\models\AcceptedRequests */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="accepted-requests-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'user_id')->dropDownList(Users::getArrayAll());
?>

    <?php 
echo $form->field($model, 'task_id')->dropDownList(Tasks::getAllTasks());
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Exemple #7
0
 public static function submitFlag($team, $task, $flag)
 {
     if (Tasks::isTaskAccepted($team, $task)) {
         return true;
     }
     $model = Tasks::find()->where(["id" => $task])->one();
     if (!$model) {
         return false;
     }
     if ($model->visible !== 1) {
         return false;
     }
     $request = new Requests();
     $request->user_id = $team;
     $request->task_id = $task;
     $request->answer = $flag;
     $task_is_accepted = false;
     if ($model->checker_name === 0) {
         $task_is_accepted = $flag === $model->answer;
     } else {
         $main_checker = new MainChecker();
         $task_is_accepted = $main_checker->checkFlag($model->checker_name, $flag);
     }
     if ($task_is_accepted === true) {
         Tasks::givePoints($team, $task);
         $request->result = 1;
         $request->save();
         $tasks_open = Tasks::find()->where(["category" => $model->category])->andWhere('position = :position+1', [':position' => $model->position])->orderBy("position")->all();
         foreach ($tasks_open as $task_open) {
             $task_open->visible = 1;
             $task_open->save();
         }
         return true;
     } else {
         $request->result = 0;
         $request->save();
         return false;
     }
 }