Merge branch 'feature-galaxy-disabled' into develop

pull/7468/head
mokaddem 2021-06-03 11:29:02 +02:00
commit 529a359690
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
5 changed files with 143 additions and 7 deletions

View File

@ -310,6 +310,8 @@ class ACLComponent extends Component
'attachCluster' => array('perm_tagger'),
'attachMultipleClusters' => array('perm_tagger'),
'delete' => array(),
'disable' => array('perm_site_admin'),
'enable' => array('perm_site_admin'),
'export' => array('*'),
'forkTree' => array('*'),
'index' => array('*'),
@ -320,6 +322,7 @@ class ACLComponent extends Component
'selectGalaxyNamespace' => array('perm_tagger'),
'selectCluster' => array('perm_tagger'),
'showGalaxies' => array('*'),
'toggle' => array('perm_site_admin'),
'update' => array(),
'view' => array('*'),
'viewGraph' => array('*'),

View File

@ -19,7 +19,7 @@ class GalaxiesController extends AppController
public function index()
{
$aclConditions = array();
$filters = $this->IndexFilter->harvestParameters(array('value'));
$filters = $this->IndexFilter->harvestParameters(array('value', 'enabled'));
$searchConditions = array();
if (empty($filters['value'])) {
$filters['value'] = '';
@ -35,6 +35,9 @@ class GalaxiesController extends AppController
)
);
}
if (isset($filters['enabled'])) {
$searchConditions[]['enabled'] = $filters['enabled'] ? 1 : 0;
}
if ($this->_isRest()) {
$galaxies = $this->Galaxy->find(
'all',
@ -51,6 +54,7 @@ class GalaxiesController extends AppController
$this->paginate['conditions']['AND'][] = $aclConditions;
$galaxies = $this->paginate();
$this->set('galaxyList', $galaxies);
$this->set('passedArgsArray', $this->passedArgs);
$this->set('searchall', $filters['value']);
}
}
@ -139,7 +143,7 @@ class GalaxiesController extends AppController
}
$result = $this->Galaxy->delete($id);
if ($result) {
$message = 'Galaxy deleted';
$message = __('Galaxy deleted');
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Galaxy', 'delete', false, $this->response->type(), $message);
} else {
@ -147,7 +151,7 @@ class GalaxiesController extends AppController
$this->redirect(array('controller' => 'galaxies', 'action' => 'index'));
}
} else {
$message = 'Could not delete Galaxy.';
$message = __('Could not delete Galaxy.');
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('Galaxy', 'delete', false, $message);
} else {
@ -156,7 +160,55 @@ class GalaxiesController extends AppController
}
}
}
public function enable($id) {
return $this->toggle($id, true);
}
public function disable($id) {
return $this->toggle($id, false);
}
public function toggle($id, $enabled=null)
{
if (Validation::uuid($id)) {
$id = $this->Toolbox->findIdByUuid($this->Galaxy, $id);
} elseif (!is_numeric($id)) {
throw new NotFoundException('Invalid galaxy.');
}
$galaxy = $this->Galaxy->find('first', array(
'recursive' => -1,
'conditions' => array('Galaxy.id' => $id)
));
if (empty($galaxy)) {
throw new NotFoundException('Invalid galaxy.');
}
if (is_null($enabled)) {
$galaxy['Galaxy']['enabled'] = !$galaxy['Galaxy']['enabled'];
} else {
$galaxy['Galaxy']['enabled'] = $enabled;
}
$result = $this->Galaxy->save($galaxy);
if ($result) {
$message = __('Galaxy enabled');
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('Galaxy', 'toggle', false, $this->response->type(), $message);
} else {
$this->Flash->success($message);
$this->redirect(array('controller' => 'galaxies', 'action' => 'index'));
}
} else {
$message = __('Could not enable Galaxy.');
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('Galaxy', 'toggle', false, $message);
} else {
$this->Flash->success($message);
$this->redirect($this->referer());
}
}
}
public function import()
{
if ($this->request->is('post') || $this->request->is('put')) {
@ -284,6 +336,9 @@ class GalaxiesController extends AppController
$local = !empty($this->params['named']['local']) ? $this->params['named']['local'] : '0';
$eventid = !empty($this->params['named']['eventid']) ? $this->params['named']['eventid'] : '0';
$conditions = $namespace === '0' ? array() : array('namespace' => $namespace);
$conditions[] = [
'enabled' => true
];
$galaxies = $this->Galaxy->find('all', array(
'recursive' => -1,
'fields' => array('MAX(Galaxy.version) as latest_version', 'id', 'kill_chain_order', 'name', 'icon', 'description'),
@ -339,6 +394,7 @@ class GalaxiesController extends AppController
$namespaces = $this->Galaxy->find('list', array(
'recursive' => -1,
'fields' => array('namespace', 'namespace'),
'conditions' => array('enabled' => 1),
'group' => array('namespace'),
'order' => array('namespace asc')
));

View File

@ -90,7 +90,7 @@ class AppModel extends Model
51 => false, 52 => false, 53 => false, 54 => false, 55 => false, 56 => false,
57 => false, 58 => false, 59 => false, 60 => false, 61 => false, 62 => false,
63 => true, 64 => false, 65 => false, 66 => false, 67 => false, 68 => false,
69 => false,
69 => false, 70 => false,
);
public $advanced_updates_description = array(
@ -1600,6 +1600,9 @@ class AppModel extends Model
INDEX `model_id` (`model_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;";
break;
case 70:
$sqlArray[] = "ALTER TABLE `galaxies` ADD `enabled` tinyint(1) NOT NULL DEFAULT 1 AFTER `namespace`;";
break;
case 'fixNonEmptySharingGroupID':
$sqlArray[] = 'UPDATE `events` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';
$sqlArray[] = 'UPDATE `attributes` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';

View File

@ -5,6 +5,26 @@
'data' => $galaxyList,
'top_bar' => array(
'children' => array(
array(
'type' => 'simple',
'children' => array(
array(
'url' => $baseurl . '/galaxies/index',
'text' => __('All'),
'active' => !isset($passedArgsArray['enabled']),
),
array(
'url' => $baseurl . '/galaxies/index/enabled:1',
'text' => __('Enabled'),
'active' => isset($passedArgsArray['enabled']) && $passedArgsArray['enabled'] === "1",
),
array(
'url' => $baseurl . '/galaxies/index/enabled:0',
'text' => __('Disabled'),
'active' => isset($passedArgsArray['enabled']) && $passedArgsArray['enabled'] === "0",
)
)
),
array(
'type' => 'search',
'button' => __('Filter'),
@ -52,7 +72,14 @@
array(
'name' => __('Description'),
'data_path' => 'Galaxy.description',
)
),
array(
'name' => __('Enabled'),
'element' => 'boolean',
'sort' => 'enabled',
'class' => 'short',
'data_path' => 'Galaxy.enabled',
),
),
'title' => __('Galaxy index'),
'actions' => array(
@ -64,6 +91,42 @@
'icon' => 'eye',
'dbclickAction' => true
),
array(
'title' => __('Enable'),
'icon' => 'play',
'postLink' => true,
'url' => $baseurl . '/galaxies/enable',
'url_params_data_paths' => ['Galaxy.id'],
'postLinkConfirm' => __('Are you sure you want to enable this galaxy library?'),
'complex_requirement' => array(
'function' => function ($row, $options) use ($isSiteAdmin) {
return $isSiteAdmin && !$options['datapath']['enabled'];
},
'options' => array(
'datapath' => array(
'enabled' => 'Galaxy.enabled'
)
)
),
),
array(
'title' => __('Disable'),
'icon' => 'stop',
'postLink' => true,
'url' => $baseurl . '/galaxies/disable',
'url_params_data_paths' => ['Galaxy.id'],
'postLinkConfirm' => __('Are you sure you want to disable this galaxy library?'),
'complex_requirement' => array(
'function' => function ($row, $options) use ($isSiteAdmin) {
return $isSiteAdmin && $options['datapath']['enabled'];
},
'options' => array(
'datapath' => array(
'enabled' => 'Galaxy.enabled'
)
)
),
),
array(
'url' => '/galaxies/delete',
'url_params_data_paths' => array(

View File

@ -2460,6 +2460,17 @@
"column_default": "misp",
"extra": ""
},
{
"column_name": "enabled",
"is_nullable": "NO",
"data_type": "tinyint",
"character_maximum_length": null,
"numeric_precision": "3",
"collation_name": null,
"column_type": "tinyint(1)",
"column_default": "1",
"extra": ""
},
{
"column_name": "kill_chain_order",
"is_nullable": "YES",
@ -8158,5 +8169,5 @@
"id": true
}
},
"db_version": "69"
"db_version": "70"
}