Merge branch '2.4' of github.com:MISP/MISP into 2.4

pull/4033/head
iglocska 2019-01-18 15:54:04 +01:00
commit e1716ac738
8 changed files with 155 additions and 87 deletions

View File

@ -1590,7 +1590,8 @@ class AttributesController extends AppController
$tagItemsRemove = array();
foreach ($tags as $k => $tag) {
$tagName = $tag['name'];
$tagItemsRemove[h($tagName)] = array(
$tagItemsRemove[] = array(
'name' => h($tagName),
'value' => h($tag['id']),
'template' => $tagTemplate,
'templateData' => array(
@ -1622,7 +1623,8 @@ class AttributesController extends AppController
$optionName = h($cluster['value']);
$optionName .= $cluster['synonyms_string'] !== '' ? ' (' . h($cluster['synonyms_string']) . ')' : '';
$clusterItemsRemove[$optionName] = array(
$clusterItemsRemove[] = array(
'name' => $optionName,
'value' => h($cluster['id']),
'additionalData' => array(
'event_id' => h($id),
@ -1651,7 +1653,8 @@ class AttributesController extends AppController
$tagItemsAdd = array();
foreach ($tags as $k => $tag) {
$tagName = $tag['name'];
$tagItemsAdd[h($tagName)] = array(
$tagItemsAdd[] = array(
'name' => h($tagName),
'value' => h($tag['id']),
'template' => $tagTemplate,
'templateData' => array(
@ -1671,7 +1674,10 @@ class AttributesController extends AppController
));
$clusterItemsAdd = array();
foreach ($clusters as $k => $cluster) {
$clusterItemsAdd[$cluster['GalaxyCluster']['value']] = $cluster['GalaxyCluster']['id'];
$clusterItemsAdd[] = array(
'name' => $cluster['GalaxyCluster']['value'],
'value' => $cluster['GalaxyCluster']['id']
);
}
unset($clusters);

View File

@ -107,7 +107,10 @@ class GalaxiesController extends AppController
}
$items = array();
$items[__('All clusters')] = "/galaxies/selectCluster/" . h($target_id) . '/' . h($target_type) . '/0';
$items[] = array(
'name' => __('All clusters'),
'value' => "/galaxies/selectCluster/" . h($target_id) . '/' . h($target_type) . '/0'
);
foreach ($galaxies as $galaxy) {
if ($galaxy['Galaxy']['id'] != -1) {
// construct option template
@ -119,7 +122,8 @@ class GalaxiesController extends AppController
$galaxyTemplate .= '<it class="fa fa-info-circle" style="float:right;" title="{{=it.description}}"></it>';
}
$items[$galaxy['Galaxy']['name']] = array(
$items[] = array(
'name' => h($galaxy['Galaxy']['name']),
'value' => "/galaxies/selectCluster/" . h($target_id) . '/' . h($target_type) . '/' . h($galaxy['Galaxy']['id']),
'template' => $galaxyTemplate,
'templateData' => array(
@ -129,7 +133,8 @@ class GalaxiesController extends AppController
)
);
} else { // attackMatrix
$items[$galaxy['Galaxy']['name']] = array(
$items[] = array(
'name' => $galaxy['Galaxy']['name'],
'functionName' => "getMitreMatrixPopup('" . h($target_type) . "', '" . h($target_id) . "')",
'isPill' => true,
'img' => "/img/mitre-attack-icon.ico",
@ -150,9 +155,15 @@ class GalaxiesController extends AppController
));
$items = array();
$items[__('All namespaces')] = "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/0';
$items[] = array(
'name' => __('All namespaces'),
'value' => "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/0'
);
foreach ($namespaces as $namespace) {
$items[h($namespace)] = "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/' . h($namespace);
$items[] = array(
'name' => h($namespace),
'value' => "/galaxies/selectGalaxy/" . h($target_id) . '/' . h($target_type) . '/' . h($namespace)
);
}
$this->set('items', $items);
@ -212,7 +223,8 @@ class GalaxiesController extends AppController
$name = h($cluster['value']);
$optionName = h($cluster['value']);
$optionName .= $cluster['synonyms_string'] !== '' ? ' (' . h($cluster['synonyms_string']) . ')' : '';
$items[$optionName] = array(
$items[] = array(
'name' => $optionName,
'value' => h($cluster_id),
'title' => $title,
'additionalData' => array(

View File

@ -17,12 +17,44 @@ class ObjectTemplatesController extends AppController
'recursive' => -1
);
public function objectMetaChoice($event_id) {
$metas = $this->ObjectTemplate->find('list', array(
'recursive' => -1,
'conditions' => array('ObjectTemplate.active' => 1),
'fields' => array('meta-category'),
'group' => array('ObjectTemplate.meta-category'),
'order' => array('ObjectTemplate.meta-category asc')
));
$items = array();
$items[] = array(
'name' => __('All Objects'),
'value' => "/ObjectTemplates/objectChoice/" . h($event_id) . "/" . "0"
);
foreach($metas as $meta) {
$items[] = array(
'name' => $meta,
'value' => "/ObjectTemplates/objectChoice/" . h($event_id) . "/" . h($meta)
);
}
$this->set('items', $items);
$this->set('options', array(
'multiple' => 0,
));
$this->render('/Elements/generic_picker');
}
public function objectChoice($event_id, $category=false)
{
$this->ObjectTemplate->populateIfEmpty($this->Auth->user());
$conditions = array('ObjectTemplate.active' => 1);
if ($category !== false && $category !== "0") {
$conditions['meta-category'] = $category;
}
$templates_raw = $this->ObjectTemplate->find('all', array(
'recursive' => -1,
'conditions' => array('ObjectTemplate.active' => 1),
'conditions' => $conditions,
'fields' => array('id', 'meta-category', 'name', 'description', 'org_id'),
'contain' => array('Organisation.name'),
'order' => array('ObjectTemplate.name asc')
@ -39,7 +71,8 @@ class ObjectTemplatesController extends AppController
}
$chosenTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; margin-top: 5px; font-size: smaller;"><i>{{=it.metacateg}}</i></div>';
$items[$template['name']] = array(
$items[] = array(
'name' => $template['name'],
'value' => $template['id'],
'additionalData' => array('event_id' => h($event_id)),
'template' => $chosenTemplate,

View File

@ -576,19 +576,31 @@ class TagsController extends AppController
$items = array();
$favourites = $this->Tag->FavouriteTag->find('count', array('conditions' => array('FavouriteTag.user_id' => $this->Auth->user('id'))));
if ($favourites) {
$items[__('Favourite Tags')] = "/tags/selectTag/" . h($id) . "/favourites/" . h($scope);
$items[] = array(
'name' => __('Favourite Tags'),
'value' => "/tags/selectTag/" . h($id) . "/favourites/" . h($scope)
);
}
if ($scope !== 'tag_collection') {
$items[__('Tag Collections')] = "/tags/selectTag/" . h($id) . "/collections/" . h($scope);
$items[] = array(
'name' => __('Tag Collections'),
'value' => "/tags/selectTag/" . h($id) . "/collections/" . h($scope)
);
}
$items[__('All Tags')] = "/tags/selectTag/" . h($id) . "/all/" . h($scope);
$items[] = array(
'name' => __('All Tags'),
'value' => "/tags/selectTag/" . h($id) . "/all/" . h($scope)
);
$this->loadModel('Taxonomy');
$options = $this->Taxonomy->find('list', array('conditions' => array('enabled' => true), 'fields' => array('namespace'), 'order' => array('Taxonomy.namespace ASC')));
foreach ($options as $k => $option) {
$tags = $this->Taxonomy->getTaxonomyTags($k, false, true);
if (!empty($tags)) {
$items[__('Taxonomy Library') . ":" . h($option)] = "/tags/selectTag/" . h($id) . "/" . h($k) . "/" . h($scope);
$items[] = array(
'name' => __('Taxonomy Library') . ":" . h($option),
'value' => "/tags/selectTag/" . h($id) . "/" . h($k) . "/" . h($scope)
);
}
}
$this->set('items', $items);
@ -668,9 +680,13 @@ class TagsController extends AppController
$conditions = array('Tag.user_id' => array(0, $this->Auth->user('id')));
$conditions['Tag.hide_tag'] = 0;
$allTags = $this->Tag->find('all', array('conditions' => $conditions, 'recursive' => -1));
$allTags = $this->Tag->EventTag->Event->massageTags(array('EventTag' => $allTags), 'Event', false);
$allTags = $allTags['EventTag'];
$tags = array();
foreach ($allTags as $i => $tag) {
$tags[$tag['Tag']['id']] = $tag['Tag'];
if (!empty($tag['Tag'])) {
$tags[$tag['Tag']['id']] = $tag['Tag'];
}
}
unset($allTags);
$expanded = $tags;
@ -737,7 +753,8 @@ class TagsController extends AppController
$tagTemplate .= '<div class="apply_css_arrow" style="padding-left: 5px; margin-top: 5px; font-size: smaller;"><i>{{=it.includes}}</i></div>';
}
$items[h($tagName)] = array(
$itemParam = array(
'name' => h($tagName),
'value' => h($choice_id),
'additionalData' => array(
'id' => h($id)
@ -752,8 +769,9 @@ class TagsController extends AppController
);
if ($taxonomy_id === 'collections') {
$TagCollectionTag = __('Includes: ') . h($inludedTagListString[$tag['id']]);
$items[h($tagName)]['templateData']['includes'] = $TagCollectionTag;
$itemParam['templateData']['includes'] = $TagCollectionTag;
}
$items[] = $itemParam;
}
$this->set('items', $items);
$this->set('options', array( // set chosen (select picker) options

View File

@ -3,7 +3,7 @@
* Generic select picker
*/
/** Config **/
$select_threshold = 6; // threshold above which pills will be replace by a select (unused if multiple is > 1)
$select_threshold = 7; // threshold above which pills will be replace by a select (unused if multiple is > 1)
$defaults_options = array(
'select_options' => array(
// 'multiple' => '', // set to add possibility to pick multiple options in the select
@ -65,8 +65,13 @@ function setupChosen(id, redrawChosen) {
} else { // for obscure reasons, `selected` variable is not set in some cases
endpoint = $(event.target).val();
}
$select.data('endpoint', endpoint);
fetchRequestedData($select);
if (endpoint === '') {
$wrapper = $select.closest('div').find('div.generic-picker-wrapper');
$wrapper.hide(0);
} else {
$select.data('endpoint', endpoint);
fetchRequestedData($select);
}
}
});
}
@ -180,12 +185,12 @@ function submitFunction(clicked, callback) {
<select id="<?php echo $select_id; ?>" style="height: 100px; margin-bottom: 0px;" <?php echo h($this->GenericPicker->add_select_params($defaults)); ?>>
<option></option>
<?php
foreach ($items as $name => $param) {
foreach ($items as $k => $param) {
if (isset($param['isPill']) && $param['isPill']) {
$flag_addPills = true;
continue;
} else {
echo $this->GenericPicker->add_option($name, $param, $defaults);
echo $this->GenericPicker->add_option($param, $defaults);
}
}
?>
@ -196,9 +201,9 @@ function submitFunction(clicked, callback) {
<?php if ($flag_addPills): // add forced pills ?>
<ul class="nav nav-pills">
<?php foreach ($items as $name => $param): ?>
<?php foreach ($items as $k => $param): ?>
<?php if (isset($param['isPill']) && $param['isPill']): ?>
<?php echo $this->GenericPicker->add_pill($name, $param, $defaults); ?>
<?php echo $this->GenericPicker->add_pill($param, $defaults); ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
@ -212,8 +217,8 @@ function submitFunction(clicked, callback) {
<?php elseif (count($items) > 0): ?>
<ul class="nav nav-pills">
<?php foreach ($items as $name => $param): ?>
<?php echo $this->GenericPicker->add_pill($name, $param, $defaults); ?>
<?php foreach ($items as $k => $param): ?>
<?php echo $this->GenericPicker->add_pill($param, $defaults); ?>
<?php endforeach; ?>
</ul>
<?php else: ?>

View File

@ -54,7 +54,7 @@
'text' => __('Add Attribute')
));
echo '<li>';
echo '<a href="#" onclick="popoverPopup(this, ' . h($event['Event']['id']) . ', \'objectTemplates\', \'objectChoice\')"> ' . __('Add Object') . '</a>';
echo '<a href="#" onclick="popoverPopup(this, ' . h($event['Event']['id']) . ', \'objectTemplates\', \'objectMetaChoice\')"> ' . __('Add Object') . '</a>';
echo '</li>';
echo $this->element('/side_menu_link', array(
'element_id' => 'addAttachment',

View File

@ -16,81 +16,74 @@ class GenericPickerHelper extends AppHelper {
return $select_html;
}
function add_option($name, $param, $defaults) {
function add_option($param, $defaults) {
$option_html = '<option';
if (is_array($param)) {
if (isset($param['value'])) {
$option_html .= ' value=' . h($param['value']);
} else {
$option_html .= ' value=' . h($name);
}
if (isset($param['additionalData'])) {
$additionalData = json_encode($param['additionalData']);
} else {
$additionalData = json_encode(array());
}
if (isset($param['template'])) {
$option_html .= ' data-template=' . base64_encode($param['template']);
}
if (isset($param['templateData'])) {
$option_html .= ' data-templatedata=' . base64_encode(json_encode($param['templateData']));
}
$option_html .= ' data-additionaldata=' . $additionalData;
if (isset($param['disabled']) && $param['disabled']) {
$option_html .= ' disabled';
} else if (isset($param['selected']) && $param['selected']) { // nonsense to pre-select if disabled
$option_html .= ' selected';
}
if (isset($param['value'])) {
$option_html .= ' value=' . h($param['value']);
} else {
$option_html .= ' value=' . h($param);
$option_html .= ' value=' . h($param['name']);
}
if (isset($param['additionalData'])) {
$additionalData = json_encode($param['additionalData']);
} else {
$additionalData = json_encode(array());
}
if (isset($param['template'])) {
$option_html .= ' data-template=' . base64_encode($param['template']);
}
if (isset($param['templateData'])) {
$option_html .= ' data-templatedata=' . base64_encode(json_encode($param['templateData']));
}
$option_html .= ' data-additionaldata=' . $additionalData;
if (isset($param['disabled']) && $param['disabled']) {
$option_html .= ' disabled';
} else if (isset($param['selected']) && $param['selected']) { // nonsense to pre-select if disabled
$option_html .= ' selected';
}
$option_html .= '>';
$option_html .= h($name);
$option_html .= h($param['name']);
$option_html .= '</option>';
return $option_html;
}
function add_link_params($name, $param, $defaults=array()) {
function add_link_params($param, $defaults=array()) {
$param_html = ' ';
if (is_array($param)) { // add data as param
if (isset($param['functionName'])) {
$param_html .= 'onclick="execAndClose(this, ' . $param['functionName'] . ')" ';
} else { // fallback to default submit function
if ($defaults['functionName'] !== '') {
$param_html .= 'onclick="submitFunction(this, ' . $defaults['functionName'] . ')" ';
} else {
$param_html .= 'data-endpoint="' . h($param['value']) . '" ';
$param_html .= 'onclick="fetchRequestedData(this)" ';
}
if (isset($param['functionName'])) {
$param_html .= 'onclick="execAndClose(this, ' . $param['functionName'] . ')" ';
} else { // fallback to default submit function
if ($defaults['functionName'] !== '') {
$param_html .= 'onclick="submitFunction(this, ' . $defaults['functionName'] . ')" ';
} else {
$param_html .= 'data-endpoint="' . h($param['value']) . '" ';
$param_html .= 'onclick="fetchRequestedData(this)" ';
}
$additionalData = json_encode(array());
foreach ($param as $paramName => $paramValue) {
if ($paramName === 'additionalData') {
$additionalData = json_encode($param['additionalData']);
} else if ($paramName === 'value') {
$param_html .= 'value="' . h($paramValue) . '" ';
} else if ($paramName === 'template' || $paramName === 'templateData') {
continue;
} else {
$param_html .= 'data-' . h($paramName). '="' . h($paramValue) . '" ';
}
}
$param_html .= ' data-additionaldata=' . $additionalData;
} else { // param is a simple endpoint from which fetch data
$param_html .= 'data-endpoint="' . h($param) . '" ';
$param_html .= 'onclick="fetchRequestedData(this)" ';
}
$additionalData = json_encode(array());
foreach ($param as $paramName => $paramValue) {
if ($paramName === 'additionalData') {
$additionalData = json_encode($param['additionalData']);
} else if ($paramName === 'value') {
$param_html .= 'value="' . h($paramValue) . '" ';
} else if ($paramName === 'template' || $paramName === 'templateData') {
continue;
} else {
$param_html .= 'data-' . h($paramName). '="' . h($paramValue) . '" ';
}
}
$param_html .= ' data-additionaldata=' . $additionalData;
return $param_html;
}
function add_pill($name, $param, $defaults=array()) {
function add_pill($param, $defaults=array()) {
$pill_html = '<li>';
$pill_html .= '<a href="#" data-toggle="pill" class="pill-pre-picker"';
$pill_html .= ' ' . $this->add_link_params($name, $param, $defaults);
$pill_html .= ' ' . $this->add_link_params($param, $defaults);
$pill_html .= '>';
if (isset($param['img'])) {
$pill_html .= '<img src="' . $param['img'] . '" style="margin-right: 5px; height: 14px;">';
@ -98,7 +91,7 @@ class GenericPickerHelper extends AppHelper {
$icon = isset($param['icon']) ? $param['icon'] : $param['templateData']['icon'];
$pill_html .= '<span class="fa fa-' . $icon . '" style="margin-right: 5px;"></span>';
}
$pill_html .= h($name) . '</a>';
$pill_html .= h($param['name']) . '</a>';
$pill_html .= '</li>';
return $pill_html;
}

View File

@ -275,6 +275,7 @@
function pickCell(cell, clusterId, recurseChosen) {
recurseChosen = recurseChosen === undefined ? true : recurseChosen;
clusterId = parseInt(clusterId);
var $cells = $('td[data-cluster-id="' + clusterId + '"]');
if (!cell.hasClass('cell-picked')) {