Skip to content

Commit

Permalink
Merge pull request #1148 from echoCTF/issue-1147
Browse files Browse the repository at this point in the history
Issue 1147
  • Loading branch information
proditis authored Apr 15, 2024
2 parents d22f738 + 90f2054 commit 33242d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public function actionExec($id)
*/
public function actionIndex()
{
if(($ret=$this->prerequisitesCheck())!==[])
{
return $this->redirect($ret);
}

$searchModel = new TargetInstanceSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

Expand Down Expand Up @@ -173,6 +178,11 @@ public function actionView($id)
*/
public function actionCreate()
{
if(($ret=$this->prerequisitesCheck())!==[])
{
return $this->redirect($ret);
}

$model = new TargetInstance();

if ($model->load(Yii::$app->request->post()) && $model->save()) {
Expand Down Expand Up @@ -305,4 +315,33 @@ protected function findModel($id)

throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
}

/**
* Check for prerequisite players, targets and servers
* @param boolean $player Whether to check for players exist
* @param boolean $target Whether to check for target exist
* @param boolean $server Whether to check for server exist
* @return array
*/
protected function prerequisitesCheck($player=true,$target=true,$server=true)
{
if((bool) $player && (int)\app\modules\frontend\models\Player::find()->count() === 0)
{
Yii::$app->session->setFlash('warning', Yii::t('app',"No players found create one first."));
return ['/frontend/player/create'];
}

if((bool) $target && (int)\app\modules\gameplay\models\Target::find()->count() === 0)
{
Yii::$app->session->setFlash('warning', Yii::t('app',"No targets found create one first."));
return ['/gameplay/target/create'];
}

if((bool) $server && (int)\app\modules\infrastructure\models\Server::find()->count() === 0)
{
Yii::$app->session->setFlash('warning', Yii::t('app',"No servers found create one first."));
return ['/infrastructure/server/create'];
}
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->player_id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Logs', ['logs', 'id' => $model->player_id], ['class' => 'btn btn-info']) ?>
<?= Html::a('Exec', ['exec', 'id' => $model->player_id], ['class' => 'btn btn-danger','style'=>'background: black; color: white']) ?>
<?= Html::a('Logs', ['logs', 'id' => $model->player_id], ['class' => 'btn btn-info']) ?>
<?= Html::a('Restart', ['restart', 'id' => $model->player_id], [
'class' => 'btn btn-warning',
'data' => [
Expand Down

0 comments on commit 33242d8

Please sign in to comment.