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

pull/9665/head
Sami Mokaddem 2024-04-03 16:43:30 +02:00
commit 7dcca1ae2a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
5 changed files with 22 additions and 24 deletions

View File

@ -2413,7 +2413,7 @@ class EventsController extends AppController
if (isset($this->params['named']['distribution'])) {
$distribution = intval($this->params['named']['distribution']);
if (!array_key_exists($distribution, $distributionLevels)) {
throw new MethodNotAllowedException(__('Wrong distribution level'));
throw new BadRequestException(__('Wrong distribution level'));
}
} else {
$distribution = $initialDistribution;
@ -2421,11 +2421,11 @@ class EventsController extends AppController
$sharingGroupId = null;
if ($distribution == 4) {
if (!isset($this->params['named']['sharing_group_id'])) {
throw new MethodNotAllowedException(__('The sharing group id is needed when the distribution is set to 4 ("Sharing group").'));
throw new BadRequestException(__('The sharing group id is needed when the distribution is set to 4 ("Sharing group").'));
}
$sharingGroupId = intval($this->params['named']['sharing_group_id']);
if (!array_key_exists($sharingGroupId, $sgs)) {
throw new MethodNotAllowedException(__('Please select a valid sharing group id.'));
throw new BadRequestException(__('Please select a valid sharing group id.'));
}
}
$clusterDistribution = $initialDistribution;
@ -2435,15 +2435,15 @@ class EventsController extends AppController
if (isset($this->params['name']['cluster_distribution'])) {
$clusterDistribution = intval($this->params['named']['cluster_distribution']);
if (!array_key_exists($clusterDistribution, $distributionLevels)) {
throw new MethodNotAllowedException(__('Wrong cluster distribution level'));
throw new BadRequestException(__('Wrong cluster distribution level'));
}
if ($clusterDistribution == 4) {
if (!isset($this->params['named']['cluster_sharing_group_id'])) {
throw new MethodNotAllowedException(__('The cluster sharing group id is needed when the cluster distribution is set to 4 ("Sharing group").'));
throw new BadRequestException(__('The cluster sharing group id is needed when the cluster distribution is set to 4 ("Sharing group").'));
}
$clusterSharingGroupId = intval($this->params['named']['cluster_sharing_group_id']);
if (!array_key_exists($clusterSharingGroupId, $sgs)) {
throw new MethodNotAllowedException(__('Please select a valid cluster sharing group id.'));
throw new BadRequestException(__('Please select a valid cluster sharing group id.'));
}
}
}
@ -2475,8 +2475,8 @@ class EventsController extends AppController
} else {
return $this->RestResponse->saveFailResponse('Events', 'upload_stix', false, $result, $this->response->type());
}
} else {
$original_file = !empty($this->data['Event']['original_file']) ? $this->data['Event']['stix']['name'] : '';
} else { // not REST request
$originalFile = !empty($this->data['Event']['original_file']) ? $this->data['Event']['stix']['name'] : '';
if (isset($this->data['Event']['stix']) && $this->data['Event']['stix']['size'] > 0 && is_uploaded_file($this->data['Event']['stix']['tmp_name'])) {
$filePath = FileAccessTool::createTempFile();
if (!move_uploaded_file($this->data['Event']['stix']['tmp_name'], $filePath)) {
@ -2489,12 +2489,12 @@ class EventsController extends AppController
$this->Auth->user(),
$filePath,
$stix_version,
$original_file,
$originalFile,
$this->data['Event']['publish'],
$this->data['Event']['distribution'],
$this->data['Event']['sharing_group_id'] ?? null,
$this->data['Event']['galaxies_handling'],
$this->data['Event']['cluster_distribution'],
$this->data['Event']['galaxies_handling'] ?? false,
$this->data['Event']['cluster_distribution'] ?? 0,
$this->data['Event']['cluster_sharing_group_id'] ?? null,
$debug
);

View File

@ -6111,7 +6111,7 @@ class Event extends AppModel
/**
* @param string $stixVersion
* @param string $file
* @param string $file Path to STIX file
* @param int $distribution
* @param int|null $sharingGroupId
* @param bool $galaxiesAsTags
@ -6169,6 +6169,7 @@ class Event extends AppModel
try {
$stdout = ProcessTool::execute($shellCommand, null, true);
} catch (ProcessException $e) {
$this->logException("Could not import $stixVersion file $file", $e);
$stdout = $e->stdout();
}

View File

@ -1256,6 +1256,8 @@ class Sighting extends AppModel
if (!isset($attributes[$s['attribute_uuid']])) {
continue; // attribute doesn't exists or user don't have permission to access it
}
$existingSighting[$s['uuid']] = true; // just to be sure that there are no sigthings with duplicated UUID
list($attributeId, $eventId) = $attributes[$s['attribute_uuid']];
if ($s['type'] === '2') {
@ -1271,11 +1273,8 @@ class Sighting extends AppModel
if ($user['Role']['perm_sync']) {
if (isset($s['org_id'])) {
if ($s['org_id'] != 0 && !empty($s['Organisation'])) {
if (isset($existingOrganisations[$s['Organisation']['uuid']])) {
$saveOnBehalfOf = $existingOrganisations[$s['Organisation']['uuid']];
} else {
$saveOnBehalfOf = $this->Organisation->captureOrg($s['Organisation'], $user);
}
$saveOnBehalfOf = $existingOrganisations[$s['Organisation']['uuid']] ??
$this->Organisation->captureOrg($s['Organisation'], $user);
} else {
$saveOnBehalfOf = 0;
}
@ -1297,8 +1296,8 @@ class Sighting extends AppModel
}
if ($this->saveMany($toSave)) {
$existingUuids = array_column($toSave, 'uuid');
$this->Event->publishSightingsRouter($event['Event']['id'], $user, $passAlong, $existingUuids);
$sightingsUuidsToPush = array_column($toSave, 'uuid');
$this->Event->publishSightingsRouter($event['Event']['id'], $user, $passAlong, $sightingsUuidsToPush);
return count($toSave);
}

View File

@ -133,8 +133,7 @@ $(function(){
checkSharingGroup('Event');
});
checkSharingGroup('Event');
});
$(function(){
$('#EventGalaxiesHandling').change(function() {
if ($(this).val() == 0) {
$('#ClusterDistribution').show();
@ -146,8 +145,7 @@ $(function(){
$('#ClusterSGContainer').hide();
}
}).change();
});
$(function(){
$('#EventClusterDistribution').change(function() {
if ($(this).val() == 4 && $('#EventGalaxiesHandling').val() == 0) {
$('#ClusterSGContainer').show();

@ -1 +1 @@
Subproject commit f531a2cdce0e1ff2bcc879d57d2872f6318fb5cf
Subproject commit 6f344fe8e813c2d512d725f07699003ec7548430