Skip to content

Commit

Permalink
Merge pull request #1175 from proditis/target-datails
Browse files Browse the repository at this point in the history
Target datails
  • Loading branch information
proditis authored May 7, 2024
2 parents 3d23bea + 8dd1b99 commit 2e83d46
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 7 deletions.
39 changes: 39 additions & 0 deletions backend/modules/infrastructure/controllers/TargetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use app\modules\gameplay\models\Target;
use app\modules\gameplay\models\TargetSearch;
use app\modules\infrastructure\models\TargetExecCommandForm;
use app\modules\infrastructure\models\TargetInstanceSearch;
use app\modules\infrastructure\models\NetworkTargetScheduleSearch;

use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use Docker\DockerClientFactory;
Expand Down Expand Up @@ -498,6 +501,42 @@ public function actionHeadshots($id)
])));
}

/**
* Return Instances for a given target
* @param string $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionInstances($id)
{
$target = $this->findModel($id);
$searchModel = new TargetInstanceSearch();
$searchModel->target_id = $target->id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Json::encode(trim($this->renderAjax('full-view/_target_instances-tab', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
])));
}

/**
* Return Instances for a given target
* @param string $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionNetworkSchedule($id)
{
$target = $this->findModel($id);
$searchModel = new NetworkTargetScheduleSearch();
$searchModel->target_id = $target->id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return Json::encode(trim($this->renderAjax('full-view/_network-schedule-tab', [
'dataProvider' => $dataProvider,
'searchModel' => $searchModel
])));
}

/**
* Return submitted writeups for a given target
* @param string $id
Expand Down
51 changes: 51 additions & 0 deletions backend/modules/infrastructure/views/target/full-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@
<!-- Begin .page-heading -->
<p></p>
<?= $this->render('full-view/_heading', ['model' => $model]); ?>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Logs', ['logs', 'id' => $model->id], ['class' => 'btn btn-info']) ?>
<?= Html::a('Exec', ['exec', 'id' => $model->id], ['class' => 'btn btn-danger','style'=>'background: black; color: white']) ?>
<?= Html::a('Generate', ['generate', 'id' => $model->id], ['class' => 'btn btn-info', 'style'=>'background-color: gray']) ?>
<?= Html::a('Spin', ['spin', 'id' => $model->id], [
'class' => 'btn btn-warning',
'data' => [
'confirm' => 'Are you sure you want to restart the host?',
'method' => 'post',
],
]) ?>
<?= Html::a('Pull', ['pull', 'id' => $model->id], [
'class' => 'btn btn-success',
'data' => [
'method' => 'post',
],
]) ?>

<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
<?= Html::a('Destroy', ['destroy', 'id' => $model->id], [
'class' => 'btn btn-info',
'data' => [
'confirm' => 'Are you sure you want to destroy the container for this item?',
'method' => 'post',
],
]) ?>

</p>
<div class="row">
<div class="col-md-4">
<?= $this->render('full-view/_target_booleans', ['model' => $model]); ?>
Expand All @@ -42,6 +77,22 @@
'options' => ['id' => '_properties-tab'],
'active' => true,
],
[
'label' => '<i class="far fa-file-alt" data-toggle="tooltip" data-placement="top" title="Target Metadata"></i>',
'content' => $this->render('full-view/_metadata-tab', ['model' => $model]),
'headerOptions' => ['style' => 'font-weight:bold'],
'options' => ['id' => '_metadata-tab'],
],
[
'label' => '<i class="fas fa-server" data-toggle="tooltip" data-placement="top" title="Target Instances"></i>',
'linkOptions' => ['data-url' => Url::to(['instances', 'id' => $model->id])],
'options' => ['id' => 'instances-tab'],
],
[
'label' => '<i class="fas fa-calendar-alt" data-toggle="tooltip" data-placement="top" title="Target Network Migration Schedule"></i>',
'linkOptions' => ['data-url' => Url::to(['network-schedule', 'id' => $model->id])],
'options' => ['id' => 'network-schedule-tab'],
],
[
'label' => '<i class="fas fa-spinner" data-toggle="tooltip" data-placement="top" title="Player Progress"></i>',
'headerOptions' => ['style' => 'font-weight:bold'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
?>
<div class="page-heading">
<div class="media-left pr30">
<div class="row">
<div class="col-lg-1">
<div class="row d-flex h-100">
<div class="col-lg-4">
<a href="//<?= Yii::$app->sys->offense_domain ?>/target/<?= $model->id ?>" target="_blank">
<img width="100px" class="img-fluid img-thumbnail" src="//<?= Yii::$app->sys->offense_domain ?>/images/targets/_<?= $model->name ?>-thumbnail.png" alt="<?= Yii::$app->sys->offense_domain ?>/images/targets/_<?= $model->name ?>-thumbnail.png">
<img width="100%" class="img-fluid img-thumbnail" src="//<?= Yii::$app->sys->offense_domain ?>/images/targets/<?= $model->name ?>.png" alt="<?= Yii::$app->sys->offense_domain ?>/images/targets/<?= $model->name ?>.png">
</a>
</div>
<div class="col">
<h2 class="media-heading"><?= Html::encode($model->name) ?> - <span class="text-muted h5"><?=Html::encode($model->purpose)?></span></h2>
<?= $model->description ?>
<div class="col justify-content-center align-self-center">
<h2 class="media-heading"><?= Html::encode($model->name) ?> - <span class="text-muted h5"><?= Html::encode($model->purpose) ?></span></h2>
<?= $model->description ?>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

use yii\widgets\DetailView;
use yii\helpers\HtmlPurifier;
use yii\helpers\Markdown;
use yii\helpers\Html;

?>
<h5>Target Metadata</h5>
<?= DetailView::widget([
'model' => $model->metadata,
'attributes' => [
[
'attribute' => 'scenario',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->scenario, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'instructions',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->instructions, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'solution',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->solution, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'pre_exploitation',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->pre_exploitation, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'pre_credits',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->pre_credits, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'post_credits',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->post_credits, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'pre_exploitation',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->pre_exploitation, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
[
'attribute' => 'post_exploitation',
'format' => 'html',
'contentOptions' => ['style' => 'max-width:100%'],
'value' => function ($model) {
return HtmlPurifier::process(Markdown::process($model->post_exploitation, 'gfm-comment'), ['Attr.AllowedFrameTargets' => ['_blank']]);
}
],
],
]) ?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\infrastructure\models\NetworkTargetScheduleSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

Pjax::begin(['id' => 'network-schedule-tabPJ', 'enablePushState' => false, 'enableReplaceState' => false,]); ?>

<h1>Network Target Schedule</h1>

<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'id' => 'network-schedule-tab',
'columns' => [
[
'attribute' => 'target_name',
'value' => 'target.name',
],
[
'attribute' => 'network_name',
'value' => 'network.name',
],
'migration_date',

['class' => 'yii\grid\ActionColumn'],
],
]);
Pjax::end();
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="panel">
<div class="panel-heading">
<span class="panel-icon">
<i class="fas fa-diagnoses"></i>
<i class="fas fa-diagnoses"></i>
</span>
<span class="panel-title"> Details</span>
</div>
Expand All @@ -16,6 +16,12 @@
</tr>
</thead>
<tbody>
<?php if ($model->ondemand) : ?>
<tr>
<td class="<?= $model->ondemand->state==1 ? "text-success" : "text-danger"?>"><b><i class="fas fa-power-off"></i> OnDemand</b></td>
<td><?= $model->ondemand->state==1 ? $model->ondemand->player->username : "" ?></td>
</tr>
<?php endif; ?>
<tr>
<td><i class="fas fa-battery-half"></i> Difficulty</td>
<td><?= $model->difficultyString ?></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\grid\GridView;
use yii\widgets\Pjax;
use app\modules\infrastructure\models\Server;
/* @var $this yii\web\View */
/* @var $searchModel app\modules\infrastructure\models\TargetInstanceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

Pjax::begin(['id' => 'instances-tabPJ', 'enablePushState' => false, 'enableReplaceState' => false,]); ?>
?>
<h3>Target Instances</h3>

<?= GridView::widget([
'id' => 'instances-tab',
'dataProvider' => $dataProvider,
'columns' => [
[
'attribute' => 'player_id',
'value' => function ($model) {
return $model->player_id . ': ' . $model->player->username;
}
],
[
'attribute' => 'server_id',
'filter' => ArrayHelper::map(Server::find()->orderBy(['name' => SORT_ASC, 'ip' => SORT_ASC])->asArray()->all(), 'id', 'name'),
'value' => function ($model) {
if ($model->server) return $model->server_id . ': ' . $model->server->name;
return null;
}
],
'ipoctet',
[
'attribute' => 'reboot',
'value' => 'rebootVal',
'filter' => [0 => 'Start / Do Nothing', 1 => 'Restart', 2 => 'Destroy'],
'headerOptions' => ['style' => 'width:7em'],
'contentOptions' => ['style' => 'white-space: nowrap;'],
],
'team_allowed:boolean',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{restart} {destroy} {view} {update} {delete}',
'contentOptions' => ['style' => 'white-space: nowrap;'],
'buttons' => [
'restart' => function ($url) {
return Html::a(
'<i class="bi bi-arrow-clockwise"></i>',
$url,
[
'title' => 'Restart instance',
'data-pjax' => '0',
'data-confirm' => 'You are about to start/restart this instance. Are you sure?',
'data-method' => 'POST',
]
);
},
'destroy' => function ($url) {
return Html::a(
'<i class="bi bi-power"></i>',
$url,
[
'title' => 'Destroy container',
'data-pjax' => '0',
'data-confirm' => 'You are about to destroy this instance. Are you sure?',
'data-method' => 'POST',
]
);
},
],
],
],
]);
Pjax::end();

0 comments on commit 2e83d46

Please sign in to comment.