new: [clusterBlocklist] Added initial blocklist similar to the event one

pull/6120/head
mokaddem 2020-07-13 11:14:56 +02:00
parent 1333dea1fe
commit 724de8a759
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
5 changed files with 271 additions and 0 deletions

View File

@ -0,0 +1,92 @@
<?php
App::uses('AppController', 'Controller');
class GalaxyClusterBlocklistsController extends AppController
{
public $components = array('Session', 'RequestHandler', 'BlackList');
public $paginate = array(
'limit' => 60,
'maxLimit' => 9999, // LATER we will bump here on a problem once we have more than 9999 clusters <- no we won't, this is the max a user van view/page.
'order' => array(
'GalaxyClusterBlocklist.created' => 'DESC'
),
);
public function index()
{
$passedArgsArray = array();
$passedArgs = $this->passedArgs;
$params = array();
$validParams = array('cluster_uuid', 'comment', 'cluster_info', 'cluster_orgc');
foreach ($validParams as $validParam) {
if (!empty($this->params['named'][$validParam])) {
$params[$validParam] = $this->params['named'][$validParam];
}
}
if (!empty($this->params['named']['searchall'])) {
$params['AND']['OR'] = array(
'cluster_uuid' => $this->params['named']['searchall'],
'comment' => $this->params['named']['searchall'],
'cluster_info' => $this->params['named']['searchall'],
'cluster_orgc' => $this->params['named']['searchall']
);
}
$this->set('passedArgs', json_encode($passedArgs));
$this->set('passedArgsArray', $passedArgsArray);
$this->BlackList->index($this->_isRest(), $params);
}
public function add()
{
$this->BlackList->add($this->_isRest());
}
public function edit($id)
{
$this->BlackList->edit($this->_isRest(), $id);
}
public function delete($id)
{
$this->BlackList->delete($this->_isRest(), $id);
}
public function massDelete()
{
if ($this->request->is('post') || $this->request->is('put')) {
if (!isset($this->request->data['GalaxyClusterBlocklist'])) {
$this->request->data = array('GalaxyClusterBlocklist' => $this->request->data);
}
$ids = $this->request->data['GalaxyClusterBlocklist']['ids'];
$cluster_ids = json_decode($ids, true);
if (empty($cluster_ids)) {
throw new NotFoundException(__('Invalid cluster IDs.'));
}
$result = $this->GalaxyClusterBlocklist->deleteAll(array('GalaxyClusterBlocklist.id' => $cluster_ids));
if ($result) {
if ($this->_isRest()) {
return $this->RestResponse->saveSuccessResponse('GalaxyClusterBlocklist', 'Deleted', $ids, $this->response->type());
} else {
$this->Flash->success('Blacklist entry removed');
$this->redirect(array('controller' => 'GalaxyClusterBlocklist', 'action' => 'index'));
}
} else {
$error = __('Failed to delete GalaxyCluster from GalaxyClusterBlocklist. Error: ') . PHP_EOL . h($result);
if ($this->_isRest()) {
return $this->RestResponse->saveFailResponse('GalaxyClusterBlocklist', 'Deleted', false, $error, $this->response->type());
} else {
$this->Flash->error($error);
$this->redirect(array('controller' => 'galaxyClusterBlocklists', 'action' => 'index'));
}
}
} else {
$ids = json_decode($this->request->query('ids'), true);
if (empty($ids)) {
throw new NotFoundException(__('Invalid cluster IDs.'));
}
$this->set('cluster_ids', $ids);
}
}
}

View File

@ -1414,8 +1414,10 @@ class AppModel extends Model
$sqlArray[] = "ALTER TABLE `galaxy_clusters` ADD `extends_version` int(11) DEFAULT 0;";
$sqlArray[] = "ALTER TABLE `galaxy_clusters` ADD `published` tinyint(1) NOT NULL DEFAULT 0;";
$sqlArray[] = "ALTER TABLE `roles` ADD `perm_galaxy_editor` tinyint(1) NOT NULL DEFAULT 0;";
$sqlArray[] = "UPDATE `roles` SET `perm_galaxy_editor`=1 WHERE `perm_tag_editor`=1;";
$sqlArray[] = "UPDATE `galaxy_clusters` SET `distribution`=3, `default`=1 WHERE `org_id`=0;";
$sqlArray[] = "ALTER TABLE `galaxy_reference` RENAME `galaxy_cluster_relations`;";
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `galaxy_cluster_uuid` varchar(40) COLLATE utf8_bin NOT NULL;";
$sqlArray[] = "ALTER TABLE `galaxy_cluster_relations` ADD `distribution` tinyint(4) NOT NULL DEFAULT 0;";
@ -1428,12 +1430,25 @@ class AppModel extends Model
`tag_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$sqlArray[] = "ALTER TABLE `tags` ADD `is_galaxy` tinyint(1) NOT NULL DEFAULT 0;";
$sqlArray[] = "ALTER TABLE `tags` ADD `is_custom_galaxy` tinyint(1) NOT NULL DEFAULT 0;";
$sqlArray[] = "UPDATE `tags` SET `is_galaxy`=1 WHERE `name` LIKE 'misp-galaxy:%';";
$sqlArray[] = "UPDATE `tags` SET `is_custom_galaxy`=1 WHERE `name` REGEXP '^misp-galaxy:[^:=\"]+=\"[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\"$';";
$sqlArray[] = "ALTER TABLE `servers` ADD `push_galaxy_clusters` tinyint(1) NOT NULL DEFAULT 0 AFTER `push_sightings`;";
$sqlArray[] = "ALTER TABLE `servers` ADD `pull_galaxy_clusters` tinyint(1) NOT NULL DEFAULT 0 AFTER `push_galaxy_clusters`;";
$sqlArray[] = "CREATE TABLE IF NOT EXISTS `galaxy_cluster_blocklists` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`cluster_uuid` varchar(40) COLLATE utf8_bin NOT NULL,
`created` datetime NOT NULL,
`cluster_info` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`comment` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci,
`cluster_orgc` VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;";
$indexArray[] = array('galaxy_clusters', 'org_id');
$indexArray[] = array('galaxy_clusters', 'orgc_id');
$indexArray[] = array('galaxy_clusters', 'sharing_group_id');
@ -1445,6 +1460,8 @@ class AppModel extends Model
$indexArray[] = array('galaxy_cluster_relations', 'default');
$indexArray[] = array('galaxy_cluster_relation_tags', 'galaxy_cluster_relation_id');
$indexArray[] = array('galaxy_cluster_relation_tags', 'tag_id');
$indexArray[] = array('galaxy_cluster_blocklists', 'cluster_uuid');
$indexArray[] = array('galaxy_cluster_blocklists', 'cluster_orgc');
break;
case 'fixNonEmptySharingGroupID':
$sqlArray[] = 'UPDATE `events` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';

View File

@ -0,0 +1,44 @@
<?php
App::uses('AppModel', 'Model');
class GalaxyClusterBlocklist extends AppModel
{
public $useTable = 'galaxy_cluster_blocklists';
public $recursive = -1;
public $actsAs = array(
'SysLogLogable.SysLogLogable' => array( // TODO Audit, logable
'userModel' => 'User',
'userKey' => 'user_id',
'change' => 'full'),
'Containable',
);
public $blocklistFields = array('cluster_uuid', 'comment', 'cluster_info', 'cluster_orgc');
public $validate = array(
'cluster_uuid' => array(
'unique' => array(
'rule' => 'isUnique',
'message' => 'Galaxy Cluster already blocklisted.'
),
'uuid' => array(
'rule' => array('uuid'),
'message' => 'Please provide a valid UUID'
),
)
);
public function beforeValidate($options = array())
{
parent::beforeValidate();
$date = date('Y-m-d H:i:s');
if (empty($this->data['GalaxyClusterBlocklist']['id'])) {
$this->data['GalaxyClusterBlocklist']['date_created'] = $date;
}
if (empty($this->data['GalaxyClusterBlocklist']['comment'])) {
$this->data['GalaxyClusterBlocklist']['comment'] = '';
}
return true;
}
}

View File

@ -1150,6 +1150,13 @@
'url' => '/galaxies/index',
'text' => __('List Galaxies')
));
if ($isSiteAdmin) {
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'index_blocklist',
'url' => '/galaxy_cluster_blocklists/index',
'text' => __('List Cluster Blocklists')
));
}
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'url' => '/galaxy_cluster_relations/index',
'text' => __('List Relationships')
@ -1291,6 +1298,13 @@
'url' => '/galaxies/index',
'text' => __('List Galaxies')
));
if ($isSiteAdmin) {
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'index',
'url' => '/galaxy_cluster_blocklists/index',
'text' => __('List Cluster Blocklists')
));
}
echo $this->element('/genericElements/SideMenu/side_menu_link', array(
'element_id' => 'index',
'url' => '/galaxy_cluster_relations/index',

View File

@ -0,0 +1,104 @@
<?php
echo '<div class="index">';
echo $this->element('/genericElements/IndexTable/index_table', array(
'data' => array(
'data' => $response,
'top_bar' => array(
'children' => array(
array(
'type' => 'simple',
'children' => array(
array(
'url' => sprintf('%s/galaxy_cluster_blocklists/add/', $baseurl),
'text' => __('+ Add entry to blocklist'),
),
)
),
array(
'type' => 'search',
'button' => __('Filter'),
'placeholder' => __('Enter value to search'),
'data' => '',
'searchKey' => 'searchall'
)
)
),
'fields' => array(
array(
'name' => __('Id'),
'sort' => 'id',
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.id',
),
array(
'name' => __('Org'),
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.cluster_orgc',
),
array(
'name' => __('Galaxy Cluster UUID'),
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.cluster_uuid',
),
array(
'name' => __('Created'),
'sort' => 'type',
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.created',
),
array(
'name' => __('Cluster info'),
'sort' => 'type',
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.cluster_info',
),
array(
'name' => __('Comment'),
'sort' => 'type',
'class' => 'short',
'data_path' => 'GalaxyClusterBlocklist.comment',
),
),
'title' => __('Galaxy Cluster Blocklist Index'),
'description' => __('List all galaxy clusters that will be prevented to be created (also via synchronization) on this instance'),
'actions' => array(
array(
'title' => 'Edit',
'url' => '/galaxy_cluster_blocklists/edit',
'url_params_data_paths' => array(
'GalaxyClusterBlocklist.id'
),
'icon' => 'edit',
),
array(
'title' => 'Delete',
'url' => '/galaxy_cluster_blocklists/delete',
'url_params_data_paths' => array(
'GalaxyClusterBlocklist.id'
),
'postLink' => true,
'postLinkConfirm' => __('Are you sure you want to delete the entry?'),
'icon' => 'trash'
),
)
)
));
echo '</div>';
echo $this->element('/genericElements/SideMenu/side_menu', array('menuList' => 'galaxies', 'menuItem' => 'index_blocklist'));
?>
<script type="text/javascript">
var passedArgsArray = <?php echo $passedArgs; ?>;
if (passedArgsArray['context'] === undefined) {
passedArgsArray['context'] = 'pending';
}
$(document).ready(function() {
$('#quickFilterButton').click(function() {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
});
$('#quickFilterField').on('keypress', function (e) {
if(e.which === 13) {
runIndexQuickFilter('/context:' + passedArgsArray['context']);
}
});
});
</script>