From a4d122091c2d865dd4ff1ff088547f02ebeb8bb1 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Tue, 7 May 2024 07:41:59 +0300 Subject: [PATCH 1/5] add 2 new actions for instances and schedule --- .../controllers/TargetController.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/modules/infrastructure/controllers/TargetController.php b/backend/modules/infrastructure/controllers/TargetController.php index e873950c6..9a48d300e 100644 --- a/backend/modules/infrastructure/controllers/TargetController.php +++ b/backend/modules/infrastructure/controllers/TargetController.php @@ -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; @@ -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 From b2b9589a0836f9087b017776d998401205cf045c Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Tue, 7 May 2024 07:42:31 +0300 Subject: [PATCH 2/5] change heading to include twitter image --- .../views/target/full-view/_heading.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/modules/infrastructure/views/target/full-view/_heading.php b/backend/modules/infrastructure/views/target/full-view/_heading.php index 33bb105d4..5ec3a08f9 100644 --- a/backend/modules/infrastructure/views/target/full-view/_heading.php +++ b/backend/modules/infrastructure/views/target/full-view/_heading.php @@ -4,15 +4,15 @@ ?>
-
-
+
+ -
-

name) ?> - purpose)?>

- description ?> +
+

name) ?> - purpose) ?>

+ description ?>
From f75403aa864c03c490b7149b6950e9833e72ca47 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Tue, 7 May 2024 07:42:51 +0300 Subject: [PATCH 3/5] add ondemand information --- .../views/target/full-view/_target_details.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/modules/infrastructure/views/target/full-view/_target_details.php b/backend/modules/infrastructure/views/target/full-view/_target_details.php index f3c380a0d..f6ebe5403 100644 --- a/backend/modules/infrastructure/views/target/full-view/_target_details.php +++ b/backend/modules/infrastructure/views/target/full-view/_target_details.php @@ -5,7 +5,7 @@
- + Details
@@ -16,6 +16,12 @@ +ondemand) : ?> + + "> OnDemand + ondemand->state==1 ? $model->ondemand->player->username : "" ?> + + Difficulty difficultyString ?> From 34bf38c6a15e5eaaaba69607e8ffff97d749ba47 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Tue, 7 May 2024 07:43:11 +0300 Subject: [PATCH 4/5] add views for new tabs --- .../views/target/full-view/_metadata-tab.php | 78 +++++++++++++++++++ .../full-view/_network-schedule-tab.php | 32 ++++++++ .../full-view/_target_instances-tab.php | 76 ++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 backend/modules/infrastructure/views/target/full-view/_metadata-tab.php create mode 100644 backend/modules/infrastructure/views/target/full-view/_network-schedule-tab.php create mode 100644 backend/modules/infrastructure/views/target/full-view/_target_instances-tab.php diff --git a/backend/modules/infrastructure/views/target/full-view/_metadata-tab.php b/backend/modules/infrastructure/views/target/full-view/_metadata-tab.php new file mode 100644 index 000000000..3115a9e13 --- /dev/null +++ b/backend/modules/infrastructure/views/target/full-view/_metadata-tab.php @@ -0,0 +1,78 @@ + +
Target Metadata
+ $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']]); + } + ], + ], +]) ?> \ No newline at end of file diff --git a/backend/modules/infrastructure/views/target/full-view/_network-schedule-tab.php b/backend/modules/infrastructure/views/target/full-view/_network-schedule-tab.php new file mode 100644 index 000000000..7cc7c54b8 --- /dev/null +++ b/backend/modules/infrastructure/views/target/full-view/_network-schedule-tab.php @@ -0,0 +1,32 @@ + 'network-schedule-tabPJ', 'enablePushState' => false, 'enableReplaceState' => false,]); ?> + +

Network Target Schedule

+ + $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(); diff --git a/backend/modules/infrastructure/views/target/full-view/_target_instances-tab.php b/backend/modules/infrastructure/views/target/full-view/_target_instances-tab.php new file mode 100644 index 000000000..8cb15d615 --- /dev/null +++ b/backend/modules/infrastructure/views/target/full-view/_target_instances-tab.php @@ -0,0 +1,76 @@ + 'instances-tabPJ', 'enablePushState' => false, 'enableReplaceState' => false,]); ?> +?> +

Target Instances

+ + '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( + '', + $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( + '', + $url, + [ + 'title' => 'Destroy container', + 'data-pjax' => '0', + 'data-confirm' => 'You are about to destroy this instance. Are you sure?', + 'data-method' => 'POST', + ] + ); + }, + ], + ], + ], +]); +Pjax::end(); From 8dd1b99e1e6ec692d95136b4e9721a6face08acc Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Tue, 7 May 2024 07:43:37 +0300 Subject: [PATCH 5/5] add actions to target operations --- .../infrastructure/views/target/full-view.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/backend/modules/infrastructure/views/target/full-view.php b/backend/modules/infrastructure/views/target/full-view.php index dc4aebf61..2b9001a1f 100644 --- a/backend/modules/infrastructure/views/target/full-view.php +++ b/backend/modules/infrastructure/views/target/full-view.php @@ -17,6 +17,41 @@

render('full-view/_heading', ['model' => $model]); ?> +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], ['class' => 'btn btn-info']) ?> + $model->id], ['class' => 'btn btn-danger','style'=>'background: black; color: white']) ?> + $model->id], ['class' => 'btn btn-info', 'style'=>'background-color: gray']) ?> + $model->id], [ + 'class' => 'btn btn-warning', + 'data' => [ + 'confirm' => 'Are you sure you want to restart the host?', + 'method' => 'post', + ], + ]) ?> + $model->id], [ + 'class' => 'btn btn-success', + 'data' => [ + 'method' => 'post', + ], + ]) ?> + + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Are you sure you want to delete this item?', + 'method' => 'post', + ], + ]) ?> + $model->id], [ + 'class' => 'btn btn-info', + 'data' => [ + 'confirm' => 'Are you sure you want to destroy the container for this item?', + 'method' => 'post', + ], + ]) ?> + +

render('full-view/_target_booleans', ['model' => $model]); ?> @@ -42,6 +77,22 @@ 'options' => ['id' => '_properties-tab'], 'active' => true, ], + [ + 'label' => '', + 'content' => $this->render('full-view/_metadata-tab', ['model' => $model]), + 'headerOptions' => ['style' => 'font-weight:bold'], + 'options' => ['id' => '_metadata-tab'], + ], + [ + 'label' => '', + 'linkOptions' => ['data-url' => Url::to(['instances', 'id' => $model->id])], + 'options' => ['id' => 'instances-tab'], + ], + [ + 'label' => '', + 'linkOptions' => ['data-url' => Url::to(['network-schedule', 'id' => $model->id])], + 'options' => ['id' => 'network-schedule-tab'], + ], [ 'label' => '', 'headerOptions' => ['style' => 'font-weight:bold'],