Skip to content

Commit

Permalink
Merge pull request #1331 from proditis/fixes-1324
Browse files Browse the repository at this point in the history
Fixes 1324
  • Loading branch information
proditis authored Nov 30, 2024
2 parents 63cd84f + 0b9fdee commit 114c35d
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 171 deletions.
16 changes: 8 additions & 8 deletions frontend/assets/MaterialAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class MaterialAsset extends AssetBundle

public $css = [
['//fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons|Roboto+Mono|Orbitron&display=swap', 'async' => 'async', 'crossorigin' => "anonymous"],
['css/all.min.css?v=0.20.3', 'defer' => 'defer'],
'css/material-dashboard.css?v=0.20.0',
'css/material.css?v=0.22.0',
['css/all.min.css?v=1.0.0', 'defer' => 'defer'],
'css/material-dashboard.css?v=1.0.0',
'css/material.css?v=1.0.0',
];

public $js = [
'/js/core/popper.min.js?v=0.20.0',
'/js/core/bootstrap-material-design.min.js?v=0.20.0',
'/js/plugins/perfect-scrollbar.jquery.min.js?v=0.20.0',
'/js/core/popper.min.js?v=1.0.0',
'/js/core/bootstrap-material-design.min.js?v=1.0.0',
'/js/plugins/perfect-scrollbar.jquery.min.js?v=1.0.0',
// ["js/plugins/bootstrap-autocomplete.min.js", 'defer' => 'defer'],
/* Plugin for the momentJs */
['/js/plugins/moment.min.js', 'defer' => 'defer'],
Expand All @@ -67,8 +67,8 @@ class MaterialAsset extends AssetBundle
// 'https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE',
/******/
//'/js/cookieconsent.min.js', // Move this to only the pages needing it.
'/js/material-dashboard.js?v=0.24.0',
['/js/libechoctf.js?v=0.24.0', 'defer' => 'defer'],
'/js/material-dashboard.js?v=1.0.0',
['/js/libechoctf.js?v=1.0.0', 'defer' => 'defer'],
];

public $depends = [
Expand Down
42 changes: 34 additions & 8 deletions frontend/modules/target/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ public function behaviors()
return ArrayHelper::merge(parent::behaviors(), [
'access' => [
'class' => AccessControl::class,
'only' => ['index', 'view', 'claim', 'spin', 'spawn', 'shut', 'versus', 'badge', 'search'],
'only' => ['index', 'view', 'claim', 'spin', 'spawn', 'shut', 'versus', 'badge', 'search','ip'],
'rules' => [
'eventStartEnd' => [
'actions' => ['index', 'view', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search'],
'actions' => ['index', 'view', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search','ip'],
],
'teamsAccess' => [
'actions' => ['index', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search'],
'actions' => ['index', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search','ip'],
],
'disabledRoute' => [
'actions' => ['badge', 'view', 'index', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search'],
'actions' => ['badge', 'view', 'index', 'claim', 'spin', 'spawn', 'shut', 'versus', 'search', 'ip'],
],
[
'actions' => ['spawn', 'shut', 'spin'],
Expand Down Expand Up @@ -110,7 +110,7 @@ public function behaviors()
'verbs' => ['post'],
],
[
'actions' => ['index','search'],
'actions' => ['index','search','ip'],
'allow' => true,
'roles' => ['@']
],
Expand All @@ -124,7 +124,7 @@ public function behaviors()
},
],
[
'actions' => ['view', 'versus', 'badge'],
'actions' => ['view', 'versus', 'badge','ip'],
'allow' => true,
'roles' => ['@']
],
Expand All @@ -140,7 +140,7 @@ public function behaviors()
],
[
'class' => 'yii\filters\AjaxFilter',
'only' => ['claim', 'search'],
'only' => ['claim', 'search','ip'],
],
]);
}
Expand Down Expand Up @@ -221,7 +221,7 @@ public function actionIndex()
}

/**
* Lists all Credits models.
* Returns target models matching $q.
* @return mixed
*/
public function actionSearch($q)
Expand All @@ -248,6 +248,32 @@ public function actionSearch($q)
return [];
}

/**
* Lists all Credits models.
* @return mixed
*/

public function actionIp($id)
{
Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
if (($target = \app\modules\target\models\Target::find()->where(['t.id' => $id])->forView(\Yii::$app->user->id)->one()) === null) {
throw new NotFoundHttpException(\Yii::t('app', 'The requested target does not exist.'));
}
$obj=new \stdClass;
if (Yii::$app->user->identity->instance)
{
$obj->ip = long2ip(Yii::$app->user->identity->instance->ip);
$obj->instance=true;
}
else if(($target->on_ondemand===false) || ($target->on_ondemand && $target->ondemand_state==1))
{
$obj->ip = long2ip($target->ip);
}
else
$obj->ip=long2ip(0);

return $obj;
}
/**
* Renders a Target model details view
* @return string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
else
$display_ip=Html::a($target_ip,$target_ip,["class"=>'copy-to-clipboard text-danger text-bold','swal-data'=>"Copied to clipboard",'data-toggle'=>'tooltip','title'=>\Yii::t('app',"The IP of your private instance. Click to copy IP to clipboard.")]);
}

if($target_ip=='0.0.0.0')
{
$this->registerJs("targetUpdates({$target->id});", \yii\web\View::POS_READY);
}
$subtitleARR=[$target->category,ucfirst($target->getDifficultyText($target->average_rating)),boolval($target->rootable) ? "Rootable" : "Non rootable",$target->timer===false ? null:'Timed'];
$subtitle=implode(", ",array_filter($subtitleARR));
Card::begin([
Expand All @@ -31,7 +34,7 @@
'icon'=>sprintf('<img src="%s" class="img-fluid" style="max-width: 10rem; max-height: 4rem;" />', $target->logo),
'color'=>'target',
'subtitle'=>$subtitle,
'title'=>sprintf('%s / %s', $target->name, $display_ip),
'title'=>sprintf('%s / <span id="target_id">%s</span>', $target->name, $display_ip),
'footer'=>sprintf('<div class="stats">%s</div><span>%s</span>', $target->purpose, TargetCardActions::widget(['model'=>$target,'identity'=>$identity]) ),
]);
echo "<p class='text-danger'><i class='fas fa-flag'></i> ", $target->total_treasures, ": Flag".($target->total_treasures > 1 ? 's' : '')." ";
Expand Down
Loading

0 comments on commit 114c35d

Please sign in to comment.