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

pull/7255/head
iglocska 2021-03-24 21:49:21 +01:00
commit d91f70377d
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
21 changed files with 109 additions and 25 deletions

View File

@ -169,17 +169,25 @@ class AdminShell extends AppShell
} }
} }
# FIXME: Make Taxonomy->update() return a status string on API if successful
public function updateTaxonomies() public function updateTaxonomies()
{ {
$this->ConfigLoad->execute(); $this->ConfigLoad->execute();
$result = $this->Taxonomy->update(); $result = $this->Taxonomy->update();
if ($result) { $successes = count(!empty($result['success']) ? $result['success'] : []);
echo 'Taxonomies updated' . PHP_EOL; $fails = count(!empty($result['fails']) ? $result['fails'] : []);
} else { $message = '';
echo 'Could not update Taxonomies' . PHP_EOL; if ($successes == 0 && $fails == 0) {
$message = __('All taxonomies are up to date already.');
} elseif ($successes == 0 && $fails > 0) {
$message = __('Could not update any of the taxonomies.');
} elseif ($successes > 0 ) {
$message = __('Successfully updated %s taxonomies.', $successes);
if ($fails != 0) {
$message .= __(' However, could not update %s taxonomies.', $fails);
} }
} }
echo $message . PHP_EOL;
}
public function updateWarningLists() public function updateWarningLists()
{ {

View File

@ -2714,15 +2714,15 @@ class AttributesController extends AppController
} else { } else {
$attribute = $attributes[0]; $attribute = $attributes[0];
} }
if (!$this->__canModifyTag($attribute, $local)) {
$fails++;
continue;
}
$eventId = $attribute['Attribute']['event_id']; $eventId = $attribute['Attribute']['event_id'];
$event = $this->Attribute->Event->find('first', array( $event = $this->Attribute->Event->find('first', array(
'conditions' => array('Event.id' => $eventId), 'conditions' => array('Event.id' => $eventId),
'recursive' => -1 'recursive' => -1
)); ));
if (!$this->__canModifyTag($event, $local)) {
$fails++;
continue;
}
if (!$this->_isRest()) { if (!$this->_isRest()) {
$this->Attribute->Event->insertLock($this->Auth->user(), $eventId); $this->Attribute->Event->insertLock($this->Auth->user(), $eventId);
} }

View File

@ -727,6 +727,7 @@ class ACLComponent extends Component
), ),
'eventGraph' => array( 'eventGraph' => array(
'view' => array('*'), 'view' => array('*'),
'viewPicture' => array('*'),
'add' => array('perm_add'), 'add' => array('perm_add'),
'delete' => array('perm_modify'), 'delete' => array('perm_modify'),
) )

View File

@ -50,6 +50,37 @@ class EventGraphController extends AppController
return $this->RestResponse->viewData($eventGraphs, $this->response->type()); return $this->RestResponse->viewData($eventGraphs, $this->response->type());
} }
public function viewPicture($event_id, $graph_id)
{
$this->loadModel('Event');
$event = $this->Event->fetchSimpleEvent($this->Auth->user(), $event_id);
if (empty($event)) {
throw new NotFoundException('Invalid event');
}
$conditions = [
'EventGraph.event_id' => $event['Event']['id'],
'EventGraph.org_id' => $this->Auth->user('org_id'),
'EventGraph.id' => $graph_id,
];
$eventGraph = $this->EventGraph->find('first', array(
'conditions' => $conditions,
'contain' => array(
'User' => array(
'fields' => array(
'User.email'
)
)
)
));
if (empty($eventGraph)) {
throw new MethodNotAllowedException('Invalid event graph');
}
$eventGraph = $eventGraph;
$imageData = $this->EventGraph->getPictureData($eventGraph);
return new CakeResponse(array('body' => $imageData, 'type' => 'png'));
}
public function add($event_id = false) public function add($event_id = false)
{ {
if ($this->request->is('get')) { if ($this->request->is('get')) {

View File

@ -4252,7 +4252,7 @@ class Attribute extends AppModel
'tags' => array('function' => 'set_filter_tags', 'pop' => true), 'tags' => array('function' => 'set_filter_tags', 'pop' => true),
'uuid' => array('function' => 'set_filter_uuid'), 'uuid' => array('function' => 'set_filter_uuid'),
'deleted' => array('function' => 'set_filter_deleted'), 'deleted' => array('function' => 'set_filter_deleted'),
'timestamp' => array('function' => 'set_filter_timestamp'), 'timestamp' => array('function' => 'set_filter_timestamp', 'pop' => true),
'attribute_timestamp' => array('function' => 'set_filter_timestamp'), 'attribute_timestamp' => array('function' => 'set_filter_timestamp'),
'first_seen' => array('function' => 'set_filter_seen'), 'first_seen' => array('function' => 'set_filter_seen'),
'last_seen' => array('function' => 'set_filter_seen'), 'last_seen' => array('function' => 'set_filter_seen'),

View File

@ -3077,6 +3077,9 @@ class Event extends AppModel
); );
foreach ($filters[$options['filter']] as $f) { foreach ($filters[$options['filter']] as $f) {
$conditions = $this->Attribute->setTimestampConditions($params[$options['filter']], $conditions, $f); $conditions = $this->Attribute->setTimestampConditions($params[$options['filter']], $conditions, $f);
if (!empty($options['pop'])) {
unset($params[$options['filter']]);
}
} }
} }
return $conditions; return $conditions;

View File

@ -53,4 +53,18 @@ class EventGraph extends AppModel
} }
return true; return true;
} }
public function getPictureData($eventGraph)
{
$b64 = str_replace('data:image/png;base64,', '', $eventGraph['EventGraph']['preview_img']);
$imageDecoded = base64_decode($b64);
$source = imagecreatefromstring($imageDecoded);
imagesavealpha($source, true);
ob_start();
imagepng($source, null, 9);
$imageData = ob_get_contents();
ob_end_clean();
imagedestroy($source);
return $imageData;
}
} }

View File

@ -5,7 +5,8 @@
array( array(
'attributeId' => $attributeId, 'attributeId' => $attributeId,
'tags' => $attributeTags, 'tags' => $attributeTags,
'tagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id']), 'tagAccess' => ($isSiteAdmin || $mayModify),
'localTagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id'] || (int)$me['org_id'] === Configure::read('MISP.host_org_id')),
'scope' => 'attribute' 'scope' => 'attribute'
) )
); );

View File

@ -60,6 +60,7 @@
'isSiteAdmin' => false, // prevent add button 'isSiteAdmin' => false, // prevent add button
'isAclTagger' => false, 'isAclTagger' => false,
'data' => !empty($object['Galaxy']) ? $object['Galaxy'] : array(), 'data' => !empty($object['Galaxy']) ? $object['Galaxy'] : array(),
'event' => $object,
'target_id' => $object['id'], 'target_id' => $object['id'],
'target_type' => 'attribute' 'target_type' => 'attribute'
)); ));

View File

@ -143,7 +143,17 @@ $quickEdit = function($fieldName) use ($editScope, $object, $event) {
</td> </td>
<td class="short"> <td class="short">
<div class="attributeTagContainer"> <div class="attributeTagContainer">
<?php echo $this->element('ajaxTags', array('attributeId' => $object['id'], 'tags' => $object['AttributeTag'], 'tagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id']), 'context' => $context, 'scope' => 'attribute', 'tagConflicts' => isset($object['tagConflicts']) ? $object['tagConflicts'] : array())); ?> <?php echo $this->element(
'ajaxTags',
array('attributeId' => $object['id'],
'tags' => $object['AttributeTag'],
'tagAccess' => ($isSiteAdmin || $mayModify),
'localTagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id'] || (int)$me['org_id'] === Configure::read('MISP.host_org_id')),
'context' => $context,
'scope' => 'attribute',
'tagConflicts' => isset($object['tagConflicts']) ? $object['tagConflicts'] : array()
)
); ?>
</div> </div>
</td> </td>
<?php <?php
@ -166,6 +176,7 @@ $quickEdit = function($fieldName) use ($editScope, $object, $event) {
'mayModify' => $mayModify, 'mayModify' => $mayModify,
'isAclTagger' => $isAclTagger, 'isAclTagger' => $isAclTagger,
'data' => (!empty($object['Galaxy']) ? $object['Galaxy'] : array()), 'data' => (!empty($object['Galaxy']) ? $object['Galaxy'] : array()),
'event' => $event,
'target_id' => $object['id'], 'target_id' => $object['id'],
'target_type' => 'attribute', 'target_type' => 'attribute',
)); ));

View File

@ -110,6 +110,7 @@
'mayModify' => false, 'mayModify' => false,
'isAclTagger' => false, 'isAclTagger' => false,
'data' => $galaxies, 'data' => $galaxies,
'event' => $event,
'target_id' => $event['Event']['id'], 'target_id' => $event['Event']['id'],
'target_type' => 'event', 'target_type' => 'event',
'static_tags_only' => 1 'static_tags_only' => 1
@ -127,6 +128,7 @@
'event' => $event, 'event' => $event,
'tags' => $event['EventTag'], 'tags' => $event['EventTag'],
'tagAccess' => false, 'tagAccess' => false,
'localTagAccess' => false,
'missingTaxonomies' => false, 'missingTaxonomies' => false,
'columnised' => true, 'columnised' => true,
'static_tags_only' => 1, 'static_tags_only' => 1,

View File

@ -22,6 +22,7 @@
break; break;
} }
$full = $isAclTagger && $tagAccess && empty($static_tags_only); $full = $isAclTagger && $tagAccess && empty($static_tags_only);
$fullLocal = $isAclTagger && $localTagAccess && empty($static_tags_only);
$host_org_editor = (int)$me['org_id'] === Configure::read('MISP.host_org_id') && $isAclTagger && empty($static_tags_only); $host_org_editor = (int)$me['org_id'] === Configure::read('MISP.host_org_id') && $isAclTagger && empty($static_tags_only);
$tagData = ""; $tagData = "";
foreach ($tags as $tag) { foreach ($tags as $tag) {
@ -85,7 +86,7 @@
); );
} }
$span_delete = ''; $span_delete = '';
if ($full) { if ($full || ($fullLocal && $tag['Tag']['local'])) {
$span_delete = sprintf( $span_delete = sprintf(
'<span class="%s" title="%s" role="%s" tabindex="%s" aria-label="%s" onClick="%s">x</span>', '<span class="%s" title="%s" role="%s" tabindex="%s" aria-label="%s" onClick="%s">x</span>',
'black-white tag useCursorPointer noPrint', 'black-white tag useCursorPointer noPrint',
@ -121,7 +122,7 @@
'<i class="fas fa-globe-americas"></i> +' '<i class="fas fa-globe-americas"></i> +'
); );
} }
if ($host_org_editor || $full) { if ($full || $fullLocal) {
$buttonData[] = sprintf( $buttonData[] = sprintf(
'<button title="%s" role="button" tabindex="0" aria-label="%s" class="%s" style="%s" onClick="%s">%s</button>', '<button title="%s" role="button" tabindex="0" aria-label="%s" class="%s" style="%s" onClick="%s">%s</button>',
__('Add a local tag'), __('Add a local tag'),

View File

@ -7,8 +7,15 @@ if (isset($preview) && $preview) {
} else { } else {
$preview = false; $preview = false;
} }
$tagAccess = ($isSiteAdmin || ($mayModify && $isAclTagger));
if (empty($local_tag_off) || !empty($event)) {
$localTagAccess = ($isSiteAdmin || ($mayModify || $me['org_id'] == $event['Event']['org_id'] || (int)$me['org_id'] === Configure::read('MISP.host_org_id'))) && $isAclTagger;
} else {
$localTagAccess = false;
}
$editButtonsEnabled = !(isset($static_tags_only) && $static_tags_only); $editButtonsEnabled = empty($static_tags_only) && $tagAccess;
$editButtonsLocalEnabled = empty($static_tags_only) && $localTagAccess && empty($local_tag_off);
$sortClusters = function (array $clusters) { $sortClusters = function (array $clusters) {
usort($clusters, function (array $a, array $b) { usort($clusters, function (array $a, array $b) {
@ -94,7 +101,7 @@ $generatePopover = function (array $cluster) use ($normalizeKey) {
<a href="<?= $baseurl ?>/galaxy_clusters/view/<?= h($cluster['id']) ?>" class="black fa fa-search" title="<?= __('View details about this cluster') ?>" aria-label="<?= __('View cluster') ?>"></a> <a href="<?= $baseurl ?>/galaxy_clusters/view/<?= h($cluster['id']) ?>" class="black fa fa-search" title="<?= __('View details about this cluster') ?>" aria-label="<?= __('View cluster') ?>"></a>
<a href="<?= $baseurl ?>/events/index/searchtag:<?= h($cluster['tag_id']) ?>" class="black fa fa-list" title="<?= __('View all events containing this cluster') ?>" aria-label="<?= __('View all events containing this cluster') ?>"></a> <a href="<?= $baseurl ?>/events/index/searchtag:<?= h($cluster['tag_id']) ?>" class="black fa fa-list" title="<?= __('View all events containing this cluster') ?>" aria-label="<?= __('View all events containing this cluster') ?>"></a>
<?php endif ;?> <?php endif ;?>
<?php if ($editButtonsEnabled && ($isSiteAdmin || ($mayModify && $isAclTagger))) { <?php if ($editButtonsEnabled || ($editButtonsLocalEnabled && $cluster['local'])) {
echo $this->Form->create(false, [ echo $this->Form->create(false, [
'id' => false, // prevent duplicate ids 'id' => false, // prevent duplicate ids
'url' => $baseurl . '/galaxy_clusters/detach/' . ucfirst(h($target_id)) . '/' . h($target_type) . '/' . $cluster['tag_id'], 'url' => $baseurl . '/galaxy_clusters/detach/' . ucfirst(h($target_id)) . '/' . h($target_type) . '/' . $cluster['tag_id'],
@ -115,7 +122,7 @@ echo $this->Form->end();
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php <?php
if ($editButtonsEnabled && ($isSiteAdmin || ($mayModify && $isAclTagger))) { if ($editButtonsEnabled) {
echo sprintf( echo sprintf(
'<button class="%s" data-target-type="%s" data-target-id="%s" data-local="false" role="button" tabindex="0" aria-label="' . __('Add new cluster') . '" title="' . __('Add new cluster') . '">%s</button>', '<button class="%s" data-target-type="%s" data-target-id="%s" data-local="false" role="button" tabindex="0" aria-label="' . __('Add new cluster') . '" title="' . __('Add new cluster') . '">%s</button>',
'useCursorPointer btn btn-inverse addGalaxy', 'useCursorPointer btn btn-inverse addGalaxy',
@ -125,11 +132,7 @@ if ($editButtonsEnabled && ($isSiteAdmin || ($mayModify && $isAclTagger))) {
); );
} }
if ( if ($editButtonsLocalEnabled) {
$editButtonsEnabled &&
(!isset($local_tag_off) || !$local_tag_off) &&
($isSiteAdmin || ($isAclTagger && $hostOrgUser))
) {
echo sprintf( echo sprintf(
'<button class="%s" data-target-type="%s" data-target-id="%s" data-local="true" role="button" tabindex="0" aria-label="' . __('Add new local cluster') . '" title="' . __('Add new local cluster') . '">%s</button>', '<button class="%s" data-target-type="%s" data-target-id="%s" data-local="true" role="button" tabindex="0" aria-label="' . __('Add new local cluster') . '" title="' . __('Add new local cluster') . '">%s</button>',
'useCursorPointer btn btn-inverse addGalaxy', 'useCursorPointer btn btn-inverse addGalaxy',

View File

@ -19,6 +19,7 @@
'attributeId' => 0, 'attributeId' => 0,
'tags' => $tags, 'tags' => $tags,
'tagAccess' => false, 'tagAccess' => false,
'localTagAccess' => false,
'static_tags_only' => 1, 'static_tags_only' => 1,
'scope' => isset($field['scope']) ? $field['scope'] : 'event', 'scope' => isset($field['scope']) ? $field['scope'] : 'event',
'hide_global_scope' => isset($field['hide_global_scope']) ? $field['hide_global_scope'] : false 'hide_global_scope' => isset($field['hide_global_scope']) ? $field['hide_global_scope'] : false

View File

@ -7,6 +7,7 @@ echo $this->element('galaxyQuickViewNew', [
'mayModify' => $mayModify, 'mayModify' => $mayModify,
'isAclTagger' => $isAclTagger, 'isAclTagger' => $isAclTagger,
'data' => $object['Galaxy'], 'data' => $object['Galaxy'],
'event' => $object,
'target_id' => $scope == 'event' ? $object['Event']['id'] : $object['Attribute']['id'], 'target_id' => $scope == 'event' ? $object['Event']['id'] : $object['Attribute']['id'],
'target_type' => $scope 'target_type' => $scope
]); ]);

View File

@ -7,6 +7,7 @@
'event' => $event, 'event' => $event,
'tags' => $tags, 'tags' => $tags,
'tagAccess' => ($isSiteAdmin || $mayModify), 'tagAccess' => ($isSiteAdmin || $mayModify),
'localTagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id'] || (int)$me['org_id'] === Configure::read('MISP.host_org_id')),
'tagConflicts' => $tagConflicts 'tagConflicts' => $tagConflicts
)); ));
?> ?>

View File

@ -19,7 +19,7 @@
if ($fieldData === 'Tag') { if ($fieldData === 'Tag') {
echo '<div><span class="blue bold">Tags</span>: '; echo '<div><span class="blue bold">Tags</span>: ';
if (!empty($event['EventTag'])) { if (!empty($event['EventTag'])) {
echo '<span>' . $this->element('ajaxTags', array('event' => $event, 'tags' => $event['EventTag'], 'static_tags_only' => true)) . '</span>'; echo '<span>' . $this->element('ajaxTags', array('event' => $event, 'tags' => $event['EventTag'], 'static_tags_only' => true, 'tagAccess' => false, 'localTagAccess' => false)) . '</span>';
} }
echo '</div>'; echo '</div>';
} else { } else {

View File

@ -71,7 +71,8 @@
$this->element('ajaxTags', array( $this->element('ajaxTags', array(
'event' => $event, 'event' => $event,
'tags' => $event['Tag'], 'tags' => $event['Tag'],
'tagAccess' => ($isSiteAdmin || $me['org_id'] == $event['Event']['orgc_id']), 'tagAccess' => false,
'localTagAccess' => false,
'static_tags_only' => 1 'static_tags_only' => 1
)) ))
) )

View File

@ -105,7 +105,8 @@
array( array(
'event' => $event, 'event' => $event,
'tags' => $event['EventTag'], 'tags' => $event['EventTag'],
'tagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['orgc_id']), 'tagAccess' => ($isSiteAdmin || $mayModify),
'localTagAccess' => ($isSiteAdmin || $mayModify || $me['org_id'] == $event['Event']['org_id'] || (int)$me['org_id'] === Configure::read('MISP.host_org_id')),
'missingTaxonomies' => $missingTaxonomies, 'missingTaxonomies' => $missingTaxonomies,
'tagConflicts' => $tagConflicts 'tagConflicts' => $tagConflicts
) )
@ -536,6 +537,7 @@
'mayModify' => $mayModify, 'mayModify' => $mayModify,
'isAclTagger' => $isAclTagger, 'isAclTagger' => $isAclTagger,
'data' => $event['Galaxy'], 'data' => $event['Galaxy'],
'event' => $event,
'target_id' => $event['Event']['id'], 'target_id' => $event['Event']['id'],
'target_type' => 'event' 'target_type' => 'event'
]); ?> ]); ?>

View File

@ -22,6 +22,7 @@
'scope' => 'feed', 'scope' => 'feed',
'tags' => array(array('Tag' => $feed['Tag'])), 'tags' => array(array('Tag' => $feed['Tag'])),
'tagAccess' => false, 'tagAccess' => false,
'localTagAccess' => false,
'static_tags_only' => true 'static_tags_only' => true
) )
) )

View File

@ -98,6 +98,7 @@ $tableData[] = [
<span class="title-section"><?= __('Galaxies') ?></span> <span class="title-section"><?= __('Galaxies') ?></span>
<?= $this->element('galaxyQuickViewNew', [ <?= $this->element('galaxyQuickViewNew', [
'data' => $event['Galaxy'], 'data' => $event['Galaxy'],
'event' => $event,
'preview' => true, 'preview' => true,
]); ?> ]); ?>
</div> </div>