mirror of https://github.com/MISP/MISP
chg: [galaxyMatrix] Added sorting by score. Fix #4608
parent
219df09e98
commit
4fbe857f90
|
@ -4953,6 +4953,7 @@ class EventsController extends AppController
|
||||||
}
|
}
|
||||||
// end FIXME
|
// end FIXME
|
||||||
|
|
||||||
|
$this->Galaxy->sortMatrixByScore($tabs, $scores);
|
||||||
if ($this->_isRest()) {
|
if ($this->_isRest()) {
|
||||||
$json = array('matrix' => $tabs, 'scores' => $scores, 'instance-uuid' => $instanceUUID);
|
$json = array('matrix' => $tabs, 'scores' => $scores, 'instance-uuid' => $instanceUUID);
|
||||||
$this->response->type('json');
|
$this->response->type('json');
|
||||||
|
|
|
@ -450,7 +450,7 @@ class GalaxyClustersController extends AppController
|
||||||
}
|
}
|
||||||
|
|
||||||
$maxScore = count($scores) > 0 ? max(array_values($scores)) : 0;
|
$maxScore = count($scores) > 0 ? max(array_values($scores)) : 0;
|
||||||
$matrixData = $this->GalaxyCluster->Galaxy->getMatrix($mitreAttackGalaxyId);
|
$matrixData = $this->GalaxyCluster->Galaxy->getMatrix($mitreAttackGalaxyId, $scores);
|
||||||
$tabs = $matrixData['tabs'];
|
$tabs = $matrixData['tabs'];
|
||||||
$matrixTags = $matrixData['matrixTags'];
|
$matrixTags = $matrixData['matrixTags'];
|
||||||
$killChainOrders = $matrixData['killChain'];
|
$killChainOrders = $matrixData['killChain'];
|
||||||
|
|
|
@ -1964,6 +1964,7 @@ class UsersController extends AppController
|
||||||
}
|
}
|
||||||
// end FIXME
|
// end FIXME
|
||||||
|
|
||||||
|
$this->Galaxy->sortMatrixByScore($tabs, $scores);
|
||||||
if ($this->_isRest()) {
|
if ($this->_isRest()) {
|
||||||
$json = array('matrix' => $tabs, 'scores' => $scores, 'instance-uuid' => $instanceUUID);
|
$json = array('matrix' => $tabs, 'scores' => $scores, 'instance-uuid' => $instanceUUID);
|
||||||
return $this->RestResponse->viewData($json, $this->response->type());
|
return $this->RestResponse->viewData($json, $this->response->type());
|
||||||
|
|
|
@ -99,6 +99,7 @@ class AttackExport
|
||||||
$maxScore = $clusterCount;
|
$maxScore = $clusterCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$this->__GalaxyModel->sortMatrixByScore($this->__tabs, $this->__clusterCounts);
|
||||||
App::uses('ColourGradientTool', 'Tools');
|
App::uses('ColourGradientTool', 'Tools');
|
||||||
$gradientTool = new ColourGradientTool();
|
$gradientTool = new ColourGradientTool();
|
||||||
$colours = $gradientTool->createGradientFromValues($this->__clusterCounts);
|
$colours = $gradientTool->createGradientFromValues($this->__clusterCounts);
|
||||||
|
@ -114,6 +115,10 @@ class AttackExport
|
||||||
$result['colours'] = $colours['mapping'];
|
$result['colours'] = $colours['mapping'];
|
||||||
$result['interpolation'] = $colours['interpolation'];
|
$result['interpolation'] = $colours['interpolation'];
|
||||||
}
|
}
|
||||||
|
if ($this->__galaxy_id == $this->__GalaxyModel->getMitreAttackGalaxyId()) {
|
||||||
|
$result['defaultTabName'] = 'mitre-attack';
|
||||||
|
$result['removeTrailling'] = 2;
|
||||||
|
}
|
||||||
$result['galaxyName'] = $this->__galaxy_name;
|
$result['galaxyName'] = $this->__galaxy_name;
|
||||||
$result['galaxyId'] = $this->__galaxy_id;
|
$result['galaxyId'] = $this->__galaxy_id;
|
||||||
$matrixGalaxies = $this->__GalaxyModel->getAllowedMatrixGalaxies();
|
$matrixGalaxies = $this->__GalaxyModel->getAllowedMatrixGalaxies();
|
||||||
|
|
|
@ -397,7 +397,7 @@ class Galaxy extends AppModel
|
||||||
return $galaxies;
|
return $galaxies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getMatrix($galaxy_id)
|
public function getMatrix($galaxy_id, $scores=array())
|
||||||
{
|
{
|
||||||
$conditions = array('Galaxy.id' => $galaxy_id);
|
$conditions = array('Galaxy.id' => $galaxy_id);
|
||||||
$contains = array(
|
$contains = array(
|
||||||
|
@ -454,18 +454,7 @@ class Galaxy extends AppModel
|
||||||
}
|
}
|
||||||
$matrixData['tabs'] = $cols;
|
$matrixData['tabs'] = $cols;
|
||||||
|
|
||||||
foreach ($matrixData['tabs'] as $k => $v) {
|
$this->sortMatrixByScore($matrixData['tabs'], $scores);
|
||||||
foreach ($matrixData['tabs'][$k] as $kc => $v2) {
|
|
||||||
// sort clusters in the kill chains
|
|
||||||
usort(
|
|
||||||
$matrixData['tabs'][$k][$kc],
|
|
||||||
function($a, $b) {
|
|
||||||
return strcmp($a['value'], $b['value']);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #FIXME temporary fix: retreive tag name of deprecated mitre galaxies (for the stats)
|
// #FIXME temporary fix: retreive tag name of deprecated mitre galaxies (for the stats)
|
||||||
if ($galaxy['Galaxy']['id'] == $this->getMitreAttackGalaxyId()) {
|
if ($galaxy['Galaxy']['id'] == $this->getMitreAttackGalaxyId()) {
|
||||||
$names = array('Enterprise Attack - Attack Pattern', 'Pre Attack - Attack Pattern', 'Mobile Attack - Attack Pattern');
|
$names = array('Enterprise Attack - Attack Pattern', 'Pre Attack - Attack Pattern', 'Mobile Attack - Attack Pattern');
|
||||||
|
@ -486,4 +475,34 @@ class Galaxy extends AppModel
|
||||||
$matrixData['matrixTags'] = array_keys($matrixData['matrixTags']);
|
$matrixData['matrixTags'] = array_keys($matrixData['matrixTags']);
|
||||||
return $matrixData;
|
return $matrixData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function sortMatrixByScore(&$tabs, $scores)
|
||||||
|
{
|
||||||
|
foreach (array_keys($tabs) as $i) {
|
||||||
|
foreach (array_keys($tabs[$i]) as $j) {
|
||||||
|
// major ordering based on score, minor based on alphabetical
|
||||||
|
usort($tabs[$i][$j], function ($a, $b) use($scores) {
|
||||||
|
if ($a['tag_name'] == $b['tag_name']) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (isset($scores[$a['tag_name']]) && isset($scores[$b['tag_name']])) {
|
||||||
|
if ($scores[$a['tag_name']] < $scores[$b['tag_name']]) {
|
||||||
|
$ret = 1;
|
||||||
|
} else if ($scores[$a['tag_name']] == $scores[$b['tag_name']]) {
|
||||||
|
$ret = strcmp($a['value'], $b['value']);
|
||||||
|
} else {
|
||||||
|
$ret = -1;
|
||||||
|
}
|
||||||
|
} else if (isset($scores[$a['tag_name']])) {
|
||||||
|
$ret = -1;
|
||||||
|
} else if (isset($scores[$b['tag_name']])) {
|
||||||
|
$ret = 1;
|
||||||
|
} else { // none is set
|
||||||
|
$ret = strcmp($a['value'], $b['value']);
|
||||||
|
}
|
||||||
|
return $ret;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue